Skip to content

Commit

Permalink
Fix OptionDescriptor.isRenamed logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Aug 28, 2020
1 parent adcb27e commit b9aab40
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Sources/OptionDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -776,7 +781,8 @@ struct _Descriptors {
keyPath: \.useVoid,
trueValues: ["void"],
falseValues: ["tuple", "tuples"]
)
).renamed(to: "useVoid")

let hexLiterals = OptionDescriptor(
argumentName: "hexliterals",
displayName: "hexliterals",
Expand All @@ -785,15 +791,17 @@ struct _Descriptors {
keyPath: \.uppercaseHex,
trueValues: ["uppercase", "upper"],
falseValues: ["lowercase", "lower"]
)
).renamed(to: "uppercaseHex")

let wrapElements = OptionDescriptor(
argumentName: "wrapelements",
displayName: "Wrap Elements",
help: "deprecated",
deprecationMessage: "Use --wrapcollections instead.",
keyPath: \.wrapCollections,
options: ["before-first", "after-first", "preserve", "disabled"]
)
).renamed(to: "wrapCollections")

let specifierOrder = OptionDescriptor(
argumentName: "specifierorder",
displayName: "Specifier Order",
Expand All @@ -805,5 +813,5 @@ struct _Descriptors {
throw FormatError.options("'\($0)' is not a valid specifier")
}
}
)
).renamed(to: "modifierOrder")
}
5 changes: 5 additions & 0 deletions Tests/ArgumentsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions Tests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ extension ArgumentsTests {
("testParseUppercaseIgnoreFileHeader", testParseUppercaseIgnoreFileHeader),
("testPreprocessArguments", testPreprocessArguments),
("testQuotedComment", testQuotedComment),
("testRenamedArgument", testRenamedArgument),
("testRulesArgumentOverridesAllConfigRules", testRulesArgumentOverridesAllConfigRules),
("testSerializeFileHeaderContainingEscapedSpace", testSerializeFileHeaderContainingEscapedSpace),
("testSerializeFileHeaderContainingLinebreak", testSerializeFileHeaderContainingLinebreak),
Expand Down

0 comments on commit b9aab40

Please sign in to comment.