refactor: Introducing Environments

This commit is contained in:
Kyle Fuller
2016-12-01 00:17:04 +00:00
parent 2be672c6a5
commit 9e2a061795
27 changed files with 289 additions and 91 deletions

View File

@@ -7,6 +7,7 @@ func testInclude() {
describe("Include") {
let path = Path(#file) + ".." + "fixtures"
let loader = FileSystemLoader(paths: [path])
let environment = Environment(loader: loader)
$0.describe("parsing") {
$0.it("throws an error when no template is given") {
@@ -35,7 +36,7 @@ func testInclude() {
do {
_ = try node.render(Context())
} catch {
try expect("\(error)") == "Template loader not in context"
try expect("\(error)") == "Template named `test.html` does not exist. No loaders found"
}
}
@@ -43,7 +44,7 @@ func testInclude() {
let node = IncludeNode(templateName: Variable("\"unknown.html\""))
do {
_ = try node.render(Context(dictionary: ["loader": loader]))
_ = try node.render(Context(environment: environment))
} catch {
try expect("\(error)".hasPrefix("Template named `unknown.html` does not exist in loader")).to.beTrue()
}
@@ -51,7 +52,7 @@ func testInclude() {
$0.it("successfully renders a found included template") {
let node = IncludeNode(templateName: Variable("\"test.html\""))
let context = Context(dictionary: ["loader":loader, "target": "World"])
let context = Context(dictionary: ["target": "World"], environment: environment)
let value = try node.render(context)
try expect(value) == "Hello World!"
}