Basic method setup and calling

This commit is contained in:
Adam Fowler
2021-03-12 14:03:46 +00:00
parent 902c300969
commit c9e33153f3
6 changed files with 96 additions and 20 deletions

View File

@@ -77,8 +77,8 @@ extension HBMustacheTemplate.Token: Equatable {
switch (lhs, rhs) {
case (.text(let lhs), .text(let rhs)):
return lhs == rhs
case (.variable(let lhs), .variable(let rhs)):
return lhs == rhs
case (.variable(let lhs, let lhs2), .variable(let rhs, let rhs2)):
return lhs == rhs && lhs2 == rhs2
case (.section(let lhs1, let lhs2), .section(let rhs1, let rhs2)):
return lhs1 == rhs1 && lhs2 == rhs2
case (.invertedSection(let lhs1, let lhs2), .invertedSection(let rhs1, let rhs2)):

View File

@@ -191,4 +191,32 @@ final class TemplateRendererTests: XCTestCase {
<h1>Today.</h1>
""")
}
func testLowercased() throws {
let template = try HBMustacheTemplate(string: """
{{#repo}}
<b>{{ lowercased(name) }}</b>
{{/repo}}
""")
let object: [String: Any] = ["repo": [["name": "Resque"], ["name": "Hub"], ["name": "RIP"]]]
XCTAssertEqual(template.render(object), """
<b>resque</b>
<b>hub</b>
<b>rip</b>
""")
}
func testPerformance() throws {
let template = try HBMustacheTemplate(string: """
{{#repo}}
<b>{{name}}</b>
{{/repo}}
""")
let object: [String: Any] = ["repo": [["name": "resque"], ["name": "hub"], ["name": "rip"]]]
let date = Date()
for _ in 1...10000 {
_ = template.render(object)
}
print(-date.timeIntervalSinceNow)
}
}