feat(for loop): Support range literals (#192)

This commit is contained in:
Ilya Puchka
2018-04-05 01:56:58 +01:00
committed by Kyle Fuller
parent 2e6a7215c5
commit fe01beb4bb
8 changed files with 131 additions and 16 deletions

View File

@@ -227,7 +227,7 @@ func testForNode() {
.block(value: "for i"),
]
let parser = TokenParser(tokens: tokens, environment: Environment())
let error = TemplateSyntaxError("'for' statements should use the following 'for x in y where condition' `for i`.")
let error = TemplateSyntaxError("'for' statements should use the syntax: `for <x> in <y> [where <condition>]")
try expect(try parser.parse()).toThrow(error)
}
@@ -306,6 +306,11 @@ func testForNode() {
try expect(result) == "childString=child\nbaseString=base\nbaseInt=1\n"
}
$0.it("can iterate in range of variables") {
let template: Template = "{% for i in 1...j %}{{ i }}{% endfor %}"
try expect(try template.render(Context(dictionary: ["j": 3]))) == "123"
}
}
}