Skip to content

Commit 755ae1f

Browse files
committed
Add suport float value
1 parent 82f3259 commit 755ae1f

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

src/TreeCompiler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ private function visit_comparator(array $node)
401401
$this->write('$value = !Utils::isEqual(%s, %s);', $a, $b);
402402
} else {
403403
$this->write(
404-
'$value = is_int(%s) && is_int(%s) && %s %s %s;',
405-
$a, $b, $a, $node['value'], $b
404+
'$value = (is_int(%s) || is_float(%s)) && (is_int(%s) || is_float(%s)) && %s %s %s;',
405+
$a, $a, $b, $b, $a, $node['value'], $b
406406
);
407407
}
408408

src/TreeInterpreter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private function dispatch(array $node, $value)
220220
*/
221221
private static function relativeCmp($left, $right, $cmp)
222222
{
223-
if (!is_int($left) || !is_int($right)) {
223+
if (!(is_int($left) || is_float($left)) || !(is_int($right) || is_float($right))) {
224224
return false;
225225
}
226226

tests/compliance/filters.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,50 @@
8080
}
8181
]
8282
},
83+
{
84+
"given": {"foo": [{"weight": 33.3},
85+
{"weight": 44.4},
86+
{"weight": 55.5}]},
87+
"cases": [
88+
{
89+
"comment": "Greater than with a number",
90+
"expression": "foo[?weight > `44.4`]",
91+
"result": [{"weight": 55.5}]
92+
},
93+
{
94+
"expression": "foo[?weight >= `44.4`]",
95+
"result": [{"weight": 44.4}, {"weight": 55.5}]
96+
},
97+
{
98+
"comment": "Greater than with a number",
99+
"expression": "foo[?weight > `55.5`]",
100+
"result": []
101+
},
102+
{
103+
"comment": "Greater than with a number",
104+
"expression": "foo[?weight < `44.4`]",
105+
"result": [{"weight": 33.3}]
106+
},
107+
{
108+
"comment": "Greater than with a number",
109+
"expression": "foo[?weight <= `44.4`]",
110+
"result": [{"weight": 33.3}, {"weight": 44.4}]
111+
},
112+
{
113+
"comment": "Greater than with a number",
114+
"expression": "foo[?weight < `33.3`]",
115+
"result": []
116+
},
117+
{
118+
"expression": "foo[?weight == `33.3`]",
119+
"result": [{"weight": 33.3}]
120+
},
121+
{
122+
"expression": "foo[?weight != `33.3`]",
123+
"result": [{"weight": 44.4}, {"weight": 55.5}]
124+
}
125+
]
126+
},
83127
{
84128
"given": {"foo": [{"top": {"name": "a"}},
85129
{"top": {"name": "b"}}]},

0 commit comments

Comments
 (0)