1+ import Testing
2+
3+ @testable import SyntaxKit
4+
5+ /// Tests to ensure compatibility and feature parity between XCTest and Swift Testing
6+ /// Validates that the migration maintains all testing capabilities
7+ struct FrameworkCompatibilityTests {
8+
9+ // MARK: - Test Organization Migration Tests
10+
11+ @Test func testStructBasedOrganization( ) {
12+ // Test that struct-based test organization works
13+ // This replaces: final class TestClass: XCTestCase
14+ let testExecuted = true
15+ #expect( testExecuted)
16+ }
17+
18+ @Test func testMethodAnnotationMigration( ) throws {
19+ // Test that @Test annotation works with throws
20+ // This replaces: func testMethod() throws
21+ let syntax = Enum ( " TestEnum " ) {
22+ EnumCase ( " first " )
23+ EnumCase ( " second " )
24+ }
25+
26+ let generated = syntax. syntax. description
27+ #expect( !generated. isEmpty)
28+ #expect( generated. contains ( " enum TestEnum " ) )
29+ }
30+
31+ // MARK: - Error Handling Compatibility Tests
32+
33+ @Test func testThrowingTestCompatibility( ) throws {
34+ // Ensure throws declaration works properly with @Test
35+ let function = Function ( " throwingFunction " , returns: " String " ) {
36+ Parameter ( name: " input " , type: " String " )
37+ } _: {
38+ Return {
39+ VariableExp ( " input.uppercased() " )
40+ }
41+ }
42+
43+ let generated = try function. syntax. description
44+ #expect( generated. contains ( " func throwingFunction " ) )
45+ }
46+
47+ // MARK: - Complex DSL Compatibility Tests
48+
49+ @Test func testFullBlackjackCompatibility( ) throws {
50+ // Test complex DSL patterns work with new framework
51+ let syntax = Struct ( " BlackjackCard " ) {
52+ Enum ( " Suit " ) {
53+ EnumCase ( " spades " ) . equals ( " ♠ " )
54+ EnumCase ( " hearts " ) . equals ( " ♡ " )
55+ EnumCase ( " diamonds " ) . equals ( " ♢ " )
56+ EnumCase ( " clubs " ) . equals ( " ♣ " )
57+ } . inherits ( " Character " )
58+
59+ Enum ( " Rank " ) {
60+ EnumCase ( " ace " ) . equals ( 1 )
61+ EnumCase ( " two " ) . equals ( 2 )
62+ EnumCase ( " jack " ) . equals ( 11 )
63+ EnumCase ( " queen " ) . equals ( 12 )
64+ EnumCase ( " king " ) . equals ( 13 )
65+ } . inherits ( " Int " )
66+
67+ Variable ( . let, name: " rank " , type: " Rank " )
68+ Variable ( . let, name: " suit " , type: " Suit " )
69+ }
70+
71+ let generated = syntax. syntax. description
72+ let normalized = generated
73+ . replacingOccurrences ( of: " //.*$ " , with: " " , options: . regularExpression)
74+ . replacingOccurrences ( of: " public \\ s+ " , with: " " , options: . regularExpression)
75+ . replacingOccurrences ( of: " \\ s*: \\ s* " , with: " : " , options: . regularExpression)
76+ . replacingOccurrences ( of: " \\ s+ " , with: " " , options: . regularExpression)
77+ . trimmingCharacters ( in: . whitespacesAndNewlines)
78+
79+ // Validate all components are present
80+ #expect( normalized. contains ( " struct BlackjackCard " ) )
81+ #expect( normalized. contains ( " enum Suit: Character " ) )
82+ #expect( normalized. contains ( " enum Rank: Int " ) )
83+ #expect( normalized. contains ( " let rank: Rank " ) )
84+ #expect( normalized. contains ( " let suit: Suit " ) )
85+ }
86+
87+ // MARK: - Function Generation Compatibility Tests
88+
89+ @Test func testFunctionGenerationCompatibility( ) throws {
90+ let function = Function ( " calculateValue " , returns: " Int " ) {
91+ Parameter ( name: " multiplier " , type: " Int " )
92+ Parameter ( name: " base " , type: " Int " , defaultValue: " 10 " )
93+ } _: {
94+ Return {
95+ VariableExp ( " multiplier * base " )
96+ }
97+ }
98+
99+ let generated = function. syntax. description
100+ let normalized = generated
101+ . replacingOccurrences ( of: " \\ s+ " , with: " " , options: . regularExpression)
102+ . trimmingCharacters ( in: . whitespacesAndNewlines)
103+
104+ #expect( normalized. contains ( " func calculateValue(multiplier: Int, base: Int = 10) -> Int " ) )
105+ #expect( normalized. contains ( " return multiplier * base " ) )
106+ }
107+
108+ // MARK: - Comment Injection Compatibility Tests
109+
110+ @Test func testCommentInjectionCompatibility( ) {
111+ let syntax = Struct ( " DocumentedStruct " ) {
112+ Variable ( . let, name: " value " , type: " String " )
113+ . comment {
114+ Line ( . doc, " The main value of the struct " )
115+ }
116+ } . comment {
117+ Line ( " MARK: - Data Models " )
118+ Line ( . doc, " A documented struct for testing " )
119+ }
120+
121+ let generated = syntax. generateCode ( )
122+
123+ #expect( !generated. isEmpty)
124+ #expect( generated. contains ( " struct DocumentedStruct " ) )
125+ #expect( generated. contains ( " let value: String " ) )
126+ }
127+
128+ // MARK: - Migration Regression Tests
129+
130+ @Test func testNoRegressionInCodeGeneration( ) {
131+ // Ensure migration doesn't introduce regressions
132+ let simpleStruct = Struct ( " Point " ) {
133+ Variable ( . var, name: " x " , type: " Double " , equals: " 0.0 " )
134+ Variable ( . var, name: " y " , type: " Double " , equals: " 0.0 " )
135+ }
136+
137+ let generated = simpleStruct. generateCode ( )
138+
139+ #expect( generated. contains ( " struct Point " ) )
140+ #expect( generated. contains ( " var x: Double = 0.0 " ) )
141+ #expect( generated. contains ( " var y: Double = 0.0 " ) )
142+ }
143+
144+ @Test func testLiteralGeneration( ) {
145+ let group = Group {
146+ Return {
147+ Literal . integer ( 100 )
148+ }
149+ }
150+
151+ let generated = group. generateCode ( ) . trimmingCharacters ( in: . whitespacesAndNewlines)
152+ #expect( generated == " return 100 " )
153+ }
154+ }
0 commit comments