From b9aab406621377ca3681f7fccea6c0c0b96772ed Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Fri, 28 Aug 2020 14:16:47 +0100 Subject: [PATCH] Fix OptionDescriptor.isRenamed logic --- Sources/OptionDescriptor.swift | 16 ++++++++++++---- Tests/ArgumentsTests.swift | 5 +++++ Tests/XCTestManifests.swift | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Sources/OptionDescriptor.swift b/Sources/OptionDescriptor.swift index 99bec6e37..29cf59889 100644 --- a/Sources/OptionDescriptor.swift +++ b/Sources/OptionDescriptor.swift @@ -70,6 +70,11 @@ class OptionDescriptor { return (try? toOptions(arg, &options)) != nil } + fileprivate func renamed(to newPropertyName: String) -> OptionDescriptor { + propertyName = newPropertyName + return self + } + var isSetType: Bool { guard case .set = type else { return false @@ -776,7 +781,8 @@ struct _Descriptors { keyPath: \.useVoid, trueValues: ["void"], falseValues: ["tuple", "tuples"] - ) + ).renamed(to: "useVoid") + let hexLiterals = OptionDescriptor( argumentName: "hexliterals", displayName: "hexliterals", @@ -785,7 +791,8 @@ struct _Descriptors { keyPath: \.uppercaseHex, trueValues: ["uppercase", "upper"], falseValues: ["lowercase", "lower"] - ) + ).renamed(to: "uppercaseHex") + let wrapElements = OptionDescriptor( argumentName: "wrapelements", displayName: "Wrap Elements", @@ -793,7 +800,8 @@ struct _Descriptors { deprecationMessage: "Use --wrapcollections instead.", keyPath: \.wrapCollections, options: ["before-first", "after-first", "preserve", "disabled"] - ) + ).renamed(to: "wrapCollections") + let specifierOrder = OptionDescriptor( argumentName: "specifierorder", displayName: "Specifier Order", @@ -805,5 +813,5 @@ struct _Descriptors { throw FormatError.options("'\($0)' is not a valid specifier") } } - ) + ).renamed(to: "modifierOrder") } diff --git a/Tests/ArgumentsTests.swift b/Tests/ArgumentsTests.swift index 137a7a2d9..334c0199c 100644 --- a/Tests/ArgumentsTests.swift +++ b/Tests/ArgumentsTests.swift @@ -276,6 +276,11 @@ class ArgumentsTests: XCTestCase { XCTAssertEqual(args["header"], "// Hello World\\n// Goodbye World") } + // TODO: should this go in OptionDescriptorTests instead? + func testRenamedArgument() throws { + XCTAssert(Descriptors.specifierOrder.isRenamed) + } + // MARK: config file parsing func testParseArgumentsContainingBlankLines() { diff --git a/Tests/XCTestManifests.swift b/Tests/XCTestManifests.swift index 0e5919367..275979c09 100644 --- a/Tests/XCTestManifests.swift +++ b/Tests/XCTestManifests.swift @@ -71,6 +71,7 @@ extension ArgumentsTests { ("testParseUppercaseIgnoreFileHeader", testParseUppercaseIgnoreFileHeader), ("testPreprocessArguments", testPreprocessArguments), ("testQuotedComment", testQuotedComment), + ("testRenamedArgument", testRenamedArgument), ("testRulesArgumentOverridesAllConfigRules", testRulesArgumentOverridesAllConfigRules), ("testSerializeFileHeaderContainingEscapedSpace", testSerializeFileHeaderContainingEscapedSpace), ("testSerializeFileHeaderContainingLinebreak", testSerializeFileHeaderContainingLinebreak),