|
| 1 | +@testable import GraphQL |
| 2 | +import XCTest |
| 3 | + |
| 4 | +class MapTests: XCTestCase { |
| 5 | + func testThrowableConversion() throws { |
| 6 | + XCTAssertEqual(try Map.number(5).intValue(), 5) |
| 7 | + XCTAssertEqual(try Map.number(3.14).doubleValue(), 3.14) |
| 8 | + XCTAssertEqual(try Map.bool(false).boolValue(), false) |
| 9 | + XCTAssertEqual(try Map.bool(true).boolValue(), true) |
| 10 | + XCTAssertEqual(try Map.string("Hello world").stringValue(), "Hello world") |
| 11 | + |
| 12 | + } |
| 13 | + |
| 14 | + func testOptionalConversion() { |
| 15 | + XCTAssertEqual(Map.number(5).int, 5) |
| 16 | + XCTAssertEqual(Map.number(3.14).double, 3.14) |
| 17 | + XCTAssertEqual(Map.bool(false).bool, false) |
| 18 | + XCTAssertEqual(Map.bool(true).bool, true) |
| 19 | + XCTAssertEqual(Map.string("Hello world").string, "Hello world") |
| 20 | + } |
| 21 | + |
| 22 | + func testArrayConversion() throws { |
| 23 | + let map = Map.array([.number(1), .number(4), .number(9)]) |
| 24 | + XCTAssertEqual(map.array?.count, 3) |
| 25 | + |
| 26 | + let array = try map.arrayValue() |
| 27 | + XCTAssertEqual(array.count, 3) |
| 28 | + |
| 29 | + XCTAssertEqual(try array[0].intValue(), 1) |
| 30 | + XCTAssertEqual(try array[1].intValue(), 4) |
| 31 | + XCTAssertEqual(try array[2].intValue(), 9) |
| 32 | + } |
| 33 | + |
| 34 | + func testDictionaryConversion() throws { |
| 35 | + let map = Map.dictionary( |
| 36 | + [ |
| 37 | + "first": .number(1), |
| 38 | + "second": .number(4), |
| 39 | + "third": .number(9) |
| 40 | + ] |
| 41 | + ) |
| 42 | + XCTAssertEqual(map.dictionary?.count, 3) |
| 43 | + |
| 44 | + let dictionary = try map.dictionaryValue() |
| 45 | + |
| 46 | + XCTAssertEqual(dictionary.count, 3) |
| 47 | + XCTAssertEqual(try dictionary["first"]?.intValue(), 1) |
| 48 | + XCTAssertEqual(try dictionary["second"]?.intValue(), 4) |
| 49 | + XCTAssertEqual(try dictionary["third"]?.intValue(), 9) |
| 50 | + } |
| 51 | +} |
0 commit comments