fixed implicit conversion of integer literals to float
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
- Fixed rendering `{{ block.super }}` with several levels of inheritance
|
- Fixed rendering `{{ block.super }}` with several levels of inheritance
|
||||||
- Fixed checking dictionary values for nil in `default` filter
|
- Fixed checking dictionary values for nil in `default` filter
|
||||||
- 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
|
||||||
|
|
||||||
|
|
||||||
## 0.10.1
|
## 0.10.1
|
||||||
|
|||||||
@@ -63,8 +63,11 @@ public struct Variable : Equatable, Resolvable {
|
|||||||
return String(variable[variable.characters.index(after: variable.startIndex) ..< variable.characters.index(before: variable.endIndex)])
|
return String(variable[variable.characters.index(after: variable.startIndex) ..< variable.characters.index(before: variable.endIndex)])
|
||||||
}
|
}
|
||||||
|
|
||||||
if let number = Number(variable) {
|
|
||||||
// Number literal
|
// Number literal
|
||||||
|
if let int = Int(variable) {
|
||||||
|
return int
|
||||||
|
}
|
||||||
|
if let number = Number(variable) {
|
||||||
return number
|
return number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,6 +137,18 @@ func testFilter() {
|
|||||||
try expect(result) == "Hello World"
|
try expect(result) == "Hello World"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$0.it("can use int as default") {
|
||||||
|
let template = Template(templateString: "{{ value|default:1 }}")
|
||||||
|
let result = try template.render(Context(dictionary: [:]))
|
||||||
|
try expect(result) == "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
$0.it("can use float as default") {
|
||||||
|
let template = Template(templateString: "{{ value|default:1.5 }}")
|
||||||
|
let result = try template.render(Context(dictionary: [:]))
|
||||||
|
try expect(result) == "1.5"
|
||||||
|
}
|
||||||
|
|
||||||
$0.it("checks for underlying nil value correctly") {
|
$0.it("checks for underlying nil value correctly") {
|
||||||
let template = Template(templateString: "Hello {{ user.name|default:\"anonymous\" }}")
|
let template = Template(templateString: "Hello {{ user.name|default:\"anonymous\" }}")
|
||||||
let nilName: String? = nil
|
let nilName: String? = nil
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func testVariable() {
|
|||||||
|
|
||||||
$0.it("can resolve an integer literal") {
|
$0.it("can resolve an integer literal") {
|
||||||
let variable = Variable("5")
|
let variable = Variable("5")
|
||||||
let result = try variable.resolve(context) as? Number
|
let result = try variable.resolve(context) as? Int
|
||||||
try expect(result) == 5
|
try expect(result) == 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user