@@ -42,8 +42,21 @@ final class SwiftDriverTests: XCTestCase {
42
42
let three = Option ( " -three " , . multiArg, attributes: [ ] , numArgs: 3 )
43
43
options. addNewOption ( two)
44
44
options. addNewOption ( three)
45
- let results = try options. parse ( [ " -two " , " 1 " , " 2 " , " -three " , " 1 " , " 2 " , " 3 " , " -two " , " 2 " , " 3 " ] , for: . batch)
45
+ var results = try options. parse ( [ " -two " , " 1 " , " 2 " , " -three " , " 1 " , " 2 " , " 3 " , " -two " , " 2 " , " 3 " ] , for: . batch)
46
46
XCTAssertEqual ( results. description, " -two 1 2 -three 1 2 3 -two 2 3 " )
47
+ // test that the arguments are assigned to their corresponding flag correctly
48
+ XCTAssertEqual ( results. allInputs. count, 0 )
49
+ let twoOpts = results. arguments ( for: two)
50
+ XCTAssertEqual ( twoOpts. count, 2 )
51
+ XCTAssertEqual ( twoOpts [ 0 ] . argument. asMultiple [ 0 ] , " 1 " )
52
+ XCTAssertEqual ( twoOpts [ 0 ] . argument. asMultiple [ 1 ] , " 2 " )
53
+ XCTAssertEqual ( twoOpts [ 1 ] . argument. asMultiple [ 0 ] , " 2 " )
54
+ XCTAssertEqual ( twoOpts [ 1 ] . argument. asMultiple [ 1 ] , " 3 " )
55
+ let threeOpts = results. arguments ( for: three)
56
+ XCTAssertEqual ( threeOpts. count, 1 )
57
+ XCTAssertEqual ( threeOpts [ 0 ] . argument. asMultiple [ 0 ] , " 1 " )
58
+ XCTAssertEqual ( threeOpts [ 0 ] . argument. asMultiple [ 1 ] , " 2 " )
59
+ XCTAssertEqual ( threeOpts [ 0 ] . argument. asMultiple [ 2 ] , " 3 " )
47
60
// Check not enough arguments are passed.
48
61
XCTAssertThrowsError ( try options. parse ( [ " -two " , " 1 " ] , for: . batch) ) { error in
49
62
XCTAssertEqual ( error as? OptionParseError , . missingArgument( index: 0 , argument: " -two " ) )
0 commit comments