Add index filter

This commit is contained in:
Adam Fowler
2021-03-14 17:53:20 +00:00
parent 33b488fe40
commit 465ad49f1f
4 changed files with 31 additions and 0 deletions

View File

@@ -33,6 +33,21 @@ final class MethodTests: XCTestCase {
""")
}
func testIndex() throws {
let template = try HBMustacheTemplate(string: """
{{#repo}}
<b>{{#index()}}{{plus1(.)}}) {{/}}{{ name }}</b>
{{/repo}}
""")
let object: [String: Any] = ["repo": [["name": "resque"], ["name": "hub"], ["name": "rip"]]]
XCTAssertEqual(template.render(object), """
<b>1) resque</b>
<b>2) hub</b>
<b>3) rip</b>
""")
}
func testReversed() throws {
let template = try HBMustacheTemplate(string: """
{{#reversed(repo)}}