Skip to content

Commit ffe9a62

Browse files
author
codecov-ai[bot]
authored
Add Tests for PR#16 (#17)
1 parent 04dc929 commit ffe9a62

10 files changed

+612
-245
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
}

Tests/SyntaxKitTests/BasicTests.swift

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,32 @@ import Testing
33
@testable import SyntaxKit
44

55
struct BasicTests {
6-
@Test func testBlackjackCardExample() throws {
7-
let blackjackCard = Struct("BlackjackCard") {
8-
Enum("Suit") {
9-
EnumCase("spades").equals("")
10-
EnumCase("hearts").equals("")
11-
EnumCase("diamonds").equals("")
12-
EnumCase("clubs").equals("")
13-
}.inherits("Character")
14-
}
6+
@Test func testBlackjackCardExample() throws {
7+
let blackjackCard = Struct("BlackjackCard") {
8+
Enum("Suit") {
9+
EnumCase("spades").equals("")
10+
EnumCase("hearts").equals("")
11+
EnumCase("diamonds").equals("")
12+
EnumCase("clubs").equals("")
13+
}.inherits("Character")
14+
}
1515

16-
let expected = """
17-
struct BlackjackCard {
18-
enum Suit: Character {
19-
case spades = ""
20-
case hearts = ""
21-
case diamonds = ""
22-
case clubs = ""
23-
}
16+
let expected = """
17+
struct BlackjackCard {
18+
enum Suit: Character {
19+
case spades = ""
20+
case hearts = ""
21+
case diamonds = ""
22+
case clubs = ""
2423
}
25-
"""
24+
}
25+
"""
2626

27-
// Normalize whitespace, remove comments and modifiers, and normalize colon spacing
28-
let normalizedGenerated = blackjackCard.syntax.description
29-
.replacingOccurrences(of: "//.*$", with: "", options: .regularExpression)
30-
.replacingOccurrences(of: "public\\s+", with: "", options: .regularExpression)
31-
.replacingOccurrences(of: "\\s*:\\s*", with: ": ", options: .regularExpression)
32-
.replacingOccurrences(of: "\\s+", with: " ", options: .regularExpression)
33-
.trimmingCharacters(in: .whitespacesAndNewlines)
27+
// Normalize whitespace, remove comments and modifiers, and normalize colon spacing
28+
let normalizedGenerated = blackjackCard.syntax.description.normalize()
3429

35-
let normalizedExpected =
36-
expected
37-
.replacingOccurrences(of: "//.*$", with: "", options: .regularExpression)
38-
.replacingOccurrences(of: "public\\s+", with: "", options: .regularExpression)
39-
.replacingOccurrences(of: "\\s*:\\s*", with: ": ", options: .regularExpression)
40-
.replacingOccurrences(of: "\\s+", with: " ", options: .regularExpression)
41-
.trimmingCharacters(in: .whitespacesAndNewlines)
30+
let normalizedExpected = expected.normalize()
4231

43-
#expect(normalizedGenerated == normalizedExpected)
44-
}
32+
#expect(normalizedGenerated == normalizedExpected)
33+
}
4534
}

0 commit comments

Comments
 (0)