Skip to content

Commit

Permalink
Support for not equal
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaro-saavedra-sumup committed Mar 12, 2024
1 parent 322e29a commit 8612fa4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ const comparisonOperation = (
}

if (operation === Operations.notEquals) {
if (isMap(left) && isMap(right)) {
return !comparisonEqualForMap(left, right)
}
return left !== right
}

Expand Down
20 changes: 19 additions & 1 deletion src/spec/maps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('maps expressions', () => {
})
})

describe('comparison', () => {
describe('equal', () => {
it('should compare two equal maps', () => {
const expr = '{"c": 1, "a": 1, "b": 2} == {"a": 1, "b": 2, "c": 1}'

Expand All @@ -119,6 +119,24 @@ describe('maps expressions', () => {

})
})
describe('not equal', () => {
it('should compare two equal maps', () => {
const expr = '{"c": 1, "a": 1, "b": 2} != {"a": 1, "b": 2, "c": 1}'

const result = evaluate(expr)

expect(result).toStrictEqual(false)

})
it('should compare two different maps', () => {
const expr = '{"a": 1, "b": 2} != {"a": 1, "b": 2, "c": 1}'

const result = evaluate(expr)

expect(result).toStrictEqual(true)

})
})
describe('in', () => {
it('should find a key in the map', () => {
const expr = '"c" in {"c": 1, "a": 1, "b": 2}'
Expand Down

0 comments on commit 8612fa4

Please sign in to comment.