diff --git a/CHANGELOG.md b/CHANGELOG.md index b18c3c9..e83361b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/jmespath/nodes/condition.rb b/lib/jmespath/nodes/condition.rb index ccefdf6..9dd8e19 100644 --- a/lib/jmespath/nodes/condition.rb +++ b/lib/jmespath/nodes/condition.rb @@ -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 diff --git a/spec/compliance/filters.json b/spec/compliance/filters.json index 5086e36..7e237b8 100644 --- a/spec/compliance/filters.json +++ b/spec/compliance/filters.json @@ -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"]