Skip to content

Commit

Permalink
refactor: fixes warnings detected in Xcode 14.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fumito-ito committed Jun 29, 2023
1 parent 476ab7b commit a898858
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
30 changes: 16 additions & 14 deletions Tests/Public/BoxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import Mustache
private struct CustomHashableBoxable : MustacheBoxable, Hashable {
let int: Int
init(_ int: Int) { self.int = int }
var hashValue: Int { return int }
func hash(into hasher: inout Hasher) {
hasher.combine(int)
}
var mustacheBox: MustacheBox {
// Don't inherit the boolean nature of int
return MustacheBox(
Expand Down Expand Up @@ -588,22 +590,22 @@ class BoxTests: XCTestCase {
}
do {
// Infered element type (won't compile)
let value: Dictionary = ["int": [1, 2], "string": ["foo", "bar"]]
let value: Dictionary = ["int": [1, 2] as [Any], "string": ["foo", "bar"]]
let template = try! Template(string: "{{int}}, {{string}}")
let rendering = try! template.render(value)
XCTAssertEqual(rendering, "12, foobar")
}
do {
// Infered type (won't compile)
let value = ["int": [1, 2], "string": ["foo", "bar"]]
let value = ["int": [1, 2] as [Any], "string": ["foo", "bar"]]
let template = try! Template(string: "{{int}}, {{string}}")
let rendering = try! template.render(value)
XCTAssertEqual(rendering, "12, foobar")
}
do {
// Infered type
let template = try! Template(string: "{{int}}, {{string}}")
let value = ["int": [1, 2], "string": ["foo", "bar"]]
let value = ["int": [1, 2] as [Any], "string": ["foo", "bar"]]
let rendering = try! template.render(value)
XCTAssertEqual(rendering, "12, foobar")
}
Expand All @@ -626,22 +628,22 @@ class BoxTests: XCTestCase {
}
do {
// Infered element type (won't compile)
let value: Dictionary = ["int": ["name": 1], "string": ["name": "foo"]]
let value: Dictionary = ["int": ["name": 1] as [String : Any], "string": ["name": "foo"]]
let template = try! Template(string: "{{int.name}}, {{string.name}}")
let rendering = try! template.render(value)
XCTAssertEqual(rendering, "1, foo")
}
do {
// Infered type (won't compile)
let value = ["int": ["name": 1], "string": ["name": "foo"]]
let value = ["int": ["name": 1] as [String : Any], "string": ["name": "foo"]]
let template = try! Template(string: "{{int.name}}, {{string.name}}")
let rendering = try! template.render(value)
XCTAssertEqual(rendering, "1, foo")
}
do {
// Infered type
let template = try! Template(string: "{{int.name}}, {{string.name}}")
let value = ["int": ["name": 1], "string": ["name": "foo"]]
let value = ["int": ["name": 1] as [String : Any], "string": ["name": "foo"]]
let rendering = try! template.render(value)
XCTAssertEqual(rendering, "1, foo")
}
Expand Down Expand Up @@ -912,7 +914,7 @@ class BoxTests: XCTestCase {
do {
// Direct argument
let template = try! Template(string: "{{#.}}{{.}}{{/}}")
let rendering = try! template.render([0,"foo"])
let rendering = try! template.render([0,"foo"] as [Any])
XCTAssertEqual(rendering, "0foo")
}
do {
Expand All @@ -927,34 +929,34 @@ class BoxTests: XCTestCase {
func testArrayOfArray() {
do {
// Explicit type
let value: [Any] = [[0,"foo"]]
let value: [Any] = [[0,"foo"] as [Any]]
let template = try! Template(string: "{{#.}}{{.}}{{/}}")
let rendering = try! template.render(value)
XCTAssertEqual(rendering, "0foo")
}
do {
// Infered element type
let value: Array = [[0,"foo"]]
let value: Array = [[0,"foo"] as [Any]]
let template = try! Template(string: "{{#.}}{{.}}{{/}}")
let rendering = try! template.render(value)
XCTAssertEqual(rendering, "0foo")
}
do {
// Infered type
let value = [[0,"foo"]]
let value = [[0,"foo"] as [Any]]
let template = try! Template(string: "{{#.}}{{.}}{{/}}")
let rendering = try! template.render(value)
XCTAssertEqual(rendering, "0foo")
}
do {
// Direct argument
let template = try! Template(string: "{{#.}}{{.}}{{/}}")
let rendering = try! template.render([[0,"foo"]])
let rendering = try! template.render([[0,"foo"] as [Any]])
XCTAssertEqual(rendering, "0foo")
}
do {
// Nested
let value: [Any] = [[0,"foo"]]
let value: [Any] = [[0,"foo"] as [Any]]
let template = try! Template(string: "{{#nested}}{{#.}}{{.}}{{/}}{{/}}")
let rendering = try! template.render(["nested": value])
XCTAssertEqual(rendering, "0foo")
Expand Down Expand Up @@ -1033,7 +1035,7 @@ class BoxTests: XCTestCase {
do {
// Direct argument
let template = try! Template(string: "{{#.}}{{.}}{{/}}")
let rendering = try! template.render([0, nil, "foo"])
let rendering = try! template.render([0, nil, "foo"] as [Any?])
XCTAssertEqual(rendering, "0foo")
}
do {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Public/ContextTests/ContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ContextTests: XCTestCase {
}

func testSubscript() {
let context = Context(["name": "name1", "a": ["name": "name2"]])
let context = Context(["name": "name1", "a": ["name": "name2"]] as [String : Any])

// '.' is an expression, not a key
XCTAssertTrue(context.mustacheBox(forKey: ".").isEmpty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ContextValueForMustacheExpressionTests: XCTestCase {
let filter = Filter({ (string: String?) -> Any? in
return string!.uppercased()
})
let context = Context(["name": "success", "f": filter])
let context = Context(["name": "success", "f": filter] as [String : Any])
let box = try! context.mustacheBox(forExpression: "f(name)")
let string = box.value as? String
XCTAssertEqual(string!, "SUCCESS")
Expand Down
4 changes: 2 additions & 2 deletions Tests/Public/HookFunctionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class HookFunctionTests: XCTestCase {
template.baseContext = template.baseContext.extendedContext(willRender)
willRenderCount = 0
renderedValue = nil
rendering = try! template.render(["subject": "foo", "filter": Filter(filter)])
rendering = try! template.render(["subject": "foo", "filter": Filter(filter)] as [String : Any])
XCTAssertEqual(rendering, "FOO")
XCTAssertEqual(willRenderCount, 1)
XCTAssertEqual((renderedValue!.value as! String), "FOO")
Expand All @@ -217,7 +217,7 @@ class HookFunctionTests: XCTestCase {
template.baseContext = template.baseContext.extendedContext(willRender)
willRenderCount = 0
renderedValue = nil
rendering = try! template.render(["subject": "foo", "filter": Filter(filter)])
rendering = try! template.render(["subject": "foo", "filter": Filter(filter)] as [String : Any])
XCTAssertEqual(rendering, "3")
XCTAssertEqual(willRenderCount, 1)
XCTAssertEqual((renderedValue!.value as! Int), 3)
Expand Down

0 comments on commit a898858

Please sign in to comment.