Skip to content

Commit fa89499

Browse files
committed
test multiArg option parsing
1 parent 5a2c063 commit fa89499

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Tests/SwiftOptionsTests/OptionParsingTests.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,21 @@ final class SwiftDriverTests: XCTestCase {
4242
let three = Option("-three", .multiArg, attributes: [], numArgs: 3)
4343
options.addNewOption(two)
4444
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)
4646
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")
4760
// Check not enough arguments are passed.
4861
XCTAssertThrowsError(try options.parse(["-two", "1"], for: .batch)) { error in
4962
XCTAssertEqual(error as? OptionParseError, .missingArgument(index: 0, argument: "-two"))

0 commit comments

Comments
 (0)