Files
swift-argument-parser/Tests/ArgumentParserEndToEndTests/RawRepresentableEndToEndTests.swift
Elliott Williams 34300696f5 Prefix test target names with "ArgumentParser" (#74)
* Prefix testing and test helper targets with ArgumentParser

* Replace SAP with ArgumentParser in imports and CMakeLists
2020-03-10 12:44:07 -05:00

49 lines
1.5 KiB
Swift

//===----------------------------------------------------------*- swift -*-===//
//
// This source file is part of the Swift Argument Parser open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
import XCTest
import ArgumentParserTestHelpers
import ArgumentParser
final class RawRepresentableEndToEndTests: XCTestCase {
}
// MARK: -
fileprivate struct Bar: ParsableArguments {
struct Identifier: RawRepresentable, Equatable, ExpressibleByArgument {
var rawValue: Int
}
@Option() var identifier: Identifier
}
extension RawRepresentableEndToEndTests {
func testParsing_SingleOption() throws {
AssertParse(Bar.self, ["--identifier", "123"]) { bar in
XCTAssertEqual(bar.identifier, Bar.Identifier(rawValue: 123))
}
}
func testParsing_SingleOptionMultipleTimes() throws {
AssertParse(Bar.self, ["--identifier", "123", "--identifier", "456"]) { bar in
XCTAssertEqual(bar.identifier, Bar.Identifier(rawValue: 456))
}
}
func testParsing_SingleOption_Fails() throws {
XCTAssertThrowsError(try Bar.parse([]))
XCTAssertThrowsError(try Bar.parse(["--identifier"]))
XCTAssertThrowsError(try Bar.parse(["--identifier", "not a number"]))
XCTAssertThrowsError(try Bar.parse(["--identifier", "123.456"]))
}
}