Add template library loading from FileSystem

This commit is contained in:
Adam Fowler
2021-03-12 11:04:17 +00:00
parent 6be7a382fb
commit 902c300969
5 changed files with 101 additions and 50 deletions

View File

@@ -0,0 +1,18 @@
import XCTest
@testable import HummingbirdMustache
final class LibraryTests: XCTestCase {
func testDirectoryLoad() throws {
let fs = FileManager()
try fs.createDirectory(atPath: "./templates", withIntermediateDirectories: false)
let mustache = "<test>{{#value}}<value>{{.}}</value>{{/value}}</test>"
let data = Data(mustache.utf8)
defer { XCTAssertNoThrow(try fs.removeItem(atPath: "templates")) }
try data.write(to: URL(fileURLWithPath: "templates/test.mustache"))
defer { XCTAssertNoThrow(try fs.removeItem(atPath: "templates/test.mustache")) }
let library = HBMustacheLibrary(directory: "./templates")
let object = ["value": ["value1", "value2"]]
XCTAssertEqual(library.render(object, withTemplateNamed: "test"), "<test><value>value1</value><value>value2</value></test>")
}
}