php-src/ext/json/tests/fail001.phpt
Antony Dovgal a9230e2726 fix test
2007-05-29 12:01:14 +00:00

287 lines
10 KiB
PHP

--TEST--
JSON (http://www.crockford.com/JSON/JSON_checker/test/fail*.json)
--SKIPIF--
<?php
if (!extension_loaded('json')) die('skip: json extension not available');
?>
--FILE--
<?php
$tests = array('"A JSON payload should be an object or array, not a string."',
'["Unclosed array"',
'{unquoted_key: "keys must be quoted}',
'["extra comma",]',
'["double extra comma",,]',
'[ , "<-- missing value"]',
'["Comma after the close"],',
'["Extra close"]]',
'{"Extra comma": true,}',
'{"Extra value after close": true} "misplaced quoted value"',
'{"Illegal expression": 1 + 2}',
'{"Illegal invocation": alert()}',
'{"Numbers cannot have leading zeroes": 013}',
'{"Numbers cannot be hex": 0x14}',
'["Illegal backslash escape: \\x15"]',
'["Illegal backslash escape: \\\'"]',
'["Illegal backslash escape: \\017"]',
'[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]',
'{"Missing colon" null}',
'{"Double colon":: null}',
'{"Comma instead of colon", null}',
'["Colon instead of comma": false]',
'["Bad value", truth]',
"['single quote']");
foreach ($tests as $test)
{
echo 'Testing: ' . $test . "\n";
echo "AS OBJECT\n";
var_dump(json_decode($test));
echo "AS ARRAY\n";
var_dump(json_decode($test, true));
}
?>
--EXPECT--
Testing: "A JSON payload should be an object or array, not a string."
AS OBJECT
string(58) "A JSON payload should be an object or array, not a string."
AS ARRAY
string(58) "A JSON payload should be an object or array, not a string."
Testing: ["Unclosed array"
AS OBJECT
string(17) "["Unclosed array""
AS ARRAY
string(17) "["Unclosed array""
Testing: {unquoted_key: "keys must be quoted}
AS OBJECT
string(36) "{unquoted_key: "keys must be quoted}"
AS ARRAY
string(36) "{unquoted_key: "keys must be quoted}"
Testing: ["extra comma",]
AS OBJECT
string(16) "["extra comma",]"
AS ARRAY
string(16) "["extra comma",]"
Testing: ["double extra comma",,]
AS OBJECT
string(24) "["double extra comma",,]"
AS ARRAY
string(24) "["double extra comma",,]"
Testing: [ , "<-- missing value"]
AS OBJECT
string(26) "[ , "<-- missing value"]"
AS ARRAY
string(26) "[ , "<-- missing value"]"
Testing: ["Comma after the close"],
AS OBJECT
string(26) "["Comma after the close"],"
AS ARRAY
string(26) "["Comma after the close"],"
Testing: ["Extra close"]]
AS OBJECT
string(16) "["Extra close"]]"
AS ARRAY
string(16) "["Extra close"]]"
Testing: {"Extra comma": true,}
AS OBJECT
string(22) "{"Extra comma": true,}"
AS ARRAY
string(22) "{"Extra comma": true,}"
Testing: {"Extra value after close": true} "misplaced quoted value"
AS OBJECT
string(58) "{"Extra value after close": true} "misplaced quoted value""
AS ARRAY
string(58) "{"Extra value after close": true} "misplaced quoted value""
Testing: {"Illegal expression": 1 + 2}
AS OBJECT
string(29) "{"Illegal expression": 1 + 2}"
AS ARRAY
string(29) "{"Illegal expression": 1 + 2}"
Testing: {"Illegal invocation": alert()}
AS OBJECT
string(31) "{"Illegal invocation": alert()}"
AS ARRAY
string(31) "{"Illegal invocation": alert()}"
Testing: {"Numbers cannot have leading zeroes": 013}
AS OBJECT
string(43) "{"Numbers cannot have leading zeroes": 013}"
AS ARRAY
string(43) "{"Numbers cannot have leading zeroes": 013}"
Testing: {"Numbers cannot be hex": 0x14}
AS OBJECT
string(31) "{"Numbers cannot be hex": 0x14}"
AS ARRAY
string(31) "{"Numbers cannot be hex": 0x14}"
Testing: ["Illegal backslash escape: \x15"]
AS OBJECT
string(34) "["Illegal backslash escape: \x15"]"
AS ARRAY
string(34) "["Illegal backslash escape: \x15"]"
Testing: ["Illegal backslash escape: \'"]
AS OBJECT
string(32) "["Illegal backslash escape: \'"]"
AS ARRAY
string(32) "["Illegal backslash escape: \'"]"
Testing: ["Illegal backslash escape: \017"]
AS OBJECT
string(34) "["Illegal backslash escape: \017"]"
AS ARRAY
string(34) "["Illegal backslash escape: \017"]"
Testing: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
AS OBJECT
string(266) "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
AS ARRAY
string(266) "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
Testing: {"Missing colon" null}
AS OBJECT
string(22) "{"Missing colon" null}"
AS ARRAY
string(22) "{"Missing colon" null}"
Testing: {"Double colon":: null}
AS OBJECT
string(23) "{"Double colon":: null}"
AS ARRAY
string(23) "{"Double colon":: null}"
Testing: {"Comma instead of colon", null}
AS OBJECT
string(32) "{"Comma instead of colon", null}"
AS ARRAY
string(32) "{"Comma instead of colon", null}"
Testing: ["Colon instead of comma": false]
AS OBJECT
string(33) "["Colon instead of comma": false]"
AS ARRAY
string(33) "["Colon instead of comma": false]"
Testing: ["Bad value", truth]
AS OBJECT
string(20) "["Bad value", truth]"
AS ARRAY
string(20) "["Bad value", truth]"
Testing: ['single quote']
AS OBJECT
string(16) "['single quote']"
AS ARRAY
string(16) "['single quote']"
--UEXPECT--
Testing: "A JSON payload should be an object or array, not a string."
AS OBJECT
unicode(58) "A JSON payload should be an object or array, not a string."
AS ARRAY
unicode(58) "A JSON payload should be an object or array, not a string."
Testing: ["Unclosed array"
AS OBJECT
unicode(17) "["Unclosed array""
AS ARRAY
unicode(17) "["Unclosed array""
Testing: {unquoted_key: "keys must be quoted}
AS OBJECT
unicode(36) "{unquoted_key: "keys must be quoted}"
AS ARRAY
unicode(36) "{unquoted_key: "keys must be quoted}"
Testing: ["extra comma",]
AS OBJECT
unicode(16) "["extra comma",]"
AS ARRAY
unicode(16) "["extra comma",]"
Testing: ["double extra comma",,]
AS OBJECT
unicode(24) "["double extra comma",,]"
AS ARRAY
unicode(24) "["double extra comma",,]"
Testing: [ , "<-- missing value"]
AS OBJECT
unicode(26) "[ , "<-- missing value"]"
AS ARRAY
unicode(26) "[ , "<-- missing value"]"
Testing: ["Comma after the close"],
AS OBJECT
unicode(26) "["Comma after the close"],"
AS ARRAY
unicode(26) "["Comma after the close"],"
Testing: ["Extra close"]]
AS OBJECT
unicode(16) "["Extra close"]]"
AS ARRAY
unicode(16) "["Extra close"]]"
Testing: {"Extra comma": true,}
AS OBJECT
unicode(22) "{"Extra comma": true,}"
AS ARRAY
unicode(22) "{"Extra comma": true,}"
Testing: {"Extra value after close": true} "misplaced quoted value"
AS OBJECT
unicode(58) "{"Extra value after close": true} "misplaced quoted value""
AS ARRAY
unicode(58) "{"Extra value after close": true} "misplaced quoted value""
Testing: {"Illegal expression": 1 + 2}
AS OBJECT
unicode(29) "{"Illegal expression": 1 + 2}"
AS ARRAY
unicode(29) "{"Illegal expression": 1 + 2}"
Testing: {"Illegal invocation": alert()}
AS OBJECT
unicode(31) "{"Illegal invocation": alert()}"
AS ARRAY
unicode(31) "{"Illegal invocation": alert()}"
Testing: {"Numbers cannot have leading zeroes": 013}
AS OBJECT
unicode(43) "{"Numbers cannot have leading zeroes": 013}"
AS ARRAY
unicode(43) "{"Numbers cannot have leading zeroes": 013}"
Testing: {"Numbers cannot be hex": 0x14}
AS OBJECT
unicode(31) "{"Numbers cannot be hex": 0x14}"
AS ARRAY
unicode(31) "{"Numbers cannot be hex": 0x14}"
Testing: ["Illegal backslash escape: \x15"]
AS OBJECT
unicode(34) "["Illegal backslash escape: \x15"]"
AS ARRAY
unicode(34) "["Illegal backslash escape: \x15"]"
Testing: ["Illegal backslash escape: \'"]
AS OBJECT
unicode(32) "["Illegal backslash escape: \'"]"
AS ARRAY
unicode(32) "["Illegal backslash escape: \'"]"
Testing: ["Illegal backslash escape: \017"]
AS OBJECT
unicode(34) "["Illegal backslash escape: \017"]"
AS ARRAY
unicode(34) "["Illegal backslash escape: \017"]"
Testing: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
AS OBJECT
unicode(266) "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
AS ARRAY
unicode(266) "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
Testing: {"Missing colon" null}
AS OBJECT
unicode(22) "{"Missing colon" null}"
AS ARRAY
unicode(22) "{"Missing colon" null}"
Testing: {"Double colon":: null}
AS OBJECT
unicode(23) "{"Double colon":: null}"
AS ARRAY
unicode(23) "{"Double colon":: null}"
Testing: {"Comma instead of colon", null}
AS OBJECT
unicode(32) "{"Comma instead of colon", null}"
AS ARRAY
unicode(32) "{"Comma instead of colon", null}"
Testing: ["Colon instead of comma": false]
AS OBJECT
unicode(33) "["Colon instead of comma": false]"
AS ARRAY
unicode(33) "["Colon instead of comma": false]"
Testing: ["Bad value", truth]
AS OBJECT
unicode(20) "["Bad value", truth]"
AS ARRAY
unicode(20) "["Bad value", truth]"
Testing: ['single quote']
AS OBJECT
unicode(16) "['single quote']"
AS ARRAY
unicode(16) "['single quote']"