@@ 44-59 (lines=16) @@ | ||
41 | * @todo There are a ton more permutations of a JSONPath regex |
|
42 | * See the trace() method in JSONPath for more examples to work from |
|
43 | */ |
|
44 | public function testIsValidExpression() |
|
45 | { |
|
46 | $field = JSONText::create('MyJSON'); |
|
47 | ||
48 | $this->assertTrue($field->isValidExpression('$..')); |
|
49 | $this->assertTrue($field->isValidExpression('*')); |
|
50 | $this->assertTrue($field->isValidExpression('$.[2]')); |
|
51 | $this->assertTrue($field->isValidExpression('$.cars.american[*]')); |
|
52 | $this->assertTrue($field->isValidExpression('[0:1:1]')); |
|
53 | $this->assertFalse($field->isValidExpression('[0:1:]')); |
|
54 | $this->assertFalse($field->isValidExpression('[0:1:1')); |
|
55 | $this->assertFalse($field->isValidExpression('')); |
|
56 | $this->assertFalse($field->isValidExpression('$.1.cars.american[*]')); |
|
57 | $this->assertFalse($field->isValidExpression('$')); |
|
58 | $this->assertFalse($field->isValidExpression('$[2]')); |
|
59 | } |
|
60 | ||
61 | /** |
|
62 | * @return void |
|
@@ 64-79 (lines=16) @@ | ||
61 | /** |
|
62 | * @return void |
|
63 | */ |
|
64 | public function testIsValidJson() |
|
65 | { |
|
66 | $field = JSONText::create('MyJSON'); |
|
67 | ||
68 | $this->assertFalse($field->isValidJson('')); |
|
69 | $this->assertTrue($field->isValidJson('true')); |
|
70 | $this->assertTrue($field->isValidJson('false')); |
|
71 | $this->assertFalse($field->isValidJson('null')); |
|
72 | $this->assertFalse($field->isValidJson("['one']")); |
|
73 | $this->assertFalse($field->isValidJson('["one]')); |
|
74 | $this->assertFalse($field->isValidJson('{{{')); |
|
75 | $this->assertTrue($field->isValidJson('[]')); |
|
76 | $this->assertTrue($field->isValidJson('["one"]')); |
|
77 | $this->assertTrue($field->isValidJson('["one","two"]')); |
|
78 | $this->assertTrue($field->isValidJson('{"cars":{"american":["buick","oldsmobile"]}}')); |
|
79 | } |
|
80 | ||
81 | ||
82 | /** |