feat(for tag): Provide the counter 0 indexed to the context

Closes #121
This commit is contained in:
Kyle Fuller
2017-09-07 18:21:16 +01:00
parent 482d595d01
commit 7b9817ed50
4 changed files with 23 additions and 10 deletions

View File

@@ -83,6 +83,12 @@ func testForNode() {
try expect(try node.render(context)) == "112233"
}
$0.it("renders the given nodes while providing item counter") {
let nodes: [NodeType] = [VariableNode(variable: "item"), VariableNode(variable: "forloop.counter0")]
let node = ForNode(resolvable: Variable("items"), loopVariables: ["item"], nodes: nodes, emptyNodes: [])
try expect(try node.render(context)) == "102132"
}
$0.it("renders the given nodes while filtering items using where expression") {
let nodes: [NodeType] = [VariableNode(variable: "item"), VariableNode(variable: "forloop.counter")]
let `where` = try parseExpression(components: ["item", ">", "1"], tokenParser: TokenParser(tokens: [], environment: Environment()))