Skip to content

Commit bacf5c6

Browse files
committedOct 28, 2024
add code generation test
1 parent 7b7079d commit bacf5c6

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed
 

‎.github/workflows/tests.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ jobs:
1616
- swift:6.0-noble
1717
- swiftlang/swift:nightly-main-jammy
1818
config:
19-
- args: "--enable-code-coverage"
19+
- mode: "debug"
20+
args: "--enable-code-coverage"
2021
with_codecov: true
21-
- args: "-c release -Xswiftc -enable-testing"
22+
- mode: "release"
23+
args: "-c release -Xswiftc -enable-testing"
2224
with_codecov: false
2325

2426
runs-on: ubuntu-latest
@@ -37,8 +39,8 @@ jobs:
3739
with:
3840
path: .build
3941
# e.g. 'enumerator-macro-debug-build-swiftlang/swift:nightly-6.0-jammy-Linux-c7008df8062ac4d5887ead9e59aa05829e'
40-
key: "${{ github.event.repository.name }}-debug-build-${{ matrix.swift-image }}-${{ runner.os }}-${{ hashFiles('./Package.resolved') }}"
41-
restore-keys: "${{ github.event.repository.name }}-debug-build-${{ matrix.swift-image }}-${{ runner.os }}-"
42+
key: "${{ github.event.repository.name }}-${{ matrix.config.mode }}-build-${{ matrix.swift-image }}-${{ runner.os }}-${{ hashFiles('./Package.resolved') }}"
43+
restore-keys: "${{ github.event.repository.name }}-${{ matrix.config.mode }}-build-${{ matrix.swift-image }}-${{ runner.os }}-"
4244

4345
- name: Build ${{ github.event.repository.name }}
4446
run: swift build --build-tests
@@ -48,7 +50,7 @@ jobs:
4850
uses: actions/cache/save@v4
4951
with:
5052
path: .build
51-
key: "${{ github.event.repository.name }}-debug-build-${{ matrix.swift-image }}-${{ runner.os }}-${{ hashFiles('./Package.resolved') }}"
53+
key: "${{ github.event.repository.name }}-${{ matrix.config.mode }}-build-${{ matrix.swift-image }}-${{ runner.os }}-${{ hashFiles('./Package.resolved') }}"
5254

5355
- name: Run tests
5456
run: swift test ${{ matrix.config.args }} --parallel

‎Tests/EnumeratorMacroTests/EnumeratorMacroTests.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ final class EnumeratorMacroTests: XCTestCase {
6969
enum TestEnum {
7070
case aBcD
7171
case eFgH
72-
72+
7373
var caseCode: Int {
7474
switch self {
7575
case .aBcD:
@@ -108,7 +108,7 @@ final class EnumeratorMacroTests: XCTestCase {
108108
enum TestEnum {
109109
case aBcD
110110
case eFgH
111-
111+
112112
var caseCode: Int {
113113
switch self {
114114
case .aBcD:
@@ -273,7 +273,7 @@ final class EnumeratorMacroTests: XCTestCase {
273273
assertMacroExpansion(
274274
#"""
275275
@Enumerator("""
276-
{{#cases}}
276+
{{#cases}}
277277
{{^isEmpty(parameters)}}
278278
func get{{capitalized(name)}}() -> ({{joined(tupleValue(parameters))}})? {
279279
switch self {
@@ -283,7 +283,7 @@ final class EnumeratorMacroTests: XCTestCase {
283283
return nil
284284
}
285285
}
286-
{{/isEmpty(parameters)}}
286+
{{/isEmpty(parameters)}}
287287
{{/cases}}
288288
""")
289289
enum TestEnum {
@@ -1230,6 +1230,10 @@ final class EnumeratorMacroTests: XCTestCase {
12301230
)
12311231
}
12321232

1233+
func testRealEnumGeneratesCode() throws {
1234+
XCTAssertEqual(TestEnum.b.caseName, "b")
1235+
}
1236+
12331237
/// FixItApplier not available in older versions of SwiftSyntax.
12341238
#if canImport(SwiftSyntax600)
12351239
/// Test name is referenced in the README.
@@ -1285,6 +1289,16 @@ var isTestCase2: Bool {
12851289
}
12861290
}
12871291
""")
1292+
@Enumerator("""
1293+
var caseName: Bool {
1294+
switch self {
1295+
{{#cases}}
1296+
case .{{name}}:
1297+
return "{{name}}"
1298+
{{/cases}}
1299+
}
1300+
}
1301+
""")
12881302
enum TestEnum {
12891303
case a(val1: String, val2: Int)
12901304
case b

0 commit comments

Comments
 (0)