Port TestExtJson
Esse commit está contido em:
@@ -37,7 +37,6 @@
|
||||
#include "hphp/test/ext/test_ext_curl.h"
|
||||
#include "hphp/test/ext/test_ext_imagesprite.h"
|
||||
#include "hphp/test/ext/test_ext_ipc.h"
|
||||
#include "hphp/test/ext/test_ext_json.h"
|
||||
#include "hphp/test/ext/test_ext_mailparse.h"
|
||||
#include "hphp/test/ext/test_ext_math.h"
|
||||
#include "hphp/test/ext/test_ext_mb.h"
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| HipHop for PHP |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.01 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.php.net/license/3_01.txt |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#include "hphp/test/ext/test_ext_json.h"
|
||||
#include "hphp/runtime/ext/ext_json.h"
|
||||
#include "hphp/system/systemlib.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TestExtJson::RunTests(const std::string &which) {
|
||||
bool ret = true;
|
||||
|
||||
RUN_TEST(test_json_encode);
|
||||
RUN_TEST(test_json_decode);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TestExtJson::test_json_encode() {
|
||||
VS(f_json_encode(CREATE_MAP3("a", 1, "b", 2.3, 3, "test")),
|
||||
"{\"a\":1,\"b\":2.3,\"3\":\"test\"}");
|
||||
VS(f_json_encode(CREATE_VECTOR5("a", 1, true, false, uninit_null())),
|
||||
"[\"a\",1,true,false,null]");
|
||||
|
||||
VS(f_json_encode("a\xE0"), "null");
|
||||
VS(f_json_encode("a\xE0", k_JSON_FB_LOOSE), "\"a?\"");
|
||||
|
||||
VS(f_json_encode(CREATE_MAP2("0", "apple", "1", "banana")),
|
||||
"[\"apple\",\"banana\"]");
|
||||
|
||||
VS(f_json_encode(CREATE_VECTOR1(CREATE_MAP1("a", "apple"))),
|
||||
"[{\"a\":\"apple\"}]");
|
||||
|
||||
VS(f_json_encode(CREATE_VECTOR1(CREATE_MAP1("a", "apple")),
|
||||
k_JSON_PRETTY_PRINT),
|
||||
"[\n {\n \"a\": \"apple\"\n }\n]");
|
||||
|
||||
VS(f_json_encode(CREATE_VECTOR4(1, 2, 3, CREATE_VECTOR3(1, 2, 3)),
|
||||
k_JSON_PRETTY_PRINT),
|
||||
"[\n"
|
||||
" 1,\n"
|
||||
" 2,\n"
|
||||
" 3,\n"
|
||||
" [\n"
|
||||
" 1,\n"
|
||||
" 2,\n"
|
||||
" 3\n"
|
||||
" ]\n"
|
||||
"]");
|
||||
|
||||
Array arr = CREATE_MAP3(
|
||||
"a", 1,
|
||||
"b", CREATE_VECTOR2(1, 2),
|
||||
"c", CREATE_MAP1("d", 42)
|
||||
);
|
||||
VS(f_json_encode(arr, k_JSON_PRETTY_PRINT),
|
||||
"{\n"
|
||||
" \"a\": 1,\n"
|
||||
" \"b\": [\n"
|
||||
" 1,\n"
|
||||
" 2\n"
|
||||
" ],\n"
|
||||
" \"c\": {\n"
|
||||
" \"d\": 42\n"
|
||||
" }\n"
|
||||
"}");
|
||||
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtJson::test_json_decode() {
|
||||
Array arr = CREATE_MAP1("fbid", 101501853510151001LL);
|
||||
VS(f_json_decode(f_json_encode(arr), true), arr);
|
||||
|
||||
VS(f_json_decode("{\"0\":{\"00\":0}}", true),
|
||||
CREATE_MAP1("0", CREATE_MAP1("00", 0)));
|
||||
|
||||
VS(f_json_decode("{\"a\":1,\"b\":2.3,\"3\":\"test\"}", true),
|
||||
CREATE_MAP3("a", 1, "b", 2.3, 3, "test"));
|
||||
VS(f_json_decode("[\"a\",1,true,false,null]", true),
|
||||
CREATE_VECTOR5("a", 1, true, false, uninit_null()));
|
||||
|
||||
Object obj = f_json_decode("{\"a\":1,\"b\":2.3,\"3\":\"test\"}");
|
||||
Object obj2(SystemLib::AllocStdClassObject());
|
||||
obj2->o_set("a", 1);
|
||||
obj2->o_set("b", 2.3);
|
||||
obj2->o_set("3", "test");
|
||||
VS(obj.toArray(), obj2.toArray());
|
||||
|
||||
obj = f_json_decode("[\"a\",1,true,false,null]");
|
||||
VS(obj.toArray(), CREATE_VECTOR5("a", 1, true, false, uninit_null()));
|
||||
|
||||
VS(f_json_decode("{z:1}", true), uninit_null());
|
||||
VS(f_json_decode("{z:1}", true, k_JSON_FB_LOOSE), CREATE_MAP1("z", 1));
|
||||
VS(f_json_decode("{z:\"z\"}", true), uninit_null());
|
||||
VS(f_json_decode("{z:\"z\"}", true, k_JSON_FB_LOOSE), CREATE_MAP1("z", "z"));
|
||||
VS(f_json_decode("{'x':1}", true), uninit_null());
|
||||
VS(f_json_decode("{'x':1}", true, k_JSON_FB_LOOSE), CREATE_MAP1("x", 1));
|
||||
VS(f_json_decode("{y:1,}", true), uninit_null());
|
||||
VS(f_json_decode("{y:1,}", true, k_JSON_FB_LOOSE), CREATE_MAP1("y", 1));
|
||||
VS(f_json_decode("{,}", true), uninit_null());
|
||||
VS(f_json_decode("{,}", true, k_JSON_FB_LOOSE), uninit_null());
|
||||
VS(f_json_decode("[1,2,3,]", true), uninit_null());
|
||||
VS(f_json_decode("[1,2,3,]", true, k_JSON_FB_LOOSE), CREATE_VECTOR3(1,2,3));
|
||||
VS(f_json_decode("[,]", true), uninit_null());
|
||||
VS(f_json_decode("[,]", true, k_JSON_FB_LOOSE), uninit_null());
|
||||
VS(f_json_decode("[]", true), Array::Create());
|
||||
VS(f_json_decode("[]", true, k_JSON_FB_LOOSE), Array::Create());
|
||||
VS(f_json_decode("{}", true), Array::Create());
|
||||
VS(f_json_decode("{}", true, k_JSON_FB_LOOSE), Array::Create());
|
||||
|
||||
VS(f_json_decode("[{\"a\":\"apple\"},{\"b\":\"banana\"}]", true),
|
||||
CREATE_VECTOR2(CREATE_MAP1("a", "apple"), CREATE_MAP1("b", "banana")));
|
||||
|
||||
Variant a = "[{\"a\":[{\"n\":\"1st\"}]},{\"b\":[{\"n\":\"2nd\"}]}]";
|
||||
VS(f_json_decode(a, true),
|
||||
CREATE_VECTOR2
|
||||
(CREATE_MAP1("a", CREATE_VECTOR1(CREATE_MAP1("n", "1st"))),
|
||||
CREATE_MAP1("b", CREATE_VECTOR1(CREATE_MAP1("n", "2nd")))));
|
||||
|
||||
return Count(true);
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| HipHop for PHP |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.01 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.php.net/license/3_01.txt |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifndef incl_HPHP_TEST_EXT_JSON_H_
|
||||
#define incl_HPHP_TEST_EXT_JSON_H_
|
||||
|
||||
// >>>>>> Generated by idl.php. Do NOT modify. <<<<<<
|
||||
|
||||
#include "hphp/test/ext/test_cpp_ext.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TestExtJson : public TestCppExt {
|
||||
public:
|
||||
virtual bool RunTests(const std::string &which);
|
||||
|
||||
bool test_json_encode();
|
||||
bool test_json_decode();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // incl_HPHP_TEST_EXT_JSON_H_
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
|
||||
$arr = array("fbid" => 101501853510151001);
|
||||
var_dump(json_decode(json_encode($arr), true));
|
||||
|
||||
var_dump(json_decode("{\"0\":{\"00\":0}}", true));
|
||||
|
||||
var_dump(json_decode("{\"a\":1,\"b\":2.3,\"3\":\"test\"}", true));
|
||||
var_dump(json_decode("[\"a\",1,true,false,null]", true));
|
||||
|
||||
$obj = json_decode("[\"a\",1,true,false,null]");
|
||||
var_dump($obj);
|
||||
|
||||
var_dump(json_decode("{z:1}", true));
|
||||
var_dump(json_decode("{z:1}", true, JSON_FB_LOOSE));
|
||||
var_dump(json_decode("{z:\"z\"}", true));
|
||||
var_dump(json_decode("{z:\"z\"}", true, JSON_FB_LOOSE));
|
||||
var_dump(json_decode("{'x':1}", true));
|
||||
var_dump(json_decode("{'x':1}", true, JSON_FB_LOOSE));
|
||||
var_dump(json_decode("{y:1,}", true));
|
||||
var_dump(json_decode("{y:1,}", true, JSON_FB_LOOSE));
|
||||
var_dump(json_decode("{,}", true));
|
||||
var_dump(json_decode("{,}", true, JSON_FB_LOOSE));
|
||||
var_dump(json_decode("[1,2,3,]", true));
|
||||
var_dump(json_decode("[1,2,3,]", true, JSON_FB_LOOSE));
|
||||
var_dump(json_decode("[,]", true));
|
||||
var_dump(json_decode("[,]", true, JSON_FB_LOOSE));
|
||||
var_dump(json_decode("[]", true));
|
||||
var_dump(json_decode("[]", true, JSON_FB_LOOSE));
|
||||
var_dump(json_decode("{}", true));
|
||||
var_dump(json_decode("{}", true, JSON_FB_LOOSE));
|
||||
|
||||
var_dump(json_decode("[{\"a\":\"apple\"},{\"b\":\"banana\"}]", true));
|
||||
|
||||
$a = "[{\"a\":[{\"n\":\"1st\"}]},{\"b\":[{\"n\":\"2nd\"}]}]";
|
||||
var_dump(json_decode($a, true));
|
||||
@@ -0,0 +1,120 @@
|
||||
array(1) {
|
||||
["fbid"]=>
|
||||
int(101501853510151001)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
["00"]=>
|
||||
int(0)
|
||||
}
|
||||
}
|
||||
array(3) {
|
||||
["a"]=>
|
||||
int(1)
|
||||
["b"]=>
|
||||
float(2.3)
|
||||
[3]=>
|
||||
string(4) "test"
|
||||
}
|
||||
array(5) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
int(1)
|
||||
[2]=>
|
||||
bool(true)
|
||||
[3]=>
|
||||
bool(false)
|
||||
[4]=>
|
||||
NULL
|
||||
}
|
||||
array(5) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
int(1)
|
||||
[2]=>
|
||||
bool(true)
|
||||
[3]=>
|
||||
bool(false)
|
||||
[4]=>
|
||||
NULL
|
||||
}
|
||||
NULL
|
||||
array(1) {
|
||||
["z"]=>
|
||||
int(1)
|
||||
}
|
||||
NULL
|
||||
array(1) {
|
||||
["z"]=>
|
||||
string(1) "z"
|
||||
}
|
||||
NULL
|
||||
array(1) {
|
||||
["x"]=>
|
||||
int(1)
|
||||
}
|
||||
NULL
|
||||
array(1) {
|
||||
["y"]=>
|
||||
int(1)
|
||||
}
|
||||
NULL
|
||||
NULL
|
||||
NULL
|
||||
array(3) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
[2]=>
|
||||
int(3)
|
||||
}
|
||||
NULL
|
||||
NULL
|
||||
array(0) {
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
["a"]=>
|
||||
string(5) "apple"
|
||||
}
|
||||
[1]=>
|
||||
array(1) {
|
||||
["b"]=>
|
||||
string(6) "banana"
|
||||
}
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
["a"]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
["n"]=>
|
||||
string(3) "1st"
|
||||
}
|
||||
}
|
||||
}
|
||||
[1]=>
|
||||
array(1) {
|
||||
["b"]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
["n"]=>
|
||||
string(3) "2nd"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
var_dump(json_encode(array("a" => 1, "b" => 2.3, 3 => "test")));
|
||||
var_dump(json_encode(array("a", 1, true, false, null)));
|
||||
|
||||
var_dump(json_encode("a\xE0"));
|
||||
var_dump(json_encode("a\xE0", JSON_FB_LOOSE));
|
||||
|
||||
var_dump(json_encode(array("0" => "apple", "1" => "banana")));
|
||||
|
||||
var_dump(json_encode(array(array("a" => "apple"))));
|
||||
|
||||
var_dump(json_encode(array(array("a" => "apple")), JSON_PRETTY_PRINT));
|
||||
|
||||
var_dump(json_encode(array(1, 2, 3, array(1, 2, 3)), JSON_PRETTY_PRINT));
|
||||
|
||||
$arr = array(
|
||||
"a" => 1,
|
||||
"b" => array(1, 2),
|
||||
"c" => array("d" => 42)
|
||||
);
|
||||
var_dump(json_encode($arr, JSON_PRETTY_PRINT));
|
||||
@@ -0,0 +1,31 @@
|
||||
string(26) "{"a":1,"b":2.3,"3":"test"}"
|
||||
string(23) "["a",1,true,false,null]"
|
||||
string(4) "null"
|
||||
string(4) ""a?""
|
||||
string(18) "["apple","banana"]"
|
||||
string(15) "[{"a":"apple"}]"
|
||||
string(36) "[
|
||||
{
|
||||
"a": "apple"
|
||||
}
|
||||
]"
|
||||
string(68) "[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
]"
|
||||
string(87) "{
|
||||
"a": 1,
|
||||
"b": [
|
||||
1,
|
||||
2
|
||||
],
|
||||
"c": {
|
||||
"d": 42
|
||||
}
|
||||
}"
|
||||
Referência em uma Nova Issue
Bloquear um usuário