Remove trailing CRs.

This commit is contained in:
David I. Lehn 2013-03-01 15:07:40 -05:00
parent 9a760ef766
commit 4552cc6112
2 changed files with 82 additions and 82 deletions

View file

@ -31,39 +31,39 @@ if(!$isCli) {
set_error_handler('error_handler'); set_error_handler('error_handler');
} }
function deep_compare($expect, $result) { function deep_compare($expect, $result) {
if(is_array($expect)) { if(is_array($expect)) {
if(!is_array($result)) { if(!is_array($result)) {
return false; return false;
} }
if(count($expect) !== count($result)) { if(count($expect) !== count($result)) {
return false; return false;
} }
foreach($expect as $i => $v) { foreach($expect as $i => $v) {
if(!deep_compare($v, $result[$i])) { if(!deep_compare($v, $result[$i])) {
return false; return false;
} }
} }
return true; return true;
} }
if(is_object($expect)) { if(is_object($expect)) {
if(!is_object($result)) { if(!is_object($result)) {
return false; return false;
} }
if(count(get_object_vars($expect)) !== count(get_object_vars($result))) { if(count(get_object_vars($expect)) !== count(get_object_vars($result))) {
return false; return false;
} }
foreach($expect as $k => $v) { foreach($expect as $k => $v) {
if(!property_exists($result, $k) || !deep_compare($v, $result->{$k})) { if(!property_exists($result, $k) || !deep_compare($v, $result->{$k})) {
return false; return false;
} }
} }
return true; return true;
} }
return $expect === $result; return $expect === $result;
} }
function expanded_compare($x, $y, $is_list=false) { function expanded_compare($x, $y, $is_list=false) {
if($x === $y) { if($x === $y) {
@ -170,21 +170,21 @@ function read_test_nquads($file, $filepath) {
* *
* @return the encoded input. * @return the encoded input.
*/ */
function jsonld_encode($input) { function jsonld_encode($input) {
// newer PHP has a flag to avoid escaped '/' // newer PHP has a flag to avoid escaped '/'
if(defined('JSON_UNESCAPED_SLASHES')) { if(defined('JSON_UNESCAPED_SLASHES')) {
$options = JSON_UNESCAPED_SLASHES; $options = JSON_UNESCAPED_SLASHES;
if(defined('JSON_PRETTY_PRINT')) { if(defined('JSON_PRETTY_PRINT')) {
$options |= JSON_PRETTY_PRINT; $options |= JSON_PRETTY_PRINT;
} }
$json = json_encode($input, $options); $json = json_encode($input, $options);
} }
else { else {
// use a simple string replacement of '\/' to '/'. // use a simple string replacement of '\/' to '/'.
$json = str_replace('\\/', '/', json_encode($input)); $json = str_replace('\\/', '/', json_encode($input));
} }
return $json; return $json;
} }
class TestRunner { class TestRunner {
@ -254,10 +254,10 @@ class TestRunner {
if(!$pass && $relabel) { if(!$pass && $relabel) {
echo "WARN tried normalization..."; echo "WARN tried normalization...";
$expect_normalized = jsonld_normalize( $expect_normalized = jsonld_normalize(
$expect, array('format' => 'application/nquads')); $expect, array('format' => 'application/nquads'));
$result_normalized = jsonld_normalize( $result_normalized = jsonld_normalize(
$result, array('format' => 'application/nquads')); $result, array('format' => 'application/nquads'));
$pass = ($expect_normalized === $result_normalized); $pass = ($expect_normalized === $result_normalized);
} }
if($pass) { if($pass) {
@ -346,9 +346,9 @@ class TestRunner {
try { try {
if(in_array('jld:ApiErrorTest', $type)) { if(in_array('jld:ApiErrorTest', $type)) {
echo "Skipping test \"{$test->name}\" of type: " . echo "Skipping test \"{$test->name}\" of type: " .
json_encode($type) . $eol; json_encode($type) . $eol;
continue; continue;
} }
else if(in_array('jld:NormalizeTest', $type)) { else if(in_array('jld:NormalizeTest', $type)) {
$this->test($test->name); $this->test($test->name);
@ -371,10 +371,10 @@ class TestRunner {
$result = jsonld_compact($input, $test->context, $options); $result = jsonld_compact($input, $test->context, $options);
} }
else if(in_array('jld:FlattenTest', $type)) { else if(in_array('jld:FlattenTest', $type)) {
$this->test($test->name); $this->test($test->name);
$input = read_test_json($test->input, $filepath); $input = read_test_json($test->input, $filepath);
$test->expect = read_test_json($test->expect, $filepath); $test->expect = read_test_json($test->expect, $filepath);
$result = jsonld_flatten($input, null, $options); $result = jsonld_flatten($input, null, $options);
} }
else if(in_array('jld:FrameTest', $type)) { else if(in_array('jld:FrameTest', $type)) {
$this->test($test->name); $this->test($test->name);
@ -402,13 +402,13 @@ class TestRunner {
continue; continue;
} }
// check results // check results
$this->check($test, $test->expect, $result, $type); $this->check($test, $test->expect, $result, $type);
} }
catch(JsonLdException $e) { catch(JsonLdException $e) {
echo $eol . $e; echo $eol . $e;
$this->failed += 1; $this->failed += 1;
echo "FAIL$eol"; echo "FAIL$eol";
} }
} }
if(property_exists($manifest, 'name')) { if(property_exists($manifest, 'name')) {

View file

@ -223,11 +223,11 @@ function jsonld_default_get_url($url) {
'header' => 'header' =>
"Accept: application/ld+json\r\n" . "Accept: application/ld+json\r\n" .
"User-Agent: PaySwarm PHP Client/1.0\r\n"), "User-Agent: PaySwarm PHP Client/1.0\r\n"),
'https' => array( 'https' => array(
'verify_peer' => true, 'verify_peer' => true,
'method' => "GET", 'method' => "GET",
'header' => 'header' =>
"Accept: application/ld+json\r\n" . "Accept: application/ld+json\r\n" .
"User-Agent: PaySwarm PHP Client/1.0\r\n")); "User-Agent: PaySwarm PHP Client/1.0\r\n"));
$stream = stream_context_create($opts); $stream = stream_context_create($opts);
$result = @file_get_contents($url, false, $stream); $result = @file_get_contents($url, false, $stream);
@ -237,28 +237,28 @@ function jsonld_default_get_url($url) {
return $result; return $result;
} }
/** /**
* The default implementation to retrieve JSON-LD at the given secure URL. * The default implementation to retrieve JSON-LD at the given secure URL.
* *
* @param string $url the secure URL to to retrieve. * @param string $url the secure URL to to retrieve.
* *
* @return the JSON-LD. * @return the JSON-LD.
*/ */
function jsonld_default_get_secure_url($url) { function jsonld_default_get_secure_url($url) {
if(strpos($url, 'https') !== 0) { if(strpos($url, 'https') !== 0) {
throw new Exception("Could not GET url: '$url'; 'https' is required."); throw new Exception("Could not GET url: '$url'; 'https' is required.");
} }
$redirects = array(); $redirects = array();
// default JSON-LD https GET implementation // default JSON-LD https GET implementation
$opts = array( $opts = array(
'https' => array( 'https' => array(
'verify_peer' => true, 'verify_peer' => true,
'method' => "GET", 'method' => "GET",
'header' => 'header' =>
"Accept: application/ld+json\r\n" . "Accept: application/ld+json\r\n" .
"User-Agent: PaySwarm PHP Client/1.0\r\n")); "User-Agent: PaySwarm PHP Client/1.0\r\n"));
$stream = stream_context_create($opts); $stream = stream_context_create($opts);
stream_context_set_params($stream, array('notification' => stream_context_set_params($stream, array('notification' =>
function($notification_code, $severity, $message) use (&$redirects) { function($notification_code, $severity, $message) use (&$redirects) {
@ -269,16 +269,16 @@ function jsonld_default_get_secure_url($url) {
}; };
})); }));
$result = @file_get_contents($url, false, $stream); $result = @file_get_contents($url, false, $stream);
if($result === false) { if($result === false) {
throw new Exception("Could not GET url: '$url'"); throw new Exception("Could not GET url: '$url'");
} }
foreach($redirects as $redirect) { foreach($redirects as $redirect) {
if(strpos($redirect, 'https') !== 0) { if(strpos($redirect, 'https') !== 0) {
throw new Exception( throw new Exception(
"Could not GET redirected url: '$redirect'; 'https' is required."); "Could not GET redirected url: '$redirect'; 'https' is required.");
} }
} }
return $result; return $result;
} }
/** Registered global RDF dataset parsers hashed by content-type. */ /** Registered global RDF dataset parsers hashed by content-type. */