Skip to content

Commit

Permalink
Merge pull request #32 from 4-sho/fixbool
Browse files Browse the repository at this point in the history
Add support for bool lookup in expression IN
  • Loading branch information
csknns authored Dec 31, 2023
2 parents 4ad1e20 + 3bd5392 commit dd9b34e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/jsonlogic/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ struct In: Expression {
return JSON(arrayToSearchIn.contains(JSON(integerToFind)))
} else if let doubleToFind = try targetExpression.evalWithData(data).double {
return JSON(arrayToSearchIn.contains(JSON(doubleToFind)))
} else if let boolToFind = try targetExpression.evalWithData(data).bool {
return JSON(arrayToSearchIn.contains(JSON(boolToFind)))
}
}
return JSON.Bool(false)
Expand Down
14 changes: 14 additions & 0 deletions Tests/jsonlogicTests/StringOperations/InTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,18 @@ class InTests: XCTestCase {
"""
XCTAssertEqual(false, try applyRule(rule, to: nil))
}

func testIn_BoolArgument() {
var rule =
"""
{"in":[true,[false, true, false]]}
"""
XCTAssertEqual(true, try applyRule(rule, to: nil))

rule =
"""
{"in":[true,[false, false, false]]}
"""
XCTAssertEqual(false, try applyRule(rule, to: nil))
}
}

0 comments on commit dd9b34e

Please sign in to comment.