Basic method setup and calling
This commit is contained in:
@@ -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)):
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user