|
|
|
@ -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')) {
|
|
|
|
|