Ensure the "for" iteration over a dictionary is consistent
This commit is contained in:
@@ -93,7 +93,7 @@ class ForNode : NodeType {
|
|||||||
var values: [Any]
|
var values: [Any]
|
||||||
|
|
||||||
if let dictionary = resolved as? [String: Any], !dictionary.isEmpty {
|
if let dictionary = resolved as? [String: Any], !dictionary.isEmpty {
|
||||||
values = dictionary.map { ($0.key, $0.value) }
|
values = dictionary.sorted { $0.key < $1.key }
|
||||||
} else if let array = resolved as? [Any] {
|
} else if let array = resolved as? [Any] {
|
||||||
values = array
|
values = array
|
||||||
} else if let range = resolved as? CountableClosedRange<Int> {
|
} else if let range = resolved as? CountableClosedRange<Int> {
|
||||||
|
|||||||
@@ -209,8 +209,9 @@ func testForNode() {
|
|||||||
let template = Template(templateString: templateString)
|
let template = Template(templateString: templateString)
|
||||||
let result = try template.render(context)
|
let result = try template.render(context)
|
||||||
|
|
||||||
let sortedResult = result.split(separator: ",").map(String.init).sorted(by: <)
|
try expect(result) == """
|
||||||
try expect(sortedResult) == ["one: I", "two: II"]
|
one: I,two: II,
|
||||||
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
$0.it("renders supports iterating over dictionary") {
|
$0.it("renders supports iterating over dictionary") {
|
||||||
@@ -222,8 +223,9 @@ func testForNode() {
|
|||||||
let node = ForNode(resolvable: Variable("dict"), loopVariables: ["key"], nodes: nodes, emptyNodes: emptyNodes, where: nil)
|
let node = ForNode(resolvable: Variable("dict"), loopVariables: ["key"], nodes: nodes, emptyNodes: emptyNodes, where: nil)
|
||||||
let result = try node.render(context)
|
let result = try node.render(context)
|
||||||
|
|
||||||
let sortedResult = result.split(separator: ",").map(String.init).sorted(by: <)
|
try expect(result) == """
|
||||||
try expect(sortedResult) == ["one", "two"]
|
one,two,
|
||||||
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
$0.it("renders supports iterating over dictionary") {
|
$0.it("renders supports iterating over dictionary") {
|
||||||
@@ -235,11 +237,11 @@ func testForNode() {
|
|||||||
]
|
]
|
||||||
let emptyNodes: [NodeType] = [TextNode(text: "empty")]
|
let emptyNodes: [NodeType] = [TextNode(text: "empty")]
|
||||||
let node = ForNode(resolvable: Variable("dict"), loopVariables: ["key", "value"], nodes: nodes, emptyNodes: emptyNodes, where: nil)
|
let node = ForNode(resolvable: Variable("dict"), loopVariables: ["key", "value"], nodes: nodes, emptyNodes: emptyNodes, where: nil)
|
||||||
|
|
||||||
let result = try node.render(context)
|
let result = try node.render(context)
|
||||||
|
|
||||||
let sortedResult = result.split(separator: ",").map(String.init).sorted(by: <)
|
try expect(result) == """
|
||||||
try expect(sortedResult) == ["one=I", "two=II"]
|
one=I,two=II,
|
||||||
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
$0.it("handles invalid input") {
|
$0.it("handles invalid input") {
|
||||||
|
|||||||
Reference in New Issue
Block a user