|
| 1 | +//===----------------------------------------------------------*- swift -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift Argument Parser open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// |
| 10 | +//===----------------------------------------------------------------------===// |
| 11 | + |
| 12 | +import XCTest |
| 13 | +import ArgumentParserTestHelpers |
| 14 | +import ArgumentParser |
| 15 | + |
| 16 | +final class EqualsEndToEndTests: XCTestCase { |
| 17 | +} |
| 18 | + |
| 19 | +// MARK: .short name |
| 20 | + |
| 21 | +fileprivate struct Foo: ParsableArguments { |
| 22 | + @Flag(name: .short) var toggle: Bool |
| 23 | + @Option(name: .short) var name: String? |
| 24 | + @Option(name: .short) var format: String |
| 25 | +} |
| 26 | + |
| 27 | +extension EqualsEndToEndTests { |
| 28 | + func testEquals_withShortName() throws { |
| 29 | + AssertParse(Foo.self, ["-n=Name", "-f=Format"]) { foo in |
| 30 | + XCTAssertEqual(foo.toggle, false) |
| 31 | + XCTAssertEqual(foo.name, "Name") |
| 32 | + XCTAssertEqual(foo.format, "Format") |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + func testEquals_withCombinedShortName_1() throws { |
| 37 | + AssertParse(Foo.self, ["-tf", "Format"]) { foo in |
| 38 | + XCTAssertEqual(foo.toggle, true) |
| 39 | + XCTAssertEqual(foo.name, nil) |
| 40 | + XCTAssertEqual(foo.format, "Format") |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + func testEquals_withCombinedShortName_2() throws { |
| 45 | + XCTAssertThrowsError(try Foo.parse(["-tf=Format"])) |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +// MARK: .shortAndLong name |
| 50 | + |
| 51 | +fileprivate struct Bar: ParsableArguments { |
| 52 | + @Option(name: .shortAndLong) var name: String |
| 53 | + @Option(name: .shortAndLong) var format: String |
| 54 | +} |
| 55 | + |
| 56 | +extension EqualsEndToEndTests { |
| 57 | + func testEquals_withShortAndLongName() throws { |
| 58 | + AssertParse(Bar.self, ["-n=Name", "-f=Format"]) { bar in |
| 59 | + XCTAssertEqual(bar.name, "Name") |
| 60 | + XCTAssertEqual(bar.format, "Format") |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +// MARK: .customShort name |
| 66 | + |
| 67 | +fileprivate struct Baz: ParsableArguments { |
| 68 | + @Option(name: .customShort("i")) var name: String |
| 69 | + @Option(name: .customShort("t")) var format: String |
| 70 | +} |
| 71 | + |
| 72 | +extension EqualsEndToEndTests { |
| 73 | + func testEquals_withCustomShortName() throws { |
| 74 | + AssertParse(Baz.self, ["-i=Name", "-t=Format"]) { baz in |
| 75 | + XCTAssertEqual(baz.name, "Name") |
| 76 | + XCTAssertEqual(baz.format, "Format") |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments