Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/ArgumentParser/Utilities/SwiftExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#if compiler(>=6.2)
/// Designates a type as having a sendable metatype.
public protocol _SendableMetatype: SendableMetatype {}
@_marker public protocol _SendableMetatype: SendableMetatype {}
#else
public protocol _SendableMetatype {}
@_marker public protocol _SendableMetatype {}
#endif
30 changes: 30 additions & 0 deletions Tests/ArgumentParserEndToEndTests/PositionalEndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,33 @@ extension PositionalEndToEndTests {
}
}
}

// MARK: Conditional ExpressibleByArgument conformance

// Note: This retroactive conformance is a compilation test
extension Range<Int>: ArgumentParser.ExpressibleByArgument {
public init?(argument: String) {
guard let i = argument.firstIndex(of: ":"),
let low = Int(String(argument[..<i])),
let high = Int(String(argument[i...].dropFirst())),
low <= high
else { return nil }
self = low..<high
}
}

extension PositionalEndToEndTests {
struct HasRange: ParsableArguments {
@Argument var range: Range<Int>
}

func testParseCustomRangeConformance() throws {
AssertParse(HasRange.self, ["0:4"]) { args in
XCTAssertEqual(args.range, 0..<4)
}

XCTAssertThrowsError(try HasRange.parse([]))
XCTAssertThrowsError(try HasRange.parse(["1"]))
XCTAssertThrowsError(try HasRange.parse(["1:0"]))
}
}
Loading