Skip to content

Commit

Permalink
Merge pull request #57 from mtichner/patch-1
Browse files Browse the repository at this point in the history
Allow comparison of Integers and Numeric types
  • Loading branch information
mullermp authored Nov 25, 2022
2 parents a085656 + 90ab191 commit 9c7d316
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Issue - Allow comparison of Numeric types (includes Float).

* Issue - Add jmespath.rb to gemspec executables.

1.6.1 (2022-03-07)
Expand Down
2 changes: 1 addition & 1 deletion lib/jmespath/nodes/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def optimize

class ComparatorCondition < Node
COMPARATOR_TO_CONDITION = {}
COMPARABLE_TYPES = [Integer, String].freeze
COMPARABLE_TYPES = [Numeric, String].freeze

def initialize(left, right, child)
@left = left
Expand Down
27 changes: 27 additions & 0 deletions spec/compliance/filters.json
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,33 @@
}
]
},
{
"given": {"foo": [{"length": 170},
{"length": 175.5},
{"length": 185}]},
"cases": [
{
"comment": "Less than number",
"expression": "foo[?length < `180`]",
"result": [{"length": 170}, {"length": 175.5}]
},
{
"comment": "Less than or equal to number",
"expression": "foo[?length <= `175.5`]",
"result": [{"length": 170}, {"length": 175.5}]
},
{
"comment": "Greater than number",
"expression": "foo[?length > `170`]",
"result": [{"length": 175.5}, {"length": 185}]
},
{
"comment": "Greater than or equal to number",
"expression": "foo[?length >= `175.5`]",
"result": [{"length": 175.5}, {"length": 185}]
}
]
},
{
"given": {
"foo": ["2010-02-01", "2011-05-01"]
Expand Down

0 comments on commit 9c7d316

Please sign in to comment.