Add support for first/last functions
This commit is contained in:
@@ -18,6 +18,21 @@ final class MethodTests: XCTestCase {
|
||||
XCTAssertEqual(template.render(object), "TEST")
|
||||
}
|
||||
|
||||
func testFirstLast() throws {
|
||||
let template = try HBMustacheTemplate(string: """
|
||||
{{#repo}}
|
||||
<b>{{#first()}}first: {{/}}{{#last()}}last: {{/}}{{ name }}</b>
|
||||
{{/repo}}
|
||||
""")
|
||||
let object: [String: Any] = ["repo": [["name": "resque"], ["name": "hub"], ["name": "rip"]]]
|
||||
XCTAssertEqual(template.render(object), """
|
||||
<b>first: resque</b>
|
||||
<b>hub</b>
|
||||
<b>last: rip</b>
|
||||
|
||||
""")
|
||||
}
|
||||
|
||||
func testReversed() throws {
|
||||
let template = try HBMustacheTemplate(string: """
|
||||
{{#reversed(repo)}}
|
||||
|
||||
@@ -25,6 +25,7 @@ final class TemplateRendererTests: XCTestCase {
|
||||
func testArraySection() throws {
|
||||
let template = try HBMustacheTemplate(string: "test {{#value}}*{{.}}{{/value}}")
|
||||
XCTAssertEqual(template.render(["value": ["test2", "bool"]]), "test *test2*bool")
|
||||
XCTAssertEqual(template.render(["value": ["test2"]]), "test *test2")
|
||||
XCTAssertEqual(template.render(["value": []]), "test ")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user