Skip to content

Commit 4d953e9

Browse files
committed
Add test cases to OptionTests to catch regressions of behavior when Option.Value conforms to both RawRepresentable<CustomStringConvertible> and CustomStringConvertible
feature/improve-option-decodable-conformance
1 parent 991c2b6 commit 4d953e9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Tests/ArgumentEncodingTests/OptionTests.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,40 @@ final class OptionTests: XCTestCase {
1717
}
1818
XCTAssertEqual(args, ["--configuration", "release"])
1919
}
20+
21+
func testBothRawValueAndStringConvertible() throws {
22+
let option = Option(key: "configuration", value: RawValueCustomStringConvertible(rawValue: "release"))
23+
let args = withDependencies { values in
24+
values.optionFormatter = .doubleDashPrefix
25+
} operation: {
26+
option.arguments()
27+
}
28+
XCTAssertEqual(args, ["--configuration", "release"])
29+
}
30+
31+
func testBothRawValueAndStringConvertibleContainer() throws {
32+
let container = Container(configuration: RawValueCustomStringConvertible(rawValue: "release"))
33+
let args = withDependencies { values in
34+
values.optionFormatter = .doubleDashPrefix
35+
} operation: {
36+
container.arguments()
37+
}
38+
XCTAssertEqual(args, ["--configuration", "release"])
39+
}
40+
}
41+
42+
private struct RawValueCustomStringConvertible: RawRepresentable, CustomStringConvertible {
43+
var rawValue: String
44+
45+
var description: String {
46+
"description=" + rawValue
47+
}
48+
}
49+
50+
private struct Container: ArgumentGroup {
51+
@Option var configuration: RawValueCustomStringConvertible
52+
53+
init(configuration: RawValueCustomStringConvertible) {
54+
_configuration = Option(wrappedValue: configuration)
55+
}
2056
}

0 commit comments

Comments
 (0)