1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#!/www/server/bin/php -qC
<?php
# Tests for itjs.class, currently only itjs::serialize()
$GLOBALS['ULTRASERVERTYPE'] = "live"; # don't prettyprint json
$_GET['aa'] = 1;
is(
itjs::serialize(null),
'null',
'null'
);
is(
itjs::serialize([]),
'[]',
'empty array'
);
is(
itjs::serialize([0, "0"]),
'[0,"0"]',
'number strings stay strings'
);
is(
itjs::serialize([null, "", false]),
'[null,"",false]',
'null, empty string, false'
);
is(
itjs::serialize(['foo' => "bar", "qux", 42 => "quux"]),
'{"foo":"bar","0":"qux","42":"quux"}',
'key-value pairs'
);
is(
itjs::serialize(['foo' => ['bar' => ["qux", 42]]]),
'{"foo":{"bar":["qux",42]}}',
'nested arrays'
);
is(
itjs::serialize(['import' => ['function' => [true, 42]]]),
'{"import":{"function":[true,42]}}',
'keywords'
);
is(
itjs::serialize(['foo"foo' => "bar"]),
'{"foo\"foo":"bar"}',
"quote ' in keys"
);
is(
itjs::serialize("</script>"),
'"\\u003C\\/script\\u003E"',
"quote slashes"
);
is(
itjs::serialize("hellö"),
'"hellö"',
"don't encode utf8"
);
|