advantagefse / json-logic-swift

A native Swift JsonLogic implementation. This parser accepts JsonLogic rules and executes them.
MIT License
25 stars 22 forks source link

Fixed array path in json logic rule #16

Closed alexchornyi closed 3 years ago

alexchornyi commented 3 years ago

fixed to parsing rule array with index like "payload.r.0.fr"

codecov-commenter commented 3 years ago

Codecov Report

Merging #16 (af00117) into master (a4d6647) will decrease coverage by 0.02%. The diff coverage is 95.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #16      +/-   ##
==========================================
- Coverage   98.32%   98.30%   -0.03%     
==========================================
  Files          31       31              
  Lines        3282     3298      +16     
==========================================
+ Hits         3227     3242      +15     
- Misses         55       56       +1     
Impacted Files Coverage Δ
Sources/jsonlogic/Parser.swift 95.36% <90.90%> (-0.18%) :arrow_down:
...cTests/AccessingDataOperations/ArrayMapTests.swift 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update a4d6647...af00117. Read the comment docs.

csknns commented 3 years ago

Hello @alexchornyi Thanks for your contribution!

If I understand this correctly you add support for using array index as part of the keypath string for accessing the data So the rule { "var" : "person.name.1" }

applied to { "person" : { "name" : ["John", "Green"] } }

will produce "Green"

I had missed this capability in the original implementation.

Can you also add a unit test for this? something like

    func testAccessingVariableWithArrayIndexPath() {
        let rule =
        """
           { "var" : "person.name.1" }
        """
        let data =
        """
           { "person" : { "name" : ["John", "Green"] } }
        """

        XCTAssertEqual("John", try applyRule(rule, to: data))
    }