-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComparisonsTest.php
More file actions
135 lines (104 loc) · 3.59 KB
/
ComparisonsTest.php
File metadata and controls
135 lines (104 loc) · 3.59 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
135
<?php
declare(strict_types=1);
use function Loilo\JsonPath\nothing;
use function Loilo\JsonPath\eval_compare;
describe('2.3.5.2.2. Comparisons', function () {
describe('2.3.5.3. Examples', function () {
$obj = (object) ['json' => (object) ['x' => 'y']];
$array = (object) ['json' => [2, 3]];
it('Empty nodelists 1', function () {
expect(eval_compare(nothing(), nothing(), '=='))->toBe(true);
});
it('equals implies lte 1', function () {
expect(eval_compare(nothing(), nothing(), '<='))->toBe(true);
});
it('Empty nodelist 1', function () {
expect(
eval_compare(nothing(), (object) ['json' => 'g'], '=='),
)->toBe(false);
});
it('Empty nodelists 2', function () {
expect(eval_compare(nothing(), nothing(), '!='))->toBe(false);
});
it('Empty nodelist 2', function () {
expect(
eval_compare(nothing(), (object) ['json' => 'g'], '!='),
)->toBe(true);
});
it('Numeric comparison', function () {
expect(eval_compare(1, 2, '<='))->toBe(true);
});
it('Strict, numeric comparison', function () {
expect(eval_compare(1, 2, '>'))->toBe(false);
});
it('Type mismatch 1', function () {
expect(eval_compare(13, '13', '=='))->toBe(false);
});
it('String comparison', function () {
expect(eval_compare('a', 'b', '<='))->toBe(true);
});
it('Strict, string comparison', function () {
expect(eval_compare('a', 'b', '>'))->toBe(false);
});
it('Type mismatch 2', function () use ($obj, $array) {
expect(eval_compare($obj, $array, '=='))->toBe(false);
});
it('Type mismatch 3', function () use ($obj, $array) {
expect(eval_compare($obj, $array, '!='))->toBe(true);
});
it('Object comparison 1', function () use ($obj) {
expect(eval_compare($obj, $obj, '=='))->toBe(true);
});
it('Object comparison 2', function () use ($obj) {
expect(eval_compare($obj, $obj, '!='))->toBe(false);
});
it('Array comparison 1', function () use ($array) {
expect(eval_compare($array, $array, '=='))->toBe(true);
});
it('Array comparison 2', function () use ($array) {
expect(eval_compare($array, $array, '!='))->toBe(false);
});
it('Type mismatch 4', function () use ($obj) {
expect(eval_compare($obj, 17, '=='))->toBe(false);
});
it('Type mismatch 5', function () use ($obj) {
expect(eval_compare($obj, 17, '!='))->toBe(true);
});
it('Objects and arrays do not offer lte comparison', function () use (
$obj,
$array
) {
expect(eval_compare($obj, $array, '<='))->toBe(false);
});
it('Objects and arrays do not offer lt comparison', function () use (
$obj,
$array
) {
expect(eval_compare($obj, $array, '<'))->toBe(false);
});
it('equals implies lte 2', function () use ($obj) {
expect(eval_compare($obj, $obj, '<='))->toBe(true);
});
it('equals implies lte 3', function () use ($array) {
expect(eval_compare($array, $array, '<='))->toBe(true);
});
it('Arrays do not offer lte comparison', function () use ($array) {
expect(eval_compare(1, $array, '<='))->toBe(false);
});
it('Arrays do not offer gte comparison', function () use ($array) {
expect(eval_compare(1, $array, '>='))->toBe(false);
});
it('Arrays do not offer gt comparison', function () use ($array) {
expect(eval_compare(1, $array, '>'))->toBe(false);
});
it('Arrays do not offer lt comparison', function () use ($array) {
expect(eval_compare(1, $array, '<'))->toBe(false);
});
it('equals implies lte 4', function () {
expect(eval_compare(true, true, '<='))->toBe(true);
});
it('Booleans do not offer gt comparison', function () {
expect(eval_compare(true, true, '>'))->toBe(false);
});
});
});