File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
Sources/ArgumentParser/Utilities
Tests/ArgumentParserEndToEndTests Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 11
11
12
12
#if compiler(>=6.2)
13
13
/// Designates a type as having a sendable metatype.
14
- public protocol _SendableMetatype : SendableMetatype { }
14
+ @ _marker public protocol _SendableMetatype : SendableMetatype { }
15
15
#else
16
- public protocol _SendableMetatype { }
16
+ @ _marker public protocol _SendableMetatype { }
17
17
#endif
Original file line number Diff line number Diff line change @@ -241,3 +241,33 @@ extension PositionalEndToEndTests {
241
241
}
242
242
}
243
243
}
244
+
245
+ // MARK: Conditional ExpressibleByArgument conformance
246
+
247
+ // Note: This retroactive conformance is a compilation test
248
+ extension Range < Int > : ArgumentParser . ExpressibleByArgument {
249
+ public init ? ( argument: String ) {
250
+ guard let i = argument. firstIndex ( of: " : " ) ,
251
+ let low = Int ( String ( argument [ ..< i] ) ) ,
252
+ let high = Int ( String ( argument [ i... ] . dropFirst ( ) ) ) ,
253
+ low <= high
254
+ else { return nil }
255
+ self = low..< high
256
+ }
257
+ }
258
+
259
+ extension PositionalEndToEndTests {
260
+ struct HasRange : ParsableArguments {
261
+ @Argument var range : Range < Int >
262
+ }
263
+
264
+ func testParseCustomRangeConformance( ) throws {
265
+ AssertParse ( HasRange . self, [ " 0:4 " ] ) { args in
266
+ XCTAssertEqual ( args. range, 0 ..< 4 )
267
+ }
268
+
269
+ XCTAssertThrowsError ( try HasRange . parse ( [ ] ) )
270
+ XCTAssertThrowsError ( try HasRange . parse ( [ " 1 " ] ) )
271
+ XCTAssertThrowsError ( try HasRange . parse ( [ " 1:0 " ] ) )
272
+ }
273
+ }
You can’t perform that action at this time.
0 commit comments