|
1 | | -import XCTest |
| 1 | +import Testing |
2 | 2 |
|
3 | 3 | @testable import SyntaxKit |
4 | 4 |
|
5 | | -final class BasicTests: XCTestCase { |
6 | | - 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 | | - } |
| 5 | +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 | + } |
15 | 15 |
|
16 | | - let expected = """ |
17 | | - struct BlackjackCard { |
18 | | - enum Suit: Character { |
19 | | - case spades = "♠" |
20 | | - case hearts = "♡" |
21 | | - case diamonds = "♢" |
22 | | - case clubs = "♣" |
| 16 | + let expected = """ |
| 17 | + struct BlackjackCard { |
| 18 | + enum Suit: Character { |
| 19 | + case spades = "♠" |
| 20 | + case hearts = "♡" |
| 21 | + case diamonds = "♢" |
| 22 | + case clubs = "♣" |
| 23 | + } |
23 | 24 | } |
24 | | - } |
25 | | - """ |
| 25 | + """ |
26 | 26 |
|
27 | | - // Normalize whitespace, remove comments and modifiers, and normalize colon spacing |
28 | | - let normalizedGenerated = blackjackCard.syntax.description |
29 | | - .replacingOccurrences(of: "//.*$", with: "", options: .regularExpression) // Remove comments |
30 | | - .replacingOccurrences(of: "public\\s+", with: "", options: .regularExpression) // Remove public modifier |
31 | | - .replacingOccurrences(of: "\\s*:\\s*", with: ": ", options: .regularExpression) // Normalize colon spacing |
32 | | - .replacingOccurrences(of: "\\s+", with: " ", options: .regularExpression) // Normalize whitespace |
33 | | - .trimmingCharacters(in: .whitespacesAndNewlines) |
| 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) |
34 | 34 |
|
35 | | - let normalizedExpected = |
36 | | - expected |
37 | | - .replacingOccurrences(of: "//.*$", with: "", options: .regularExpression) // Remove comments |
38 | | - .replacingOccurrences(of: "public\\s+", with: "", options: .regularExpression) // Remove public modifier |
39 | | - .replacingOccurrences(of: "\\s*:\\s*", with: ": ", options: .regularExpression) // Normalize colon spacing |
40 | | - .replacingOccurrences(of: "\\s+", with: " ", options: .regularExpression) // Normalize whitespace |
41 | | - .trimmingCharacters(in: .whitespacesAndNewlines) |
| 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) |
42 | 42 |
|
43 | | - XCTAssertEqual(normalizedGenerated, normalizedExpected) |
44 | | - } |
| 43 | + #expect(normalizedGenerated == normalizedExpected) |
| 44 | + } |
45 | 45 | } |
0 commit comments