|
| 1 | +/* |
| 2 | + This source file is part of the Swift.org open source project |
| 3 | + |
| 4 | + Copyright (c) 2023 Apple Inc. and the Swift project authors |
| 5 | + Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | + |
| 7 | + See https://swift.org/LICENSE.txt for license information |
| 8 | + See https://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 9 | +*/ |
| 10 | + |
| 11 | +import XCTest |
| 12 | +@testable import SymbolKit |
| 13 | + |
| 14 | +class GenericConstraintTests: XCTestCase { |
| 15 | + |
| 16 | + func testInitializeConformance() throws { |
| 17 | + let jsonString = """ |
| 18 | + { |
| 19 | + "kind": "conformance", |
| 20 | + "lhs": "Self", |
| 21 | + "rhs": "Hashable", |
| 22 | + } |
| 23 | + """ |
| 24 | + let jsonData = Data(jsonString.utf8) |
| 25 | + let jsonConstraint = try JSONDecoder().decode(SymbolGraph.Symbol.Swift.GenericConstraint.self, from: jsonData) |
| 26 | + let constraint = SymbolGraph.Symbol.Swift.GenericConstraint( |
| 27 | + kind: .conformance, |
| 28 | + leftTypeName: "Self", |
| 29 | + rightTypeName: "Hashable" |
| 30 | + ) |
| 31 | + XCTAssertEqual(jsonConstraint, constraint) |
| 32 | + } |
| 33 | + |
| 34 | + func testInitializeSuperclass() throws { |
| 35 | + let jsonString = """ |
| 36 | + { |
| 37 | + "kind": "superclass", |
| 38 | + "lhs": "Self", |
| 39 | + "rhs": "String", |
| 40 | + } |
| 41 | + """ |
| 42 | + let jsonData = Data(jsonString.utf8) |
| 43 | + let jsonConstraint = try JSONDecoder().decode(SymbolGraph.Symbol.Swift.GenericConstraint.self, from: jsonData) |
| 44 | + let constraint = SymbolGraph.Symbol.Swift.GenericConstraint( |
| 45 | + kind: .superclass, |
| 46 | + leftTypeName: "Self", |
| 47 | + rightTypeName: "String" |
| 48 | + ) |
| 49 | + XCTAssertEqual(jsonConstraint, constraint) |
| 50 | + } |
| 51 | + |
| 52 | + func testInitializeSameType() throws { |
| 53 | + let jsonString = """ |
| 54 | + { |
| 55 | + "kind": "sameType", |
| 56 | + "lhs": "Self", |
| 57 | + "rhs": "Problem", |
| 58 | + } |
| 59 | + """ |
| 60 | + let jsonData = Data(jsonString.utf8) |
| 61 | + let jsonConstraint = try JSONDecoder().decode(SymbolGraph.Symbol.Swift.GenericConstraint.self, from: jsonData) |
| 62 | + let constraint = SymbolGraph.Symbol.Swift.GenericConstraint( |
| 63 | + kind: .sameType, |
| 64 | + leftTypeName: "Self", |
| 65 | + rightTypeName: "Problem" |
| 66 | + ) |
| 67 | + XCTAssertEqual(jsonConstraint, constraint) |
| 68 | + } |
| 69 | +} |
0 commit comments