-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPointersTest.class.php
More file actions
134 lines (120 loc) · 3.71 KB
/
Copy pathPointersTest.class.php
File metadata and controls
134 lines (120 loc) · 3.71 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php namespace text\json\unittest;
use lang\FormatException;
use test\{Assert, Expect, Test, Values};
use text\json\{Pointers, Types, StringInput};
class PointersTest {
/** @return iterable */
private function values() {
yield ['"test"', 'test'];
yield ['true', true];
yield ['false', false];
yield ['null', null];
yield ['1', 1];
yield ['1.5', 1.5];
}
#[Test]
public function can_create() {
new Pointers(new StringInput(''));
}
#[Test, Values(from: 'values')]
public function toplevel($input, $expected) {
Assert::equals(['' => $expected], iterator_to_array(new Pointers(new StringInput($input))));
}
#[Test]
public function empty_array() {
Assert::equals(['' => Types::$ARRAY], iterator_to_array(new Pointers(new StringInput('[]'))));
}
#[Test]
public function empty_object() {
Assert::equals(['' => Types::$OBJECT], iterator_to_array(new Pointers(new StringInput('{}'))));
}
#[Test]
public function rfc_example() {
$input= <<<'JSON'
{
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
}
JSON
;
Assert::equals(
[
'' => Types::$OBJECT,
'/foo' => Types::$ARRAY,
'/foo/0' => 'bar',
'/foo/1' => 'baz',
'/' => 0,
'/a~1b' => 1,
'/c%d' => 2,
'/e^f' => 3,
'/g|h' => 4,
'/i\\j' => 5,
'/k"l' => 6,
'/ ' => 7,
'/m~0n' => 8,
],
iterator_to_array(new Pointers(new StringInput($input)))
);
}
#[Test]
public function composer_file() {
$input= <<<'JSON'
{
"name": "example/test",
"keywords": ["module", "xp"],
"require": {
"xp-forge/json": "^6.1",
"php": ">=7.4.0"
},
"autoload" : {
"files" : ["src/main/php/autoload.php"]
}
}
JSON
;
Assert::equals(
[
'' => Types::$OBJECT,
'/name' => 'example/test',
'/keywords' => Types::$ARRAY,
'/keywords/0' => 'module',
'/keywords/1' => 'xp',
'/require' => Types::$OBJECT,
'/require/xp-forge~1json' => '^6.1',
'/require/php' => '>=7.4.0',
'/autoload' => Types::$OBJECT,
'/autoload/files' => Types::$ARRAY,
'/autoload/files/0' => 'src/main/php/autoload.php',
],
iterator_to_array(new Pointers(new StringInput($input)))
);
}
#[Test, Expect(class: FormatException::class, message: 'Empty input')]
public function empty_input() {
iterator_to_array(new Pointers(new StringInput('')));
}
#[Test, Expect(class: FormatException::class, message: 'Unexpected token ["test"] reading value')]
public function invalid_literal() {
iterator_to_array(new Pointers(new StringInput('test')));
}
#[Test, Expect(class: FormatException::class, message: 'Unexpected token ["2"] reading array, expecting "," or "]"')]
public function missing_comma_in_array() {
iterator_to_array(new Pointers(new StringInput('[1 2]')));
}
#[Test, Expect(class: FormatException::class, message: 'Unexpected token ["2"] reading object, expecting ":"')]
public function missing_colon_in_object() {
iterator_to_array(new Pointers(new StringInput('{"key" 2}')));
}
#[Test, Expect(class: FormatException::class, message: 'Unexpected token ["2"] reading object, expecting "," or "}"')]
public function missing_comma_in_object() {
iterator_to_array(new Pointers(new StringInput('{"key": "value" 2}')));
}
}