Add tests of `Node.subscript(_:)`

This commit is contained in:
Norio Nomura 2017-02-04 00:29:21 +09:00
parent 5e3c6be8e3
commit 44569e7e92
No known key found for this signature in database
GPG Key ID: D4A7318EB7F7138D
1 changed files with 7 additions and 5 deletions

View File

@ -110,15 +110,17 @@ class NodeTests: XCTestCase {
}
func testSubscriptMapping() {
let mapping: Node = ["key1": "value1", "key2": "value2"]
let valueForKey1 = mapping["key1"]?.string
XCTAssertEqual(valueForKey1, "value1")
let mapping: Node = ["key1": "value1", "key2": "value2", "key3": "value3"]
XCTAssertEqual(mapping["key1" as Node]?.string, "value1") // Node resolvable as String
XCTAssertEqual(mapping["key2"]?.string, "value2") // String Literal
XCTAssertEqual(mapping[String("key3")]?.string, "value3") // String
}
func testSubscriptSequence() {
let mapping: Node = ["value1", "value2", "value3"]
let valueAtSecond = mapping[1]?.string
XCTAssertEqual(valueAtSecond, "value2")
XCTAssertEqual(mapping["0" as Node]?.string, "value1") // Node resolvable as Integer
XCTAssertEqual(mapping[1]?.string, "value2") // Integer Literal
XCTAssertEqual(mapping[Int(2)]?.string, "value3") // Int
}
func testMappingBehavesLikeADictionary() {