Fix issue with indented partials (#19)

* Fix issue with indented partials

* Add test

* Add empty transform for string
This commit is contained in:
Adam Fowler
2023-01-14 08:50:51 +00:00
committed by GitHub
parent 185004fdce
commit fa56176223
4 changed files with 59 additions and 4 deletions

View File

@@ -42,6 +42,41 @@ final class PartialTests: XCTestCase {
""")
}
/// Test where last line of partial generates no content. It should not add a
/// tab either
func testPartialEmptyLineTabbing() throws {
let library = HBMustacheLibrary()
let template = try HBMustacheTemplate(string: """
<h2>Names</h2>
{{#names}}
{{> user}}
{{/names}}
Text after
""")
let template2 = try HBMustacheTemplate(string: """
{{^empty(.)}}
<strong>{{.}}</strong>
{{/empty(.)}}
{{#empty(.)}}
<strong>empty</strong>
{{/empty(.)}}
""")
library.register(template, named: "base")
library.register(template2, named: "user")
let object: [String: Any] = ["names": ["john", "adam", "claire"]]
XCTAssertEqual(library.render(object, withTemplate: "base"), """
<h2>Names</h2>
<strong>john</strong>
<strong>adam</strong>
<strong>claire</strong>
Text after
""")
}
/// Testing dynamic partials
func testDynamicPartials() throws {
let library = HBMustacheLibrary()