Skip to content

Commit c69e508

Browse files
committed
Revert "move test case types for associated value enums up to class scope to potentially resolve issues with complex mangled type names which break tests in the swift wasm runtime"
This reverts commit fa441e3.
1 parent 75bd7b4 commit c69e508

1 file changed

Lines changed: 57 additions & 64 deletions

File tree

Tests/AutomergeTests/CodableTests/EnumAssociatedValueTests.swift

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,6 @@
11
import Automerge
22
import XCTest
33

4-
// MARK: - Test Data Structures
5-
6-
// These types are defined at file scope rather than as nested types inside the XCTestCase subclass.
7-
// Enums with associated values declared at class scope produce complex mangled type names that the
8-
// Swift-WASM runtime cannot resolve during test registration, causing a crash before any tests run.
9-
// File-scope private types avoid this issue while keeping the types local to this file.
10-
11-
private struct SimpleStruct: Codable, Equatable {
12-
let value: String
13-
}
14-
15-
private struct ComplexStruct: Codable, Equatable {
16-
let name: String
17-
let count: Int
18-
let flag: Bool
19-
}
20-
21-
private struct NestedStruct: Codable, Equatable {
22-
let inner: SimpleStruct
23-
let number: Int
24-
}
25-
26-
private enum PrimitiveEnum: Codable, Equatable {
27-
case string(String)
28-
case integer(Int)
29-
case boolean(Bool)
30-
case double(Double)
31-
}
32-
33-
private enum StructEnum: Codable, Equatable {
34-
case simple(SimpleStruct)
35-
case complex(ComplexStruct)
36-
case nested(NestedStruct)
37-
}
38-
39-
private enum OptionalStructEnum: Codable, Equatable {
40-
case optionalSimple(SimpleStruct?)
41-
case optionalComplex(ComplexStruct?)
42-
}
43-
44-
private enum OptionalPrimitiveEnum: Codable, Equatable {
45-
case optionalString(String?)
46-
case optionalInt(Int?)
47-
}
48-
49-
private enum MultipleAssociatedEnum: Codable, Equatable {
50-
case primitives(String, Int)
51-
case mixed(String, SimpleStruct)
52-
case structs(SimpleStruct, ComplexStruct)
53-
}
54-
55-
private enum DeeplyNestedEnum: Codable, Equatable {
56-
case nested(NestedStruct)
57-
}
58-
59-
private enum SpecialTypesEnum: Codable, Equatable {
60-
case url(URL)
61-
case uuid(UUID)
62-
case date(Date)
63-
case data(Data)
64-
}
65-
66-
// MARK: - Tests
67-
684
final class EnumAssociatedValueTests: XCTestCase {
695
var doc: Document!
706
var encoder: AutomergeEncoder!
@@ -76,8 +12,32 @@ final class EnumAssociatedValueTests: XCTestCase {
7612
decoder = AutomergeDecoder(doc: doc)
7713
}
7814

15+
// MARK: - Test Data Structures
16+
17+
struct SimpleStruct: Codable, Equatable {
18+
let value: String
19+
}
20+
21+
struct ComplexStruct: Codable, Equatable {
22+
let name: String
23+
let count: Int
24+
let flag: Bool
25+
}
26+
27+
struct NestedStruct: Codable, Equatable {
28+
let inner: SimpleStruct
29+
let number: Int
30+
}
31+
7932
// MARK: - Baseline: Enum with Primitive Associated Values (Should Work)
8033

34+
enum PrimitiveEnum: Codable, Equatable {
35+
case string(String)
36+
case integer(Int)
37+
case boolean(Bool)
38+
case double(Double)
39+
}
40+
8141
func testEnumWithStringAssociatedValue() throws {
8242
struct Wrapper: Codable, Equatable {
8343
let value: PrimitiveEnum
@@ -132,6 +92,12 @@ final class EnumAssociatedValueTests: XCTestCase {
13292

13393
// MARK: - Bug Test: Enum with Struct Associated Value
13494

95+
enum StructEnum: Codable, Equatable {
96+
case simple(SimpleStruct)
97+
case complex(ComplexStruct)
98+
case nested(NestedStruct)
99+
}
100+
135101
func testEnumWithSimpleStructAssociatedValue() throws {
136102
struct Wrapper: Codable, Equatable {
137103
let value: StructEnum
@@ -180,6 +146,11 @@ final class EnumAssociatedValueTests: XCTestCase {
180146

181147
// MARK: - Bug Test: Enum with Optional Struct (Data Loss)
182148

149+
enum OptionalStructEnum: Codable, Equatable {
150+
case optionalSimple(SimpleStruct?)
151+
case optionalComplex(ComplexStruct?)
152+
}
153+
183154
func testEnumWithOptionalStructAssociatedValue_nil() throws {
184155
struct Wrapper: Codable, Equatable {
185156
let value: OptionalStructEnum
@@ -229,6 +200,11 @@ final class EnumAssociatedValueTests: XCTestCase {
229200

230201
// MARK: - Optional Primitive Tests (Should Work)
231202

203+
enum OptionalPrimitiveEnum: Codable, Equatable {
204+
case optionalString(String?)
205+
case optionalInt(Int?)
206+
}
207+
232208
func testEnumWithOptionalPrimitiveAssociatedValue_nil() throws {
233209
struct Wrapper: Codable, Equatable {
234210
let value: OptionalPrimitiveEnum
@@ -257,6 +233,12 @@ final class EnumAssociatedValueTests: XCTestCase {
257233

258234
// MARK: - Multiple Associated Values (Mixed Types)
259235

236+
enum MultipleAssociatedEnum: Codable, Equatable {
237+
case primitives(String, Int)
238+
case mixed(String, SimpleStruct)
239+
case structs(SimpleStruct, ComplexStruct)
240+
}
241+
260242
func testEnumWithMultiplePrimitiveAssociatedValues() throws {
261243
struct Wrapper: Codable, Equatable {
262244
let value: MultipleAssociatedEnum
@@ -301,6 +283,10 @@ final class EnumAssociatedValueTests: XCTestCase {
301283

302284
// MARK: - Deeply Nested Cases
303285

286+
enum DeeplyNestedEnum: Codable, Equatable {
287+
case nested(NestedStruct)
288+
}
289+
304290
func testEnumWithDeeplyNestedStruct() throws {
305291
struct Wrapper: Codable, Equatable {
306292
let value: DeeplyNestedEnum
@@ -338,6 +324,13 @@ final class EnumAssociatedValueTests: XCTestCase {
338324

339325
// MARK: - Edge Case: Enum with Special Types
340326

327+
enum SpecialTypesEnum: Codable, Equatable {
328+
case url(URL)
329+
case uuid(UUID)
330+
case date(Date)
331+
case data(Data)
332+
}
333+
341334
func testEnumWithURLAssociatedValue() throws {
342335
struct Wrapper: Codable, Equatable {
343336
let value: SpecialTypesEnum

0 commit comments

Comments
 (0)