mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Use the same CS for all json tests
This commit is contained in:
parent
f8bf9bd86b
commit
e5abc53701
32 changed files with 185 additions and 252 deletions
|
@ -20,7 +20,6 @@ var_dump(json_encode(array(), JSON_FORCE_OBJECT));
|
|||
var_dump(json_encode(1));
|
||||
var_dump(json_encode("руссиш"));
|
||||
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
|
|
@ -4,15 +4,14 @@ json_encode() & extended encoding
|
|||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$a = array('<foo>',"'bar'",'"baz"','&blong&');
|
||||
$a = array('<foo>', "'bar'", '"baz"', '&blong&');
|
||||
|
||||
echo "Normal: ", json_encode($a), "\n";
|
||||
echo "Tags: ", json_encode($a,JSON_HEX_TAG), "\n";
|
||||
echo "Apos: ", json_encode($a,JSON_HEX_APOS), "\n";
|
||||
echo "Quot: ", json_encode($a,JSON_HEX_QUOT), "\n";
|
||||
echo "Amp: ", json_encode($a,JSON_HEX_AMP), "\n";
|
||||
echo "All: ", json_encode($a,JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP), "\n";
|
||||
echo "Tags: ", json_encode($a, JSON_HEX_TAG), "\n";
|
||||
echo "Apos: ", json_encode($a, JSON_HEX_APOS), "\n";
|
||||
echo "Quot: ", json_encode($a, JSON_HEX_QUOT), "\n";
|
||||
echo "Amp: ", json_encode($a, JSON_HEX_AMP), "\n";
|
||||
echo "All: ", json_encode($a, JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP), "\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
Normal: ["<foo>","'bar'","\"baz\"","&blong&"]
|
||||
|
|
|
@ -15,7 +15,6 @@ var_dump(json_last_error(), json_last_error_msg());
|
|||
var_dump(json_decode("[1"));
|
||||
var_dump(json_last_error(), json_last_error_msg());
|
||||
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
|
|
|
@ -6,14 +6,14 @@ precision=14
|
|||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
function show_eq($x,$y) {
|
||||
echo "$x ". ($x==$y ? "==" : "!=") ." $y\n";
|
||||
function json_test_show_eq($x, $y) {
|
||||
echo "$x ". ( $x == $y ? "==" : "!=") ." $y\n";
|
||||
}
|
||||
|
||||
$value = 0x7FFFFFFF; #2147483647;
|
||||
show_eq("$value", json_encode($value));
|
||||
json_test_show_eq("$value", json_encode($value));
|
||||
$value++;
|
||||
show_eq("$value", json_encode($value));
|
||||
json_test_show_eq("$value", json_encode($value));
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
|
|
@ -4,7 +4,7 @@ Bug #41034 (json_encode() ignores null byte started keys in arrays)
|
|||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
echo json_encode(array(0,"\0ab"=>1,"\0null-prefixed value"));
|
||||
echo json_encode(array(0, "\0ab"=>1, "\0null-prefixed value"));
|
||||
echo "\nDone\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
Bug #41403 (json_decode cannot decode floats if localeconv decimal_point is not '.')
|
||||
--SKIPIF--
|
||||
<?php
|
||||
|
||||
if (!extension_loaded('json')) die('skip');
|
||||
|
||||
if (setlocale(LC_NUMERIC, "de_DE") === false) {
|
||||
die("skip no de_DE locale");
|
||||
}
|
||||
|
|
|
@ -2,20 +2,19 @@
|
|||
Bug #42785 (Incorrect formatting of double values with non-english locales)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded("json")) {
|
||||
print "skip";
|
||||
} else if (!setlocale(LC_CTYPE, "de_DE", "de", "german", "ge", "de_DE.ISO8859-1", "ISO8859-1")) {
|
||||
die("skip locale needed for this test is not supported on this platform");
|
||||
}
|
||||
if (!extension_loaded('json')) die('skip');
|
||||
if (!setlocale(LC_CTYPE, "de_DE", "de", "german", "ge", "de_DE.ISO8859-1", "ISO8859-1")) {
|
||||
die("skip locale needed for this test is not supported on this platform");
|
||||
}
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
setlocale(LC_ALL, "de_DE", "de", "german", "ge", "de_DE.ISO8859-1", "ISO8859-1");
|
||||
|
||||
$foo = Array(100.10,"bar");
|
||||
$foo = array(100.10,"bar");
|
||||
var_dump(json_encode($foo));
|
||||
|
||||
Class bar {}
|
||||
class bar {}
|
||||
$bar1 = new bar;
|
||||
$bar1->a = 100.10;
|
||||
$bar1->b = "foo";
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
--TEST--
|
||||
Bug #46215 (json_encode mutates its parameter and has some class-specific state)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded("json")) {
|
||||
die('skip JSON extension not available in this build');
|
||||
}
|
||||
?>
|
||||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class foo {
|
||||
protected $a = array();
|
||||
protected $a = array();
|
||||
}
|
||||
|
||||
$a = new foo;
|
||||
|
|
|
@ -6,8 +6,8 @@ Bug #46944 (json_encode() doesn't handle 3 byte utf8 correctly)
|
|||
<?php
|
||||
|
||||
for ($i = 1; $i <= 16; $i++) {
|
||||
$first = 0xf0|($i >> 2);
|
||||
$second = 0x8f|($i & 3) << 4;
|
||||
$first = 0xf0 | ($i >> 2);
|
||||
$second = 0x8f | ($i & 3) << 4;
|
||||
$string = sprintf("aa%c%c\xbf\xbdzz", $first, $second);
|
||||
echo json_encode($string) . "\n";
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
Bug #47644 (valid large integers are truncated)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('json')) die('skip: json extension not available');
|
||||
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
|
||||
if (!extension_loaded('json')) die('skip');
|
||||
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
|
|
@ -22,8 +22,8 @@ json_encode($b);
|
|||
var_dump(json_last_error(), json_last_error_msg());
|
||||
|
||||
$c = array(
|
||||
'foo' => $bad_utf8,
|
||||
'bar' => 1
|
||||
'foo' => $bad_utf8,
|
||||
'bar' => 1
|
||||
);
|
||||
json_encode($c);
|
||||
var_dump(json_last_error(), json_last_error_msg());
|
||||
|
|
|
@ -10,11 +10,9 @@ var_dump(json_last_error());
|
|||
json_decode("");
|
||||
var_dump(json_last_error());
|
||||
|
||||
|
||||
json_decode("invalid json");
|
||||
var_dump(json_last_error());
|
||||
|
||||
|
||||
json_decode("");
|
||||
var_dump(json_last_error());
|
||||
?>
|
||||
|
|
|
@ -6,25 +6,25 @@ Bug #61978 (Object recursion not detected for classes that implement JsonSeriali
|
|||
<?php
|
||||
|
||||
class JsonTest1 {
|
||||
public $test;
|
||||
public $me;
|
||||
public function __construct() {
|
||||
$this->test = '123';
|
||||
$this->me = $this;
|
||||
}
|
||||
public $test;
|
||||
public $me;
|
||||
public function __construct() {
|
||||
$this->test = '123';
|
||||
$this->me = $this;
|
||||
}
|
||||
}
|
||||
|
||||
class JsonTest2 implements JsonSerializable {
|
||||
public $test;
|
||||
public function __construct() {
|
||||
$this->test = '123';
|
||||
}
|
||||
public function jsonSerialize() {
|
||||
return array(
|
||||
'test' => $this->test,
|
||||
'me' => $this
|
||||
);
|
||||
}
|
||||
public $test;
|
||||
public function __construct() {
|
||||
$this->test = '123';
|
||||
}
|
||||
public function jsonSerialize() {
|
||||
return array(
|
||||
'test' => $this->test,
|
||||
'me' => $this
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,28 +6,28 @@ FR #62369 (Segfault on json_encode(deeply_nested_array)
|
|||
<?php
|
||||
|
||||
$array = array();
|
||||
for ($i=0; $i<550; $i++) {
|
||||
$array = array($array);
|
||||
for ($i=0; $i < 550; $i++) {
|
||||
$array = array($array);
|
||||
}
|
||||
|
||||
json_encode($array, 0, 551);
|
||||
switch (json_last_error()) {
|
||||
case JSON_ERROR_NONE:
|
||||
echo 'OK'.PHP_EOL;
|
||||
break;
|
||||
case JSON_ERROR_DEPTH:
|
||||
echo 'ERROR'.PHP_EOL;
|
||||
break;
|
||||
case JSON_ERROR_NONE:
|
||||
echo 'OK' . PHP_EOL;
|
||||
break;
|
||||
case JSON_ERROR_DEPTH:
|
||||
echo 'ERROR' . PHP_EOL;
|
||||
break;
|
||||
}
|
||||
|
||||
json_encode($array, 0, 540);
|
||||
switch (json_last_error()) {
|
||||
case JSON_ERROR_NONE:
|
||||
echo 'OK'.PHP_EOL;
|
||||
break;
|
||||
case JSON_ERROR_DEPTH:
|
||||
echo 'ERROR'.PHP_EOL;
|
||||
break;
|
||||
case JSON_ERROR_NONE:
|
||||
echo 'OK' . PHP_EOL;
|
||||
break;
|
||||
case JSON_ERROR_DEPTH:
|
||||
echo 'ERROR' . PHP_EOL;
|
||||
break;
|
||||
}
|
||||
--EXPECTF--
|
||||
OK
|
||||
|
|
|
@ -5,10 +5,10 @@ Bug #63737 (json_decode does not properly decode with options parameter)
|
|||
--FILE--
|
||||
<?php
|
||||
function decode($json) {
|
||||
$x = json_decode($json);
|
||||
var_dump($x);
|
||||
$x = json_decode($json, false, 512, JSON_BIGINT_AS_STRING);
|
||||
var_dump($x);
|
||||
$x = json_decode($json);
|
||||
var_dump($x);
|
||||
$x = json_decode($json, false, 512, JSON_BIGINT_AS_STRING);
|
||||
var_dump($x);
|
||||
}
|
||||
|
||||
decode('123456789012345678901234567890');
|
||||
|
|
|
@ -5,9 +5,9 @@ Whitespace part of bug #64874 ("json_decode handles whitespace and case-sensitiv
|
|||
--FILE--
|
||||
<?php
|
||||
function decode($json) {
|
||||
var_dump(json_decode($json));
|
||||
var_dump(json_last_error() !== 0);
|
||||
echo "\n";
|
||||
var_dump(json_decode($json));
|
||||
var_dump(json_last_error() !== 0);
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
// Leading whitespace should be ignored
|
||||
|
|
|
@ -5,8 +5,8 @@ Case-sensitivity part of bug #64874 ("json_decode handles whitespace and case-se
|
|||
--FILE--
|
||||
<?php
|
||||
function decode($json) {
|
||||
var_dump(json_decode($json));
|
||||
echo ((json_last_error() !== 0) ? 'ERROR' : 'SUCCESS') . PHP_EOL;
|
||||
var_dump(json_decode($json));
|
||||
echo ((json_last_error() !== 0) ? 'ERROR' : 'SUCCESS') . PHP_EOL;
|
||||
}
|
||||
|
||||
// Only lowercase should work
|
||||
|
|
|
@ -9,7 +9,7 @@ class Foo {
|
|||
private $bar = 'baz';
|
||||
}
|
||||
|
||||
echo json_encode([[], (object)[], new Foo], JSON_PRETTY_PRINT), "\n";
|
||||
echo json_encode(array(array(), (object) array(), new Foo), JSON_PRETTY_PRINT);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
|
|
@ -2,43 +2,44 @@
|
|||
JSON (http://www.crockford.com/JSON/JSON_checker/test/fail*.json)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('json')) die('skip: json extension not available');
|
||||
if (!extension_loaded('json')) die('skip');
|
||||
?>
|
||||
--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']");
|
||||
$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));
|
||||
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));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,50 +1,41 @@
|
|||
--TEST--
|
||||
Test json_decode() function : basic functionality
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded("json")) {
|
||||
die('skip JSON extension not available in this build');
|
||||
}
|
||||
?>
|
||||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : mixed json_decode ( string $json [, bool $assoc ] )
|
||||
* Description: Decodes a JSON string
|
||||
* Source code: ext/json/php_json.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
echo "*** Testing json_decode() : basic functionality ***\n";
|
||||
|
||||
// array with different values for $string
|
||||
$inputs = array (
|
||||
'0',
|
||||
'123',
|
||||
'-123',
|
||||
'2147483647',
|
||||
'-2147483648',
|
||||
'123.456',
|
||||
'1230',
|
||||
'-1230',
|
||||
'true',
|
||||
'false',
|
||||
'null',
|
||||
'"abc"',
|
||||
'"Hello World\r\n"',
|
||||
'[]',
|
||||
'[1,2,3,4,5]',
|
||||
'{"myInt":99,"myFloat":123.45,"myNull":null,"myBool":true,"myString":"Hello World"}',
|
||||
'{"Jan":31,"Feb":29,"Mar":31,"April":30,"May":31,"June":30}',
|
||||
'""',
|
||||
'{}'
|
||||
'0',
|
||||
'123',
|
||||
'-123',
|
||||
'2147483647',
|
||||
'-2147483648',
|
||||
'123.456',
|
||||
'1230',
|
||||
'-1230',
|
||||
'true',
|
||||
'false',
|
||||
'null',
|
||||
'"abc"',
|
||||
'"Hello World\r\n"',
|
||||
'[]',
|
||||
'[1,2,3,4,5]',
|
||||
'{"myInt":99,"myFloat":123.45,"myNull":null,"myBool":true,"myString":"Hello World"}',
|
||||
'{"Jan":31,"Feb":29,"Mar":31,"April":30,"May":31,"June":30}',
|
||||
'""',
|
||||
'{}'
|
||||
);
|
||||
|
||||
// loop through with each element of the $inputs array to test json_decode() function
|
||||
$count = 1;
|
||||
foreach($inputs as $input) {
|
||||
echo "-- Iteration $count --\n";
|
||||
var_dump(json_decode($input));
|
||||
var_dump(json_decode($input, TRUE));
|
||||
$count ++;
|
||||
echo "-- Iteration $count --\n";
|
||||
var_dump(json_decode($input));
|
||||
var_dump(json_decode($input, true));
|
||||
$count++;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,26 +1,17 @@
|
|||
--TEST--
|
||||
Test json_decode() function : error conditions
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded("json")) {
|
||||
die('skip JSON extension not available in this build');
|
||||
}
|
||||
?>
|
||||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : mixed json_decode ( string $json [, bool $assoc=false [, int $depth=512 ]] )
|
||||
* Description: Decodes a JSON string
|
||||
* Source code: ext/json/php_json.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
echo "*** Testing json_decode() : error conditions ***\n";
|
||||
|
||||
echo "\n-- Testing json_decode() function with no arguments --\n";
|
||||
var_dump( json_decode() );
|
||||
var_dump(json_decode());
|
||||
|
||||
echo "\n-- Testing json_decode() function with more than expected no. of arguments --\n";
|
||||
$extra_arg = 10;
|
||||
var_dump( json_decode('"abc"', TRUE, 512, 0, $extra_arg) );
|
||||
var_dump(json_decode('"abc"', true, 512, 0, $extra_arg));
|
||||
|
||||
?>
|
||||
===Done===
|
||||
|
|
|
@ -1,18 +1,9 @@
|
|||
--TEST--
|
||||
Test json_encode() function : basic functionality
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded("json")) {
|
||||
die('skip JSON extension not available in this build');
|
||||
}
|
||||
?>
|
||||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string json_encode ( mixed $value )
|
||||
* Description: Returns the JSON representation of a value
|
||||
* Source code: ext/json/php_json.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
echo "*** Testing json_encode() : basic functionality ***\n";
|
||||
|
||||
//get an unset variable
|
||||
|
@ -35,64 +26,63 @@ $obj->MyString = "Hello World";
|
|||
|
||||
// array with different values for $string
|
||||
$inputs = array (
|
||||
// integers
|
||||
0,
|
||||
123,
|
||||
-123,
|
||||
2147483647,
|
||||
-2147483648,
|
||||
|
||||
// integers
|
||||
/*1*/ 0,
|
||||
123,
|
||||
-123,
|
||||
2147483647,
|
||||
-2147483648,
|
||||
// floats
|
||||
123.456,
|
||||
1.23E3,
|
||||
-1.23E3,
|
||||
|
||||
// floats
|
||||
/*6*/ 123.456,
|
||||
1.23E3,
|
||||
-1.23E3,
|
||||
// boolean
|
||||
TRUE,
|
||||
true,
|
||||
FALSE,
|
||||
false,
|
||||
|
||||
// NULL
|
||||
NULL,
|
||||
null,
|
||||
|
||||
// boolean
|
||||
/*9*/ TRUE,
|
||||
true,
|
||||
FALSE,
|
||||
false,
|
||||
// strings
|
||||
"abc",
|
||||
'abc',
|
||||
"Hello\t\tWorld\n",
|
||||
|
||||
// NULL
|
||||
/*13*/ NULL,
|
||||
null,
|
||||
|
||||
// strings
|
||||
/*15*/ "abc",
|
||||
'abc',
|
||||
"Hello\t\tWorld\n",
|
||||
|
||||
// arrays
|
||||
/*18*/ array(),
|
||||
array(1,2,3,4,5),
|
||||
array(1 => "Sun", 2=>"Mon", 3 => "Tue", 4 => "Wed", 5 => "Thur", 6 => "Fri", 7 => "Sat"),
|
||||
array("Jan" => 31, "Feb" => 29, "Mar" => 31, "April" => 30, "May" => 31, "June" => 30),
|
||||
|
||||
// empty data
|
||||
/*22*/ "",
|
||||
'',
|
||||
// arrays
|
||||
array(),
|
||||
array(1,2,3,4,5),
|
||||
array(1 => "Sun", 2 => "Mon", 3 => "Tue", 4 => "Wed", 5 => "Thur", 6 => "Fri", 7 => "Sat"),
|
||||
array("Jan" => 31, "Feb" => 29, "Mar" => 31, "April" => 30, "May" => 31, "June" => 30),
|
||||
|
||||
// undefined data
|
||||
/*24*/ @$undefined_var,
|
||||
// empty data
|
||||
"",
|
||||
'',
|
||||
|
||||
// unset data
|
||||
/*25*/ @$unset_var,
|
||||
// undefined data
|
||||
@$undefined_var,
|
||||
|
||||
// resource variable
|
||||
/*26*/ $fp,
|
||||
// unset data
|
||||
@$unset_var,
|
||||
|
||||
// object variable
|
||||
/*27*/ $obj
|
||||
// resource variable
|
||||
$fp,
|
||||
|
||||
// object variable
|
||||
$obj
|
||||
|
||||
);
|
||||
|
||||
// loop through with each element of the $inputs array to test json_encode() function
|
||||
$count = 1;
|
||||
foreach($inputs as $input) {
|
||||
echo "-- Iteration $count --\n";
|
||||
var_dump(json_encode($input));
|
||||
$count ++;
|
||||
echo "-- Iteration $count --\n";
|
||||
var_dump(json_encode($input));
|
||||
$count ++;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,18 +1,9 @@
|
|||
--TEST--
|
||||
Test json_encode() function : basic functionality with UTF8 string input
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded("json")) {
|
||||
die('skip JSON extension not available in this build');
|
||||
}
|
||||
?>
|
||||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string json_encode ( mixed $value )
|
||||
* Description: Returns the JSON representation of a value
|
||||
* Source code: ext/json/php_json.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
echo "*** Testing json_encode() : basic functionality with UTF-8 input***\n";
|
||||
|
||||
$utf8_string = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
|
||||
|
|
|
@ -1,27 +1,17 @@
|
|||
--TEST--
|
||||
Test json_encode() function : error conditions
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded("json")) {
|
||||
die('skip JSON extension not available in this build');
|
||||
}
|
||||
?>
|
||||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string json_encode ( mixed $value [, int $options=0 ] )
|
||||
* Description: Returns the JSON representation of a value
|
||||
* Source code: ext/json/php_json.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
echo "*** Testing json_encode() : error conditions ***\n";
|
||||
|
||||
echo "\n-- Testing json_encode() function with no arguments --\n";
|
||||
var_dump( json_encode() );
|
||||
var_dump(json_encode());
|
||||
|
||||
echo "\n-- Testing json_encode() function with more than expected no. of arguments --\n";
|
||||
$extra_arg = 10;
|
||||
var_dump( json_encode("abc", 0, $extra_arg) );
|
||||
var_dump(json_encode("abc", 0, $extra_arg));
|
||||
|
||||
?>
|
||||
===Done===
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
--TEST--
|
||||
Test json_encode() function with numeric flag
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded("json")) {
|
||||
die('skip JSON extension not available in this build');
|
||||
}
|
||||
?>
|
||||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
--TEST--
|
||||
json_last_error() failures
|
||||
--SKIPIF--
|
||||
<?php !extension_loaded('json') && die('skip json extension not available') ?>
|
||||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
var_dump(json_last_error());
|
||||
var_dump(json_last_error(TRUE));
|
||||
var_dump(json_last_error(true));
|
||||
var_dump(json_last_error('some', 4, 'args', 'here'));
|
||||
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
int(0)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
--TEST--
|
||||
json_last_error_msg() failures
|
||||
--SKIPIF--
|
||||
<?php !extension_loaded('json') && die('skip json extension not available') ?>
|
||||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
var_dump(json_last_error_msg());
|
||||
var_dump(json_last_error_msg(TRUE));
|
||||
var_dump(json_last_error_msg(true));
|
||||
var_dump(json_last_error_msg('some', 4, 'args', 'here'));
|
||||
|
||||
?>
|
||||
|
|
|
@ -4,8 +4,8 @@ JSON (http://www.crockford.com/JSON/JSON_checker/test/pass1.json)
|
|||
precision=14
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('json')) die('skip: json extension not available');
|
||||
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
|
||||
if (!extension_loaded('json')) die('skip');
|
||||
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
|
|
@ -4,8 +4,8 @@ JSON (http://www.crockford.com/JSON/JSON_checker/test/pass1.json)
|
|||
precision=14
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('json')) die('skip: json extension not available');
|
||||
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
|
||||
if (!extension_loaded('json')) die('skip');
|
||||
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
|
|
@ -4,7 +4,7 @@ JSON (http://www.crockford.com/JSON/JSON_checker/test/pass1.json)
|
|||
precision=14
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('json')) die('skip: json extension not available');
|
||||
if (!extension_loaded('json')) die('skip');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
--TEST--
|
||||
JSON (http://www.crockford.com/JSON/JSON_checker/test/pass2.json)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('json')) die('skip: json extension not available');
|
||||
?>
|
||||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
--TEST--
|
||||
JSON (http://www.crockford.com/JSON/JSON_checker/test/pass3.json)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('json')) die('skip: json extension not available');
|
||||
?>
|
||||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue