using error reporter from environment to handle syntax errors

This commit is contained in:
Ilya Puchka
2017-10-07 21:01:28 +02:00
parent 0edb38588d
commit d5f0be959f
3 changed files with 60 additions and 28 deletions

View File

@@ -15,30 +15,6 @@ func testTemplate() {
let result = try template.render([ "name": "Kyle" ])
try expect(result) == "Hello World"
}
$0.it("throws syntax error on invalid for tag syntax") {
let template: Template = "Hello {% for name in %}{{ name }}, {% endfor %}!"
var error = TemplateSyntaxError("'for' statements should use the following syntax 'for x in y where condition'.")
error.token = Token.block(value: "{% for name in %}", at: template.templateString.range(of: "{% for name in %}")!)
error = error.contextAwareError(templateName: nil, templateContent: template.templateString)!
try expect(try template.render(["names": ["Bob", "Alice"]])).toThrow(error)
}
$0.it("throws syntax error on missing endfor") {
let template: Template = "{% for name in names %}{{ name }}"
var error = TemplateSyntaxError("`endfor` was not found.")
error.token = Token.block(value: "{% for name in names %}", at: template.templateString.range(of: "{% for name in names %}")!)
error = error.contextAwareError(templateName: nil, templateContent: template.templateString)!
try expect(try template.render(["names": ["Bob", "Alice"]])).toThrow(error)
}
$0.it("throws syntax error on unknown tag") {
let template: Template = "{% for name in names %}{{ name }}{% end %}"
var error = TemplateSyntaxError("Unknown template tag 'end'")
error.token = Token.block(value: "{% end %}", at: template.templateString.range(of: "{% end %}")!)
error = error.contextAwareError(templateName: nil, templateContent: template.templateString)!
try expect(try template.render(["names": ["Bob", "Alice"]])).toThrow(error)
}
}
}