File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Tests/ArgumentEncodingTests Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,33 @@ extension Positional {
224224 }
225225}
226226
227+ // MARK: Convenience initializers when Value: ArgumentGroup
228+
229+ extension Positional where Value: ArgumentGroup {
230+ /// Initializes a new positional when not used as a `@propertyWrapper`
231+ ///
232+ /// - Parameters
233+ /// - wrappedValue: The underlying value
234+ public init ( value: Value ) {
235+ wrappedValue = value
236+ unwrap = Self . unwrap ( _: )
237+ }
238+
239+ /// Initializes a new positional when used as a `@propertyWrapper`
240+ ///
241+ /// - Parameters
242+ /// - wrappedValue: The underlying value
243+ public init ( wrappedValue: Value ) {
244+ self . wrappedValue = wrappedValue
245+ unwrap = Self . unwrap ( _: )
246+ }
247+
248+ @Sendable
249+ public static func unwrap( _ value: Value ) -> [ String ] {
250+ value. arguments ( )
251+ }
252+ }
253+
227254// MARK: ExpressibleBy...Literal conformances
228255
229256extension Positional : ExpressibleByIntegerLiteral where Value: BinaryInteger , Value. IntegerLiteralType == Int {
Original file line number Diff line number Diff line change @@ -26,6 +26,15 @@ final class PositionalTests: XCTestCase {
2626 let args = container. arguments ( )
2727 XCTAssertEqual ( args, [ " positional-argument " ] )
2828 }
29+
30+ func testPositionalArgumentGroup( ) throws {
31+ let positional =
32+ Positional (
33+ value: Container ( configuration: RawValueCustomStringConvertible ( rawValue: " positional-argument " ) )
34+ )
35+ let args = positional. arguments ( )
36+ XCTAssertEqual ( args, [ " positional-argument " ] )
37+ }
2938}
3039
3140private struct RawValueCustomStringConvertible : RawRepresentable , CustomStringConvertible {
You can’t perform that action at this time.
0 commit comments