Skip to content

Commit f49ac81

Browse files
committed
add new tests so this bug can't slip in again
1 parent 29e04f0 commit f49ac81

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Tests/MetaCodableTests/IgnoreInitializedTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Foundation
12
import MetaCodable
23
import Testing
34

@@ -124,6 +125,17 @@ struct IgnoreInitializedTests {
124125
case multi(_ variable: Bool, val: Int, String = "text")
125126
}
126127

128+
@Test func coding() async throws {
129+
let encoded = try JSONEncoder().encode(SomeEnum.bool(false))
130+
let expected = try JSONSerialization.data(withJSONObject: ["bool": [:]])
131+
#expect(encoded == expected)
132+
let decoded = try JSONDecoder().decode(SomeEnum.self, from: encoded)
133+
switch decoded {
134+
case SomeEnum.bool(true): break
135+
default: Issue.record("Incorrect default value")
136+
}
137+
}
138+
127139
@Test
128140
func expansion() throws {
129141
assertMacroExpansion(
@@ -234,6 +246,17 @@ struct IgnoreInitializedTests {
234246
case multi(_ variable: Bool, val: Int, String = "text")
235247
}
236248

249+
@Test func coding() async throws {
250+
let encoded = try JSONEncoder().encode(SomeEnum.int(val: 0))
251+
let expected = try JSONSerialization.data(withJSONObject: ["altInt": [:]])
252+
#expect(encoded == expected)
253+
let decoded = try JSONDecoder().decode(SomeEnum.self, from: encoded)
254+
switch decoded {
255+
case SomeEnum.int(6): break
256+
default: Issue.record("Incorrect default value")
257+
}
258+
}
259+
237260
@Test
238261
func expansion() throws {
239262
assertMacroExpansion(

0 commit comments

Comments
 (0)