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 @@ -226,6 +226,33 @@ extension Positional {
226226 }
227227}
228228
229+ // MARK: Convenience initializers when Value: ArgumentGroup
230+
231+ extension Positional where Value: ArgumentGroup {
232+ /// Initializes a new positional when not used as a `@propertyWrapper`
233+ ///
234+ /// - Parameters
235+ /// - wrappedValue: The underlying value
236+ public init ( value: Value ) {
237+ wrappedValue = value
238+ unwrap = Self . unwrap ( _: )
239+ }
240+
241+ /// Initializes a new positional when used as a `@propertyWrapper`
242+ ///
243+ /// - Parameters
244+ /// - wrappedValue: The underlying value
245+ public init ( wrappedValue: Value ) {
246+ self . wrappedValue = wrappedValue
247+ unwrap = Self . unwrap ( _: )
248+ }
249+
250+ @Sendable
251+ public static func unwrap( _ value: Value ) -> [ String ] {
252+ value. arguments ( )
253+ }
254+ }
255+
229256// MARK: ExpressibleBy...Literal conformances
230257
231258extension Positional : ExpressibleByIntegerLiteral where Value: BinaryInteger , Value. IntegerLiteralType == Int {
Original file line number Diff line number Diff line change @@ -28,6 +28,15 @@ final class PositionalTests: XCTestCase {
2828 let args = container. arguments ( )
2929 XCTAssertEqual ( args, [ " positional-argument " ] )
3030 }
31+
32+ func testPositionalArgumentGroup( ) throws {
33+ let positional =
34+ Positional (
35+ value: Container ( configuration: RawValueCustomStringConvertible ( rawValue: " positional-argument " ) )
36+ )
37+ let args = positional. arguments ( )
38+ XCTAssertEqual ( args, [ " positional-argument " ] )
39+ }
3140}
3241
3342private struct RawValueCustomStringConvertible : RawRepresentable , CustomStringConvertible {
You can’t perform that action at this time.
0 commit comments