-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCodeStyleMigrationTests.swift
More file actions
81 lines (63 loc) · 2.37 KB
/
CodeStyleMigrationTests.swift
File metadata and controls
81 lines (63 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import Testing
@testable import SyntaxKit
/// Tests for code style and API simplification changes introduced during Swift Testing migration
/// Validates the simplified Swift APIs and formatting changes
struct CodeStyleMigrationTests {
// MARK: - CharacterSet Simplification Tests
@Test func testCharacterSetSimplification() {
// Test that .whitespacesAndNewlines works instead of CharacterSet.whitespacesAndNewlines
let testString = "\n test content \n\t"
// Old style: CharacterSet.whitespacesAndNewlines
// New style: .whitespacesAndNewlines
let trimmed = testString.trimmingCharacters(in: .whitespacesAndNewlines)
#expect(trimmed == "test content")
}
// MARK: - Indentation and Formatting Tests
@Test func testConsistentIndentationInMigratedCode() throws {
// Test that the indentation changes in the migrated code work correctly
let syntax = Struct("IndentationTest") {
Variable(.let, name: "property1", type: "String")
Variable(.let, name: "property2", type: "Int")
Function("method") {
Parameter(name: "param", type: "String")
} _: {
VariableDecl(.let, name: "local", equals: "\"value\"")
Return {
VariableExp("local")
}
}
}
let generated = syntax.generateCode().normalize()
// Verify proper indentation is maintained
#expect(
generated
== "struct IndentationTest { let property1: String let property2: Int func method(param: String) { let local = \"value\" return local } }"
)
}
// MARK: - Multiline String Formatting Tests
@Test func testMultilineStringFormatting() {
let expected = """
struct TestStruct {
let value: String
var count: Int
}
"""
let syntax = Struct("TestStruct") {
Variable(.let, name: "value", type: "String")
Variable(.var, name: "count", type: "Int")
}
let normalized = syntax.generateCode().normalize()
let expectedNormalized = expected.normalize()
#expect(normalized == expectedNormalized)
}
@Test func testMigrationPreservesCodeGeneration() {
// Ensure that the style changes don't break core functionality
let group = Group {
Return {
Literal.string("migrated")
}
}
let generated = group.generateCode().trimmingCharacters(in: .whitespacesAndNewlines)
#expect(generated == "return \"migrated\"")
}
}