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

View file

@ -223,11 +223,11 @@ function jsonld_default_get_url($url) {
'header' =>
"Accept: application/ld+json\r\n" .
"User-Agent: PaySwarm PHP Client/1.0\r\n"),
'https' => array(
'https' => array(
'verify_peer' => true,
'method' => "GET",
'header' =>
"Accept: application/ld+json\r\n" .
'method' => "GET",
'header' =>
"Accept: application/ld+json\r\n" .
"User-Agent: PaySwarm PHP Client/1.0\r\n"));
$stream = stream_context_create($opts);
$result = @file_get_contents($url, false, $stream);
@ -237,28 +237,28 @@ function jsonld_default_get_url($url) {
return $result;
}
/**
* The default implementation to retrieve JSON-LD at the given secure URL.
*
* @param string $url the secure URL to to retrieve.
*
* @return the JSON-LD.
*/
/**
* The default implementation to retrieve JSON-LD at the given secure URL.
*
* @param string $url the secure URL to to retrieve.
*
* @return the JSON-LD.
*/
function jsonld_default_get_secure_url($url) {
if(strpos($url, 'https') !== 0) {
throw new Exception("Could not GET url: '$url'; 'https' is required.");
if(strpos($url, 'https') !== 0) {
throw new Exception("Could not GET url: '$url'; 'https' is required.");
}
$redirects = array();
// default JSON-LD https GET implementation
$redirects = array();
// default JSON-LD https GET implementation
$opts = array(
'https' => array(
'verify_peer' => true,
'method' => "GET",
'header' =>
"Accept: application/ld+json\r\n" .
"User-Agent: PaySwarm PHP Client/1.0\r\n"));
'method' => "GET",
'header' =>
"Accept: application/ld+json\r\n" .
"User-Agent: PaySwarm PHP Client/1.0\r\n"));
$stream = stream_context_create($opts);
stream_context_set_params($stream, array('notification' =>
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);
if($result === false) {
throw new Exception("Could not GET url: '$url'");
if($result === false) {
throw new Exception("Could not GET url: '$url'");
}
foreach($redirects as $redirect) {
if(strpos($redirect, 'https') !== 0) {
if(strpos($redirect, 'https') !== 0) {
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. */