Files
swiftpm-mustache/Tests/HummingbirdMustacheTests/LibraryTests.swift
2021-03-14 08:51:16 +00:00

19 lines
875 B
Swift

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>")
}
}