|
| 1 | +import Testing |
| 2 | + |
| 3 | +@testable import SyntaxKit |
| 4 | + |
| 5 | +/// Tests specifically focused on assertion migration from XCTest to Swift Testing |
| 6 | +/// Ensures all assertion patterns from the original tests work correctly with #expect() |
| 7 | +struct AssertionMigrationTests { |
| 8 | + // MARK: - XCTAssertEqual Migration Tests |
| 9 | + |
| 10 | + @Test func testEqualityAssertionMigration() throws { |
| 11 | + // Test the most common migration: XCTAssertEqual -> #expect(a == b) |
| 12 | + let function = Function("test", returns: "String") { |
| 13 | + Return { |
| 14 | + Literal.string("hello") |
| 15 | + } |
| 16 | + } |
| 17 | + |
| 18 | + let generated = function.syntax.description |
| 19 | + .replacingOccurrences(of: "\\s+", with: " ", options: .regularExpression) |
| 20 | + .trimmingCharacters(in: .whitespacesAndNewlines) |
| 21 | + |
| 22 | + let expected = "func test() -> String { return \"hello\" }" |
| 23 | + .replacingOccurrences(of: "\\s+", with: " ", options: .regularExpression) |
| 24 | + .trimmingCharacters(in: .whitespacesAndNewlines) |
| 25 | + |
| 26 | + // This replaces: XCTAssertEqual(generated, expected) |
| 27 | + #expect(generated == expected) |
| 28 | + } |
| 29 | + |
| 30 | + // MARK: - XCTAssertFalse Migration Tests |
| 31 | + |
| 32 | + @Test func testFalseAssertionMigration() { |
| 33 | + let syntax = Group { |
| 34 | + Variable(.let, name: "test", type: "String", equals: "\"value\"") |
| 35 | + } |
| 36 | + |
| 37 | + let generated = syntax.generateCode().trimmingCharacters(in: .whitespacesAndNewlines) |
| 38 | + |
| 39 | + // This replaces: XCTAssertFalse(generated.isEmpty) |
| 40 | + #expect(!generated.isEmpty) |
| 41 | + } |
| 42 | + |
| 43 | + // MARK: - Complex Assertion Migration Tests |
| 44 | + |
| 45 | + @Test func testNormalizedStringComparisonMigration() throws { |
| 46 | + let blackjackCard = Struct("Card") { |
| 47 | + Enum("Suit") { |
| 48 | + EnumCase("hearts").equals("♡") |
| 49 | + EnumCase("spades").equals("♠") |
| 50 | + }.inherits("Character") |
| 51 | + } |
| 52 | + |
| 53 | + let expected = """ |
| 54 | + struct Card { |
| 55 | + enum Suit: Character { |
| 56 | + case hearts = "♡" |
| 57 | + case spades = "♠" |
| 58 | + } |
| 59 | + } |
| 60 | + """ |
| 61 | + |
| 62 | + // Test the complete normalization pipeline that was used in XCTest |
| 63 | + let normalizedGenerated = blackjackCard.syntax.description.normalize() |
| 64 | + |
| 65 | + let normalizedExpected = expected.normalize() |
| 66 | + |
| 67 | + // This replaces: XCTAssertEqual(normalizedGenerated, normalizedExpected) |
| 68 | + #expect(normalizedGenerated == normalizedExpected) |
| 69 | + } |
| 70 | + |
| 71 | + @Test func testMultipleAssertionsInSingleTest() { |
| 72 | + let generated = "struct Test { var value: Int }" |
| 73 | + |
| 74 | + // Test multiple assertions in one test method |
| 75 | + #expect(!generated.isEmpty) |
| 76 | + #expect(generated.contains("struct Test")) |
| 77 | + #expect(generated.contains("var value: Int")) |
| 78 | + } |
| 79 | +} |
0 commit comments