Skip to content

Commit 201ce15

Browse files
committed
Refactor test organization with nested suites and improve test descriptions
- [x] Reorganize `ConditionalCoderTests`, `DefaultSequenceElementCodingTests`, and `DynamicCodableIdentifierTests` into nested test suites. - [x] Update test descriptions to be more concise and descriptive. - [x] Remove `CHANGELOG` entry about unreachable default case warnings (again 🤦🏻‍♂️). - [x] Simplify multi-line test attribute formatting in `CodableTests`.
1 parent 4b6fe3d commit 201ce15

9 files changed

Lines changed: 475 additions & 451 deletions

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
### 🐛 Fixes
1111

1212
* fixed optional types not detected with `valueCoder` strategy ([#141](https://github.com/SwiftyLab/MetaCodable/issues/141)) ([5873c3e](https://github.com/SwiftyLab/MetaCodable/commit/5873c3e33ab98e61c06304bfc2a2c93ab199d65d))
13-
* removed unreachable `default` case warnings for `Bool` type switches in macro-generated code
1413

1514
## [1.5.0](https://github.com/SwiftyLab/MetaCodable/compare/v1.4.0...v1.5.0) (2025-07-08)
1615

Tests/MetaCodableTests/CodableTests.swift

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,7 @@ struct CodableTests {
3030
}
3131
}
3232

33-
@Test(
34-
"Reports error for @Codable misuse (CodableTests #1)",
35-
.tags(
36-
.codable,
37-
.decoding,
38-
.encoding,
39-
.enums,
40-
.errorHandling,
41-
.macroExpansion,
42-
.structs
43-
)
44-
)
33+
@Test("Reports error for @Codable misuse (CodableTests #1)", .tags(.codable, .decoding, .encoding, .enums, .errorHandling, .macroExpansion, .structs))
4534
func expansion() throws {
4635
assertMacroExpansion(
4736
"""

Tests/MetaCodableTests/ConditionalCoderTests.swift

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Testing
1010
@Suite("Conditional Coder Tests")
1111
struct ConditionalCoderTests {
1212

13+
// MARK: Prefix & Suffix
14+
1315
/// A decoder-only coder that prefixes decoded strings.
1416
struct PrefixDecoder: HelperCoder {
1517
let prefix: String
@@ -36,6 +38,8 @@ struct ConditionalCoderTests {
3638
}
3739
}
3840

41+
// MARK: Wrappers
42+
3943
/// Wrapper for decoding tests.
4044
struct DecodingWrapper: Decodable {
4145
let value: String?
@@ -76,57 +80,64 @@ struct ConditionalCoderTests {
7680
}
7781
}
7882

79-
// MARK: - decodeIfPresent Tests
80-
81-
/// Tests that `decodeIfPresent` uses the decoder coder and returns value.
82-
@Test("Decodes from JSON successfully (ConditionalCoderTests #34)", .tags(.conditionalCoder, .decoding))
83-
func decodeIfPresentReturnsValue() throws {
84-
let json = #"{"value": "test"}"#
85-
let data = json.data(using: .utf8)!
86-
87-
let result = try JSONDecoder().decode(DecodingWrapper.self, from: data)
88-
#expect(result.value == "decoded:test")
89-
}
83+
// MARK: Decode if present
9084

91-
/// Tests that `decodeIfPresent` returns nil when value is null.
92-
@Test("Decodes from JSON successfully (ConditionalCoderTests #35)", .tags(.conditionalCoder, .decoding))
93-
func decodeIfPresentReturnsNilForNull() throws {
94-
let json = #"{"value": null}"#
95-
let data = json.data(using: .utf8)!
85+
@Suite("Coder Tests → Decode if Present")
86+
struct DecodeIfPresentCoderTests {
87+
/// Tests that `decodeIfPresent` uses the decoder coder and returns value.
88+
@Test("Decodes from JSON successfully (ConditionalCoderTests #34)", .tags(.conditionalCoder, .decoding))
89+
func decodeIfPresentReturnsValue() throws {
90+
let json = #"{"value": "test"}"#
91+
let data = json.data(using: .utf8)!
92+
93+
let result = try JSONDecoder().decode(DecodingWrapper.self, from: data)
94+
#expect(result.value == "decoded:test")
95+
}
9696

97-
let result = try JSONDecoder().decode(DecodingWrapper.self, from: data)
98-
#expect(result.value == nil)
99-
}
100-
101-
/// Tests that `decodeIfPresent` returns nil when key is missing.
102-
@Test("Decodes from JSON successfully (ConditionalCoderTests #36)", .tags(.conditionalCoder, .decoding))
103-
func decodeIfPresentReturnsNilForMissingKey() throws {
104-
let json = #"{}"#
105-
let data = json.data(using: .utf8)!
97+
/// Tests that `decodeIfPresent` returns nil when value is null.
98+
@Test("Decodes from JSON successfully (ConditionalCoderTests #35)", .tags(.conditionalCoder, .decoding))
99+
func decodeIfPresentReturnsNilForNull() throws {
100+
let json = #"{"value": null}"#
101+
let data = json.data(using: .utf8)!
102+
103+
let result = try JSONDecoder().decode(DecodingWrapper.self, from: data)
104+
#expect(result.value == nil)
105+
}
106106

107-
let result = try JSONDecoder().decode(DecodingWrapper.self, from: data)
108-
#expect(result.value == nil)
107+
/// Tests that `decodeIfPresent` returns nil when key is missing.
108+
@Test("Decodes from JSON successfully (ConditionalCoderTests #36)", .tags(.conditionalCoder, .decoding))
109+
func decodeIfPresentReturnsNilForMissingKey() throws {
110+
let json = #"{}"#
111+
let data = json.data(using: .utf8)!
112+
113+
let result = try JSONDecoder().decode(DecodingWrapper.self, from: data)
114+
#expect(result.value == nil)
115+
}
109116
}
110117

111-
// MARK: - encodeIfPresent Tests
118+
// MARK: Encode if present
112119

113-
/// Tests that `encodeIfPresent` uses the encoder coder when value is present.
114-
@Test("Encodes to JSON successfully (ConditionalCoderTests #7)", .tags(.conditionalCoder, .encoding))
115-
func encodeIfPresentEncodesValue() throws {
116-
let wrapper = EncodingWrapper(value: "test")
117-
let data = try JSONEncoder().encode(wrapper)
118-
let json = String(data: data, encoding: .utf8)!
119-
120-
#expect(json.contains("test:encoded"))
121-
}
122-
123-
/// Tests that `encodeIfPresent` skips encoding when value is nil.
124-
@Test("Encodes to JSON successfully (ConditionalCoderTests #8)", .tags(.conditionalCoder, .encoding))
125-
func encodeIfPresentSkipsNil() throws {
126-
let wrapper = EncodingWrapper(value: nil)
127-
let data = try JSONEncoder().encode(wrapper)
128-
let json = String(data: data, encoding: .utf8)!
120+
@Suite("Coder Tests → Encode if Present")
121+
struct EncodeIfPresentCoderTests {
122+
/// Tests that `encodeIfPresent` uses the encoder coder
123+
/// when value is present.
124+
@Test("Encodes to JSON successfully (ConditionalCoderTests #7)", .tags(.conditionalCoder, .encoding))
125+
func encodeIfPresentEncodesValue() throws {
126+
let wrapper = EncodingWrapper(value: "test")
127+
let data = try JSONEncoder().encode(wrapper)
128+
let json = String(data: data, encoding: .utf8)!
129+
130+
#expect(json.contains("test:encoded"))
131+
}
129132

130-
#expect(json == "{}")
133+
/// Tests that `encodeIfPresent` skips encoding when value is nil.
134+
@Test("Encodes to JSON successfully (ConditionalCoderTests #8)", .tags(.conditionalCoder, .encoding))
135+
func encodeIfPresentSkipsNil() throws {
136+
let wrapper = EncodingWrapper(value: nil)
137+
let data = try JSONEncoder().encode(wrapper)
138+
let json = String(data: data, encoding: .utf8)!
139+
140+
#expect(json == "{}")
141+
}
131142
}
132143
}

0 commit comments

Comments
 (0)