Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with using GRMustache with multiple data types. #52

Open
ajaysubramanya26 opened this issue Jun 15, 2018 · 0 comments
Open

Issues with using GRMustache with multiple data types. #52

ajaysubramanya26 opened this issue Jun 15, 2018 · 0 comments

Comments

@ajaysubramanya26
Copy link

Below are some of the test's that I wrote to show the issue that I'm seeing with the library. Please let me know if anyone else is seeing the issues. Looking into the library, the issues seem to be related to fix #83 on the GRMustache library. Please let me know if you think this is an issue and if I could help.

When there are Int types along with Strings in the value dictionary, the whole dictionary gets replaced in the place where a value for a key should be replaced in mustache. Below are some tests that I wrote to explain what's wrong.

func test_mustache_with_different_value_types() throws {
    let mustache = try? Mustache.Template(string: "{{#position}} column--{{.}}{{/position}}")
    let rendered = try? mustache?.render(["position": Int64(1),
                                          "css": "string",
                                          "style": true])
    XCTAssertEqual(rendered!, "column--1")
}

This fails with the below error:

XCTAssertEqual failed: ("Optional(" column--[AnyHashable("position"): Optional(1), AnyHashable("css"): Optional("string"), AnyHashable("style"): Optional(true)]")") is not equal to ("Optional("column--1")”)

Comments: As we can see, mustache should have returned column—1, but it replaces position with the whole dictionary. However, this never happens if they are all strings, as we can see in the below example. Also, this happens even if the position was a regular Int.I’m using Int64 because for some reason that’s what the apple SDK converts the values from the JSON to, maybe just to accommodate huge numbers.

func test_mustache_with_different_value_types() throws {
    let mustache = try? Mustache.Template(string: "{{#position}}column--{{.}}{{/position}}")
    let rendered = try? mustache?.render(["position": "1",
                                          "css": "string",
                                          "style": true])
    XCTAssertEqual(rendered!, "column--1")
}

The above test passes since position here is a string.

func test_mustache_with_different_value_types() throws {
    let mustache = try? Mustache.Template(string: "{{#position}}column--{{.}}{{/position}}")
    let rendered = try? mustache?.render(["position": [Int64(1), Int64(2)],
                                          "css": "string",
                                          "style": true])
    XCTAssertEqual(rendered!, "column--1column--2")
}

However, if position is an Array of Int64 or Int for that matter, it works as it should. The above test does pass.

Pardon my force unwraps, just trying to show issue that I'm facing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant