-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from supermetrics-public/feature/NumericalStr…
…ingComparison Allow numeric strings in number comparisons
- Loading branch information
Showing
9 changed files
with
351 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--TEST-- | ||
Test greater-than number comparison condition with integer compared to numbers and numerical strings | ||
--SKIPIF-- | ||
<?php if (!extension_loaded("jsonpath")) print "skip"; ?> | ||
--FILE-- | ||
<?php | ||
|
||
$data = [ | ||
[ | ||
'product' => 'tomato', | ||
'quantity' => '4', | ||
], | ||
[ | ||
'product' => 'apple', | ||
'quantity' => '1', | ||
], | ||
[ | ||
'product' => 'pear', | ||
'quantity' => 2, | ||
], | ||
[ | ||
'product' => 'banana', | ||
'quantity' => '0', | ||
], | ||
[ | ||
'product' => 'cucumber', | ||
'quantity' => 0, | ||
], | ||
[ | ||
'product' => 'coconut', | ||
'quantity' => '0.5', | ||
], | ||
[ | ||
'product' => 'carrot', | ||
'quantity' => '3', | ||
], | ||
[ | ||
'product' => 'cauliflower', | ||
'quantity' => '-4', | ||
], | ||
[ | ||
'product' => 'watermelon', | ||
'quantity' => '-2', | ||
], | ||
[ | ||
'product' => 'asparagus', | ||
'quantity' => '-2.5', | ||
], | ||
]; | ||
|
||
$jsonPath = new \JsonPath\JsonPath(); | ||
$result = $jsonPath->find($data, "$[?(@.quantity > 0)]"); | ||
|
||
var_dump($result); | ||
?> | ||
--EXPECT-- | ||
array(5) { | ||
[0]=> | ||
array(2) { | ||
["product"]=> | ||
string(6) "tomato" | ||
["quantity"]=> | ||
string(1) "4" | ||
} | ||
[1]=> | ||
array(2) { | ||
["product"]=> | ||
string(5) "apple" | ||
["quantity"]=> | ||
string(1) "1" | ||
} | ||
[2]=> | ||
array(2) { | ||
["product"]=> | ||
string(4) "pear" | ||
["quantity"]=> | ||
int(2) | ||
} | ||
[3]=> | ||
array(2) { | ||
["product"]=> | ||
string(7) "coconut" | ||
["quantity"]=> | ||
string(3) "0.5" | ||
} | ||
[4]=> | ||
array(2) { | ||
["product"]=> | ||
string(6) "carrot" | ||
["quantity"]=> | ||
string(1) "3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
--TEST-- | ||
Test greater-than-or-equal-to number comparison condition with integer compared to numbers and numerical strings | ||
--SKIPIF-- | ||
<?php if (!extension_loaded("jsonpath")) print "skip"; ?> | ||
--FILE-- | ||
<?php | ||
|
||
$data = [ | ||
[ | ||
'product' => 'tomato', | ||
'quantity' => '4', | ||
], | ||
[ | ||
'product' => 'apple', | ||
'quantity' => '1', | ||
], | ||
[ | ||
'product' => 'pear', | ||
'quantity' => 2, | ||
], | ||
[ | ||
'product' => 'banana', | ||
'quantity' => '0', | ||
], | ||
[ | ||
'product' => 'cucumber', | ||
'quantity' => 0, | ||
], | ||
[ | ||
'product' => 'coconut', | ||
'quantity' => '0.5', | ||
], | ||
[ | ||
'product' => 'carrot', | ||
'quantity' => '3', | ||
], | ||
[ | ||
'product' => 'cauliflower', | ||
'quantity' => '-4', | ||
], | ||
[ | ||
'product' => 'watermelon', | ||
'quantity' => '-2', | ||
], | ||
[ | ||
'product' => 'asparagus', | ||
'quantity' => '-2.5', | ||
], | ||
]; | ||
|
||
$jsonPath = new \JsonPath\JsonPath(); | ||
$result = $jsonPath->find($data, "$[?(@.quantity >= -3)]"); | ||
|
||
var_dump($result); | ||
?> | ||
--EXPECT-- | ||
array(9) { | ||
[0]=> | ||
array(2) { | ||
["product"]=> | ||
string(6) "tomato" | ||
["quantity"]=> | ||
string(1) "4" | ||
} | ||
[1]=> | ||
array(2) { | ||
["product"]=> | ||
string(5) "apple" | ||
["quantity"]=> | ||
string(1) "1" | ||
} | ||
[2]=> | ||
array(2) { | ||
["product"]=> | ||
string(4) "pear" | ||
["quantity"]=> | ||
int(2) | ||
} | ||
[3]=> | ||
array(2) { | ||
["product"]=> | ||
string(6) "banana" | ||
["quantity"]=> | ||
string(1) "0" | ||
} | ||
[4]=> | ||
array(2) { | ||
["product"]=> | ||
string(8) "cucumber" | ||
["quantity"]=> | ||
int(0) | ||
} | ||
[5]=> | ||
array(2) { | ||
["product"]=> | ||
string(7) "coconut" | ||
["quantity"]=> | ||
string(3) "0.5" | ||
} | ||
[6]=> | ||
array(2) { | ||
["product"]=> | ||
string(6) "carrot" | ||
["quantity"]=> | ||
string(1) "3" | ||
} | ||
[7]=> | ||
array(2) { | ||
["product"]=> | ||
string(10) "watermelon" | ||
["quantity"]=> | ||
string(2) "-2" | ||
} | ||
[8]=> | ||
array(2) { | ||
["product"]=> | ||
string(9) "asparagus" | ||
["quantity"]=> | ||
string(4) "-2.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--TEST-- | ||
Test greater-than number comparison condition with float compared to numbers and numerical strings | ||
--SKIPIF-- | ||
<?php if (!extension_loaded("jsonpath")) print "skip"; ?> | ||
--FILE-- | ||
<?php | ||
|
||
$data = [ | ||
[ | ||
'product' => 'tomato', | ||
'quantity' => '4', | ||
], | ||
[ | ||
'product' => 'apple', | ||
'quantity' => '1', | ||
], | ||
[ | ||
'product' => 'pear', | ||
'quantity' => 2, | ||
], | ||
[ | ||
'product' => 'banana', | ||
'quantity' => '0', | ||
], | ||
[ | ||
'product' => 'cucumber', | ||
'quantity' => 0, | ||
], | ||
[ | ||
'product' => 'coconut', | ||
'quantity' => '0.5', | ||
], | ||
[ | ||
'product' => 'carrot', | ||
'quantity' => '3', | ||
], | ||
[ | ||
'product' => 'cauliflower', | ||
'quantity' => '-4', | ||
], | ||
[ | ||
'product' => 'watermelon', | ||
'quantity' => '-2', | ||
], | ||
[ | ||
'product' => 'asparagus', | ||
'quantity' => '-2.5', | ||
], | ||
]; | ||
|
||
$jsonPath = new \JsonPath\JsonPath(); | ||
$result = $jsonPath->find($data, "$[?(@.quantity > 0.2)]"); | ||
|
||
var_dump($result); | ||
?> | ||
--EXPECT-- | ||
array(5) { | ||
[0]=> | ||
array(2) { | ||
["product"]=> | ||
string(6) "tomato" | ||
["quantity"]=> | ||
string(1) "4" | ||
} | ||
[1]=> | ||
array(2) { | ||
["product"]=> | ||
string(5) "apple" | ||
["quantity"]=> | ||
string(1) "1" | ||
} | ||
[2]=> | ||
array(2) { | ||
["product"]=> | ||
string(4) "pear" | ||
["quantity"]=> | ||
int(2) | ||
} | ||
[3]=> | ||
array(2) { | ||
["product"]=> | ||
string(7) "coconut" | ||
["quantity"]=> | ||
string(3) "0.5" | ||
} | ||
[4]=> | ||
array(2) { | ||
["product"]=> | ||
string(6) "carrot" | ||
["quantity"]=> | ||
string(1) "3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.