fix: Do not print Optional(...) when rendering arrays (#205)
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
- Fixed comparing string variables with string literals, in Swift 4 string literals became `Substring` and thus couldn't be directly compared to strings.
|
- Fixed comparing string variables with string literals, in Swift 4 string literals became `Substring` and thus couldn't be directly compared to strings.
|
||||||
- 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(..)`
|
||||||
|
|
||||||
|
|
||||||
## 0.10.1
|
## 0.10.1
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ public class VariableNode : NodeType {
|
|||||||
func stringify(_ result: Any?) -> String {
|
func stringify(_ result: Any?) -> String {
|
||||||
if let result = result as? String {
|
if let result = result as? String {
|
||||||
return result
|
return result
|
||||||
|
} else if let array = result as? [Any?] {
|
||||||
|
return unwrap(array).description
|
||||||
} else if let result = result as? CustomStringConvertible {
|
} else if let result = result as? CustomStringConvertible {
|
||||||
return result.description
|
return result.description
|
||||||
} else if let result = result as? NSObject {
|
} else if let result = result as? NSObject {
|
||||||
@@ -86,3 +88,16 @@ func stringify(_ result: Any?) -> String {
|
|||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func unwrap(_ array: [Any?]) -> [Any] {
|
||||||
|
return array.map { (item: Any?) -> Any in
|
||||||
|
if let item = item {
|
||||||
|
if let items = item as? [Any?] {
|
||||||
|
return unwrap(items)
|
||||||
|
} else {
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { return item as Any }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -167,5 +167,13 @@ func testVariable() {
|
|||||||
try expect(result) == "Jhon"
|
try expect(result) == "Jhon"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$0.it("does not render Optional") {
|
||||||
|
var array: [Any?] = [1, nil]
|
||||||
|
array.append(array)
|
||||||
|
let context = Context(dictionary: ["values": array])
|
||||||
|
|
||||||
|
try expect(VariableNode(variable: "values").render(context)) == "[1, nil, [1, nil]]"
|
||||||
|
try expect(VariableNode(variable: "values.1").render(context)) == ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user