fix: subscripting tuple by value index (#172)
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
- Integer literals now resolve into Int values, not Float
|
- Integer literals now resolve into Int values, not Float
|
||||||
- Fixed accessing properties of optional properties via reflection
|
- Fixed accessing properties of optional properties via reflection
|
||||||
- No longer render optional values in arrays as `Optional(..)`
|
- No longer render optional values in arrays as `Optional(..)`
|
||||||
|
- Fixed subscription tuples by value index, i.e. `{{ tuple.0 }}`
|
||||||
|
|
||||||
|
|
||||||
## 0.10.1
|
## 0.10.1
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ func parseFilterComponents(token: String) -> (String, [Variable]) {
|
|||||||
|
|
||||||
extension Mirror {
|
extension Mirror {
|
||||||
func getValue(for key: String) -> Any? {
|
func getValue(for key: String) -> Any? {
|
||||||
let result = descendant(key)
|
let result = descendant(key) ?? Int(key).flatMap({ descendant($0) })
|
||||||
if result == nil {
|
if result == nil {
|
||||||
// go through inheritance chain to reach superclass properties
|
// go through inheritance chain to reach superclass properties
|
||||||
return superclassMirror?.getValue(for: key)
|
return superclassMirror?.getValue(for: key)
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ func testVariable() {
|
|||||||
"counter": [
|
"counter": [
|
||||||
"count": "kylef",
|
"count": "kylef",
|
||||||
],
|
],
|
||||||
"article": Article(author: Person(name: "Kyle"))
|
"article": Article(author: Person(name: "Kyle")),
|
||||||
|
"tuple": (one: 1, two: 2)
|
||||||
])
|
])
|
||||||
|
|
||||||
#if os(OSX)
|
#if os(OSX)
|
||||||
@@ -175,5 +176,17 @@ func testVariable() {
|
|||||||
try expect(VariableNode(variable: "values").render(context)) == "[1, nil, [1, nil]]"
|
try expect(VariableNode(variable: "values").render(context)) == "[1, nil, [1, nil]]"
|
||||||
try expect(VariableNode(variable: "values.1").render(context)) == ""
|
try expect(VariableNode(variable: "values.1").render(context)) == ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$0.it("can subscript tuple by index") {
|
||||||
|
let variable = Variable("tuple.0")
|
||||||
|
let result = try variable.resolve(context) as? Int
|
||||||
|
try expect(result) == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$0.it("can subscript tuple by label") {
|
||||||
|
let variable = Variable("tuple.two")
|
||||||
|
let result = try variable.resolve(context) as? Int
|
||||||
|
try expect(result) == 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user