@testable import HummingbirdMustache import XCTest final class PartialTests: XCTestCase { /// Testing partials func testMustacheManualExample9() throws { let library = HBMustacheLibrary() let template = try HBMustacheTemplate(string: """

Names

{{#names}} {{> user}} {{/names}} """) let template2 = try HBMustacheTemplate(string: """ {{.}} """) library.register(template, named: "base") library.register(template2, named: "user") let object: [String: Any] = ["names": ["john", "adam", "claire"]] XCTAssertEqual(library.render(object, withTemplate: "base"), """

Names

john adam claire """) } /// Testing dynamic partials func testDynamicPartials() throws { let library = HBMustacheLibrary() let template = try HBMustacheTemplate(string: """

Names

{{partial}} """) let template2 = try HBMustacheTemplate(string: """ {{#names}} {{.}} {{/names}} """) library.register(template, named: "base") let object: [String: Any] = ["names": ["john", "adam", "claire"], "partial": template2] XCTAssertEqual(library.render(object, withTemplate: "base"), """

Names

john adam claire """) } /// test inheritance func testInheritance() throws { let library = HBMustacheLibrary() try library.register( """ {{$title}}Default title{{/title}} """, named: "header" ) try library.register( """ {{$header}}{{/header}} {{$content}}{{/content}} """, named: "base" ) try library.register( """ {{Hello world{{/content}} {{/base}} """, named: "mypage" ) XCTAssertEqual(library.render({}, withTemplate: "mypage")!, """ My page title

Hello world

""") } }