Fix issues from Inheritance spec (#36)
* Separate inheritance block and expansion * Catch top level partial definition, and block newlines * Add testTrailingNewLines to verify output of trailing newlines in partials * Remove comment * If block,partial has indentation add indent for first line * Re-enable full sections spec * withBlockExpansion * Get indentation of blocks correct
This commit is contained in:
@@ -21,7 +21,7 @@ final class PartialTests: XCTestCase {
|
||||
let template = try MustacheTemplate(string: """
|
||||
<h2>Names</h2>
|
||||
{{#names}}
|
||||
{{> user}}
|
||||
{{> user}}
|
||||
{{/names}}
|
||||
""")
|
||||
let template2 = try MustacheTemplate(string: """
|
||||
@@ -33,9 +33,9 @@ final class PartialTests: XCTestCase {
|
||||
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>
|
||||
<strong>john</strong>
|
||||
<strong>adam</strong>
|
||||
<strong>claire</strong>
|
||||
|
||||
""")
|
||||
}
|
||||
@@ -62,8 +62,7 @@ final class PartialTests: XCTestCase {
|
||||
""")
|
||||
var library = MustacheLibrary()
|
||||
library.register(template, named: "base")
|
||||
library.register(template2, named: "user") // , withTemplate: String)// = MustacheLibrary(templates: ["base": template, "user": template2])
|
||||
|
||||
library.register(template2, named: "user")
|
||||
let object: [String: Any] = ["names": ["john", "adam", "claire"]]
|
||||
XCTAssertEqual(library.render(object, withTemplate: "base"), """
|
||||
<h2>Names</h2>
|
||||
@@ -75,6 +74,37 @@ final class PartialTests: XCTestCase {
|
||||
""")
|
||||
}
|
||||
|
||||
func testTrailingNewLines() throws {
|
||||
let template1 = try MustacheTemplate(string: """
|
||||
{{> withNewLine }}
|
||||
>> {{> withNewLine }}
|
||||
[ {{> withNewLine }} ]
|
||||
""")
|
||||
let template2 = try MustacheTemplate(string: """
|
||||
{{> withoutNewLine }}
|
||||
>> {{> withoutNewLine }}
|
||||
[ {{> withoutNewLine }} ]
|
||||
""")
|
||||
let withNewLine = try MustacheTemplate(string: """
|
||||
{{#things}}{{.}}, {{/things}}
|
||||
|
||||
""")
|
||||
let withoutNewLine = try MustacheTemplate(string: "{{#things}}{{.}}, {{/things}}")
|
||||
let library = MustacheLibrary(templates: ["base1": template1, "base2": template2, "withNewLine": withNewLine, "withoutNewLine": withoutNewLine])
|
||||
let object = ["things": [1, 2, 3, 4, 5]]
|
||||
XCTAssertEqual(library.render(object, withTemplate: "base1"), """
|
||||
1, 2, 3, 4, 5,
|
||||
>> 1, 2, 3, 4, 5,
|
||||
|
||||
[ 1, 2, 3, 4, 5,
|
||||
]
|
||||
""")
|
||||
XCTAssertEqual(library.render(object, withTemplate: "base2"), """
|
||||
1, 2, 3, 4, 5, >> 1, 2, 3, 4, 5,
|
||||
[ 1, 2, 3, 4, 5, ]
|
||||
""")
|
||||
}
|
||||
|
||||
/// Testing dynamic partials
|
||||
func testDynamicPartials() throws {
|
||||
let template = try MustacheTemplate(string: """
|
||||
@@ -106,7 +136,6 @@ final class PartialTests: XCTestCase {
|
||||
<head>
|
||||
<title>{{$title}}Default title{{/title}}</title>
|
||||
</head>
|
||||
|
||||
""",
|
||||
named: "header"
|
||||
)
|
||||
@@ -144,4 +173,32 @@ final class PartialTests: XCTestCase {
|
||||
|
||||
""")
|
||||
}
|
||||
|
||||
func testInheritanceIndentation() throws {
|
||||
var library = MustacheLibrary()
|
||||
try library.register(
|
||||
"""
|
||||
Hi,
|
||||
{{$block}}{{/block}}
|
||||
""",
|
||||
named: "parent"
|
||||
)
|
||||
try library.register(
|
||||
"""
|
||||
{{<parent}}
|
||||
{{$block}}
|
||||
one
|
||||
two
|
||||
{{/block}}
|
||||
{{/parent}}
|
||||
""",
|
||||
named: "template"
|
||||
)
|
||||
XCTAssertEqual(library.render({}, withTemplate: "template"), """
|
||||
Hi,
|
||||
one
|
||||
two
|
||||
|
||||
""")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user