Remove low-value options descriptor tests

This commit is contained in:
Nick Lockwood
2020-07-29 18:19:17 +01:00
parent 34e06b2b7f
commit ab7ee2cbd4
2 changed files with 0 additions and 549 deletions
-516
View File
@@ -12,16 +12,6 @@ import XCTest
class OptionsDescriptorTests: XCTestCase {
private typealias OptionArgumentMapping<T> = (optionValue: T, argumentValue: String)
private func validateDescriptor(_ descriptor: FormatOptions.Descriptor,
displayName: String,
argumentName: String,
propertyName: String,
testName: String = #function) {
XCTAssertEqual(descriptor.displayName, displayName, "\(testName) : Name is -> \(displayName)")
XCTAssertEqual(descriptor.argumentName, argumentName, "\(testName) : argumentName is -> \(argumentName)")
XCTAssertEqual(descriptor.propertyName, propertyName, "\(testName) : propertyName is -> \(propertyName)")
}
private func validateDescriptorThrowsOptionsError(_ descriptor: FormatOptions.Descriptor,
invalidArguments: String = "invalid",
testName: String = #function) {
@@ -105,36 +95,6 @@ class OptionsDescriptorTests: XCTestCase {
}
}
private func validateArgumentsBinaryType(_ descriptor: FormatOptions.Descriptor,
controlTrue: [String],
controlFalse: [String],
testName: String = #function) {
let values: (true: [String], false: [String]) = descriptor.type.associatedValue()
XCTAssertEqual(values.true[0], controlTrue[0], "\(testName): First item is prefered parameter name")
XCTAssertEqual(values.false[0], controlFalse[0], "\(testName): First item is prefered parameter name")
XCTAssertEqual(Set(values.true), Set(controlTrue), "\(testName): All possible true value have representation")
XCTAssertEqual(Set(values.false), Set(controlFalse), "\(testName): All possible false value have representation")
}
private func validateFromArgumentsBinaryType(_ descriptor: FormatOptions.Descriptor,
keyPath: WritableKeyPath<FormatOptions, Bool>,
testName: String = #function) {
let values: (true: [String], false: [String]) = descriptor.type.associatedValue()
let mappings: [OptionArgumentMapping<Bool>] =
values.true.map { (optionValue: true, argumentValue: $0) } + values.false.map { (optionValue: false, argumentValue: $0) }
validateFromArguments(descriptor, keyPath: keyPath, expectations: mappings, testName: testName)
}
private func validateArgumentsListType(_ descriptor: FormatOptions.Descriptor,
validArguments: Set<String>,
testName: String = #function) {
let values: [String] = descriptor.type.associatedValue()
XCTAssertEqual(Set(values), validArguments, "\(testName): All valid arguments are accounted for")
XCTAssertTrue(validArguments.contains(descriptor.defaultArgument), "\(testName): Default argument is part of the valid arguments")
}
private typealias FreeTextValidationExpectation = (input: String, isValid: Bool)
private func validateArgumentsFreeTextType(_ descriptor: FormatOptions.Descriptor,
@@ -146,41 +106,6 @@ class OptionsDescriptorTests: XCTestCase {
}
}
private func validateGroupingDescriptor(_ descriptor: FormatOptions.Descriptor,
displayName: String,
argumentName: String,
propertyName: String,
keyPath: WritableKeyPath<FormatOptions, Grouping>,
testName: String = #function) {
let expectations: [FreeTextValidationExpectation] = [
(input: "3,4", isValid: true),
(input: " 3 , 5 ", isValid: true),
(input: "ignore", isValid: true),
(input: "none", isValid: true),
(input: "4", isValid: true),
(input: "foo", isValid: false),
(input: "4,5 6 7", isValid: false),
(input: "", isValid: false),
(input: " ", isValid: false),
]
let fromOptionExpectations: [OptionArgumentMapping<Grouping>] = [
(optionValue: Grouping.ignore, argumentValue: "ignore"),
(optionValue: Grouping.none, argumentValue: "none"),
(optionValue: Grouping.group(4, 5), argumentValue: "4,5"),
]
let fromArgumentExpectations: [OptionArgumentMapping<Grouping>] = [
(optionValue: Grouping.ignore, argumentValue: "ignore"),
(optionValue: Grouping.none, argumentValue: "none"),
(optionValue: Grouping.group(4, 5), argumentValue: "4,5"),
]
validateDescriptor(descriptor, displayName: displayName, argumentName: argumentName, propertyName: propertyName, testName: testName)
validateArgumentsFreeTextType(descriptor, expectations: expectations, testName: testName)
validateFromOptions(descriptor, keyPath: keyPath, expectations: fromOptionExpectations, testName: testName)
validateFromArguments(descriptor, keyPath: keyPath, expectations: fromArgumentExpectations, testName: testName)
validateDescriptorThrowsOptionsError(descriptor, testName: testName)
}
// MARK: All options
func testAllDescriptorsHaveProperty() {
@@ -197,361 +122,6 @@ class OptionsDescriptorTests: XCTestCase {
}
}
// MARK: Individual options
func testUseVoid() {
let descriptor = FormatOptions.Descriptor.useVoid
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: false, argumentValue: "tuple"),
(optionValue: true, argumentValue: "void"),
]
validateDescriptor(descriptor, displayName: "Void Type", argumentName: "voidtype", propertyName: "useVoid")
validateArgumentsBinaryType(descriptor, controlTrue: ["void"], controlFalse: ["tuple", "tuples", "()"])
validateFromOptions(descriptor, keyPath: \FormatOptions.useVoid, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.useVoid)
validateDescriptorThrowsOptionsError(descriptor)
}
func testAllowInlineSemicolons() {
let descriptor = FormatOptions.Descriptor.allowInlineSemicolons
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: false, argumentValue: "never"),
(optionValue: true, argumentValue: "inline"),
]
validateDescriptor(descriptor, displayName: "Semicolons", argumentName: "semicolons", propertyName: "allowInlineSemicolons")
validateArgumentsBinaryType(descriptor, controlTrue: ["inline"], controlFalse: ["never", "false"])
validateFromOptions(descriptor, keyPath: \FormatOptions.allowInlineSemicolons, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.allowInlineSemicolons)
validateDescriptorThrowsOptionsError(descriptor)
}
func testSpaceAroundRangeOperators() {
let descriptor = FormatOptions.Descriptor.spaceAroundRangeOperators
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "spaced"),
(optionValue: false, argumentValue: "no-space"),
]
validateDescriptor(descriptor, displayName: "Ranges", argumentName: "ranges", propertyName: "spaceAroundRangeOperators")
validateArgumentsBinaryType(descriptor, controlTrue: ["spaced", "space", "spaces"], controlFalse: ["no-space", "nospace"])
validateFromOptions(descriptor, keyPath: \FormatOptions.spaceAroundRangeOperators, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.spaceAroundRangeOperators)
validateDescriptorThrowsOptionsError(descriptor)
}
func testSpaceAroundOperatorDeclarations() {
let descriptor = FormatOptions.Descriptor.spaceAroundOperatorDeclarations
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "spaced"),
(optionValue: false, argumentValue: "no-space"),
]
validateDescriptor(descriptor, displayName: "Operator Functions", argumentName: "operatorfunc", propertyName: "spaceAroundOperatorDeclarations")
validateArgumentsBinaryType(descriptor, controlTrue: ["spaced", "space", "spaces"], controlFalse: ["no-space", "nospace"])
validateFromOptions(descriptor, keyPath: \FormatOptions.spaceAroundOperatorDeclarations, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.spaceAroundOperatorDeclarations)
validateDescriptorThrowsOptionsError(descriptor)
}
func testIndentCase() {
let descriptor = FormatOptions.Descriptor.indentCase
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "true"),
(optionValue: false, argumentValue: "false"),
]
validateDescriptor(descriptor, displayName: "Indent Case", argumentName: "indentcase", propertyName: "indentCase")
validateArgumentsBinaryType(descriptor, controlTrue: ["true"], controlFalse: ["false"])
validateFromOptions(descriptor, keyPath: \FormatOptions.indentCase, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.indentCase)
validateDescriptorThrowsOptionsError(descriptor)
}
func testTrailingCommas() {
let descriptor = FormatOptions.Descriptor.trailingCommas
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "always"),
(optionValue: false, argumentValue: "inline"),
]
validateDescriptor(descriptor, displayName: "Commas", argumentName: "commas", propertyName: "trailingCommas")
validateArgumentsBinaryType(descriptor, controlTrue: ["always", "true"], controlFalse: ["inline", "false"])
validateFromOptions(descriptor, keyPath: \FormatOptions.trailingCommas, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.trailingCommas)
validateDescriptorThrowsOptionsError(descriptor)
}
func testIndentComments() {
let descriptor = FormatOptions.Descriptor.indentComments
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "indent"),
(optionValue: false, argumentValue: "ignore"),
]
validateDescriptor(descriptor, displayName: "Comments", argumentName: "comments", propertyName: "indentComments")
validateArgumentsBinaryType(descriptor, controlTrue: ["indent", "indented"], controlFalse: ["ignore"])
validateFromOptions(descriptor, keyPath: \FormatOptions.indentComments, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.indentComments)
validateDescriptorThrowsOptionsError(descriptor)
}
func testTruncateBlankLines() {
let descriptor = FormatOptions.Descriptor.truncateBlankLines
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "always"),
(optionValue: false, argumentValue: "nonblank-lines"),
]
validateDescriptor(descriptor, displayName: "Trim White Space", argumentName: "trimwhitespace", propertyName: "truncateBlankLines")
validateArgumentsBinaryType(descriptor, controlTrue: ["always"], controlFalse: ["nonblank-lines", "nonblank", "non-blank-lines", "non-blank", "nonempty-lines", "nonempty", "non-empty-lines", "non-empty"])
validateFromOptions(descriptor, keyPath: \FormatOptions.truncateBlankLines, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.truncateBlankLines)
validateDescriptorThrowsOptionsError(descriptor)
}
func testAllmanBraces() {
let descriptor = FormatOptions.Descriptor.allmanBraces
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "true"),
(optionValue: false, argumentValue: "false"),
]
validateDescriptor(descriptor, displayName: "Allman Braces", argumentName: "allman", propertyName: "allmanBraces")
validateArgumentsBinaryType(descriptor, controlTrue: ["true", "enabled"], controlFalse: ["false", "disabled"])
validateFromOptions(descriptor, keyPath: \FormatOptions.allmanBraces, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.allmanBraces)
validateDescriptorThrowsOptionsError(descriptor)
}
func testHexLiteralCase() {
let descriptor = FormatOptions.Descriptor.hexLiteralCase
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "uppercase"),
(optionValue: false, argumentValue: "lowercase"),
]
validateDescriptor(descriptor, displayName: "Hex Literal Case", argumentName: "hexliteralcase", propertyName: "uppercaseHex")
validateArgumentsBinaryType(descriptor, controlTrue: ["uppercase", "upper"], controlFalse: ["lowercase", "lower"])
validateFromOptions(descriptor, keyPath: \FormatOptions.uppercaseHex, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.uppercaseHex)
validateDescriptorThrowsOptionsError(descriptor)
}
func testExponentCase() {
let descriptor = FormatOptions.Descriptor.exponentCase
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "uppercase"),
(optionValue: false, argumentValue: "lowercase"),
]
validateDescriptor(descriptor, displayName: "Exponent Case", argumentName: "exponentcase", propertyName: "uppercaseExponent")
validateArgumentsBinaryType(descriptor, controlTrue: ["uppercase", "upper"], controlFalse: ["lowercase", "lower"])
validateFromOptions(descriptor, keyPath: \FormatOptions.uppercaseExponent, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.uppercaseExponent)
validateDescriptorThrowsOptionsError(descriptor)
}
func testLetPatternPlacement() {
let descriptor = FormatOptions.Descriptor.letPatternPlacement
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "hoist"),
(optionValue: false, argumentValue: "inline"),
]
validateDescriptor(descriptor, displayName: "Pattern Let", argumentName: "patternlet", propertyName: "hoistPatternLet")
validateArgumentsBinaryType(descriptor, controlTrue: ["hoist"], controlFalse: ["inline"])
validateFromOptions(descriptor, keyPath: \FormatOptions.hoistPatternLet, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.hoistPatternLet)
validateDescriptorThrowsOptionsError(descriptor)
}
func testElsePosition() {
let descriptor = FormatOptions.Descriptor.elsePosition
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "next-line"),
(optionValue: false, argumentValue: "same-line"),
]
validateDescriptor(descriptor, displayName: "Else Position", argumentName: "elseposition", propertyName: "elseOnNextLine")
validateArgumentsBinaryType(descriptor, controlTrue: ["next-line", "nextline"], controlFalse: ["same-line", "sameline"])
validateFromOptions(descriptor, keyPath: \FormatOptions.elseOnNextLine, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.elseOnNextLine)
validateDescriptorThrowsOptionsError(descriptor)
}
func testExplicitSelf() {
let descriptor = FormatOptions.Descriptor.explicitSelf
let expectedMapping: [OptionArgumentMapping<SelfMode>] = [
(optionValue: .remove, argumentValue: "remove"),
(optionValue: .insert, argumentValue: "insert"),
(optionValue: .initOnly, argumentValue: "init-only"),
]
validateDescriptor(descriptor, displayName: "Self", argumentName: "self", propertyName: "explicitSelf")
validateArgumentsListType(descriptor, validArguments: ["remove", "insert", "init-only"])
validateFromOptions(descriptor, keyPath: \FormatOptions.explicitSelf, expectations: expectedMapping)
validateFromArguments(descriptor, keyPath: \FormatOptions.explicitSelf, expectations: expectedMapping)
validateDescriptorThrowsOptionsError(descriptor)
}
func testExperimentalRules() {
let descriptor = FormatOptions.Descriptor.experimentalRules
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "enabled"),
(optionValue: false, argumentValue: "disabled"),
]
validateDescriptor(descriptor, displayName: "Experimental Rules", argumentName: "experimental", propertyName: "experimentalRules")
validateArgumentsBinaryType(descriptor, controlTrue: ["enabled", "true"], controlFalse: ["disabled", "false"])
validateFromOptions(descriptor, keyPath: \FormatOptions.experimentalRules, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.experimentalRules)
validateDescriptorThrowsOptionsError(descriptor)
}
func testFragment() {
let descriptor = FormatOptions.Descriptor.fragment
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "true"),
(optionValue: false, argumentValue: "false"),
]
validateDescriptor(descriptor, displayName: "Fragment", argumentName: "fragment", propertyName: "fragment")
validateArgumentsBinaryType(descriptor, controlTrue: ["true", "enabled"], controlFalse: ["false", "disabled"])
validateFromOptions(descriptor, keyPath: \FormatOptions.fragment, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.fragment)
validateDescriptorThrowsOptionsError(descriptor)
}
func testIgnoreConflictMarkers() {
let descriptor = FormatOptions.Descriptor.ignoreConflictMarkers
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "ignore"),
(optionValue: false, argumentValue: "reject"),
]
validateDescriptor(descriptor, displayName: "Conflict Markers", argumentName: "conflictmarkers", propertyName: "ignoreConflictMarkers")
validateArgumentsBinaryType(descriptor, controlTrue: ["ignore", "true", "enabled"], controlFalse: ["reject", "false", "disabled"])
validateFromOptions(descriptor, keyPath: \FormatOptions.ignoreConflictMarkers, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.ignoreConflictMarkers)
validateDescriptorThrowsOptionsError(descriptor)
}
func testIfdefIndent() {
let descriptor = FormatOptions.Descriptor.ifdefIndent
let expectedMapping: [OptionArgumentMapping<IndentMode>] = [
(optionValue: IndentMode.indent, argumentValue: "indent"),
(optionValue: IndentMode.noIndent, argumentValue: "no-indent"),
(optionValue: IndentMode.outdent, argumentValue: "outdent"),
]
let alternateMapping: [OptionArgumentMapping<IndentMode>] = [
(optionValue: IndentMode.noIndent, argumentValue: "noindent"),
]
validateDescriptor(descriptor, displayName: "Ifdef Indent", argumentName: "ifdef", propertyName: "ifdefIndent")
validateArgumentsListType(descriptor, validArguments: ["indent", "no-indent", "outdent"])
validateFromOptions(descriptor, keyPath: \FormatOptions.ifdefIndent, expectations: expectedMapping)
validateFromArguments(descriptor, keyPath: \FormatOptions.ifdefIndent, expectations: expectedMapping + alternateMapping)
validateDescriptorThrowsOptionsError(descriptor)
}
func testLinebreakChar() {
let descriptor = FormatOptions.Descriptor.lineBreak
let expectedMapping: [OptionArgumentMapping<String>] = [
(optionValue: "\n", argumentValue: "lf"),
(optionValue: "\r", argumentValue: "cr"),
(optionValue: "\r\n", argumentValue: "crlf"),
]
validateDescriptor(descriptor, displayName: "Linebreak Character", argumentName: "linebreaks", propertyName: "linebreak")
validateArgumentsListType(descriptor, validArguments: ["cr", "lf", "crlf"])
validateFromOptions(descriptor, keyPath: \FormatOptions.linebreak, expectations: expectedMapping, invalid: "invalid")
validateFromArguments(descriptor, keyPath: \FormatOptions.linebreak, expectations: expectedMapping)
validateDescriptorThrowsOptionsError(descriptor)
}
func testWrapArguments() {
let descriptor = FormatOptions.Descriptor.wrapArguments
let expectedMapping: [OptionArgumentMapping<WrapMode>] = [
(optionValue: .beforeFirst, argumentValue: "before-first"),
(optionValue: .afterFirst, argumentValue: "after-first"),
(optionValue: .preserve, argumentValue: "preserve"),
(optionValue: .disabled, argumentValue: "disabled"),
]
let alternateMapping: [OptionArgumentMapping<WrapMode>] = [
(optionValue: .beforeFirst, argumentValue: "beforefirst"),
(optionValue: .afterFirst, argumentValue: "afterfirst"),
]
validateDescriptor(descriptor, displayName: "Wrap Arguments", argumentName: "wraparguments", propertyName: "wrapArguments")
validateArgumentsListType(descriptor, validArguments: [
"before-first", "after-first", "preserve", "disabled",
])
validateFromOptions(descriptor, keyPath: \FormatOptions.wrapArguments, expectations: expectedMapping)
validateFromArguments(descriptor, keyPath: \FormatOptions.wrapArguments, expectations: expectedMapping + alternateMapping)
validateDescriptorThrowsOptionsError(descriptor)
}
func testWrapCollections() {
let descriptor = FormatOptions.Descriptor.wrapCollections
let expectedMapping: [OptionArgumentMapping<WrapMode>] = [
(optionValue: .beforeFirst, argumentValue: "before-first"),
(optionValue: .afterFirst, argumentValue: "after-first"),
(optionValue: .preserve, argumentValue: "preserve"),
(optionValue: .disabled, argumentValue: "disabled"),
]
let alternateMapping: [OptionArgumentMapping<WrapMode>] = [
(optionValue: .beforeFirst, argumentValue: "beforefirst"),
(optionValue: .afterFirst, argumentValue: "afterfirst"),
]
validateDescriptor(descriptor, displayName: "Wrap Collections", argumentName: "wrapcollections", propertyName: "wrapCollections")
validateArgumentsListType(descriptor, validArguments: [
"before-first", "after-first", "preserve", "disabled",
])
validateFromOptions(descriptor, keyPath: \FormatOptions.wrapCollections, expectations: expectedMapping)
validateFromArguments(descriptor, keyPath: \FormatOptions.wrapCollections, expectations: expectedMapping + alternateMapping)
validateDescriptorThrowsOptionsError(descriptor)
}
func testStripUnusedArguments() {
let descriptor = FormatOptions.Descriptor.stripUnusedArguments
let expectedMapping: [OptionArgumentMapping<ArgumentStrippingMode>] = [
(optionValue: .unnamedOnly, argumentValue: "unnamed-only"),
(optionValue: .closureOnly, argumentValue: "closure-only"),
(optionValue: .all, argumentValue: "always"),
]
validateDescriptor(descriptor, displayName: "Strip Unused Arguments", argumentName: "stripunusedargs", propertyName: "stripUnusedArguments")
validateArgumentsListType(descriptor, validArguments: ["unnamed-only", "closure-only", "always"])
validateFromOptions(descriptor, keyPath: \FormatOptions.stripUnusedArguments, expectations: expectedMapping)
validateFromArguments(descriptor, keyPath: \FormatOptions.stripUnusedArguments, expectations: expectedMapping)
validateDescriptorThrowsOptionsError(descriptor)
}
func testDecimalGrouping() {
validateGroupingDescriptor(.decimalGrouping,
displayName: "Decimal Grouping",
argumentName: "decimalgrouping",
propertyName: "decimalGrouping",
keyPath: \FormatOptions.decimalGrouping)
}
func testBinaryGrouping() {
validateGroupingDescriptor(.binaryGrouping,
displayName: "Binary Grouping",
argumentName: "binarygrouping",
propertyName: "binaryGrouping",
keyPath: \FormatOptions.binaryGrouping)
}
func testOctalGrouping() {
validateGroupingDescriptor(.octalGrouping,
displayName: "Octal Grouping",
argumentName: "octalgrouping",
propertyName: "octalGrouping",
keyPath: \FormatOptions.octalGrouping)
}
func testHexGrouping() {
validateGroupingDescriptor(.hexGrouping,
displayName: "Hex Grouping",
argumentName: "hexgrouping",
propertyName: "hexGrouping",
keyPath: \FormatOptions.hexGrouping)
}
func testFractionGrouping() {
validateArgumentsBinaryType(.fractionGrouping,
controlTrue: ["enabled", "true"],
controlFalse: ["disabled", "false"])
}
func testExponentGrouping() {
validateArgumentsBinaryType(.exponentGrouping,
controlTrue: ["enabled", "true"],
controlFalse: ["disabled", "false"])
}
func testIndentation() {
let descriptor = FormatOptions.Descriptor.indentation
let validations: [FreeTextValidationExpectation] = [
@@ -582,7 +152,6 @@ class OptionsDescriptorTests: XCTestCase {
(optionValue: " ", argumentValue: "4"),
]
validateDescriptor(descriptor, displayName: "Indent", argumentName: "indent", propertyName: "indent")
validateArgumentsFreeTextType(descriptor, expectations: validations)
validateFromOptions(descriptor, keyPath: \FormatOptions.indent, expectations: fromOptionExpectations)
validateFromArguments(descriptor, keyPath: \FormatOptions.indent, expectations: fromArgumentExpectations)
@@ -617,7 +186,6 @@ class OptionsDescriptorTests: XCTestCase {
(optionValue: "//a\n//b", argumentValue: "//a\\n//b"),
]
validateDescriptor(descriptor, displayName: "Header", argumentName: "header", propertyName: "fileHeader")
validateArgumentsFreeTextType(descriptor, expectations: validations)
validateFromOptions(descriptor, keyPath: \FormatOptions.fileHeader, expectations: fromOptionExpectations)
validateFromOptionalArguments(descriptor, keyPath: \FormatOptions.fileHeader, expectations: fromArgumentExpectations, testCaseVariation: false)
@@ -667,88 +235,4 @@ class OptionsDescriptorTests: XCTestCase {
var options = FormatOptions()
XCTAssertNoThrow(try descriptor.toOptions("+,+", &options))
}
func testSpecifierOrder() {
let descriptor = FormatOptions.Descriptor.specifierOrder
let validations: [FreeTextValidationExpectation] = [
(input: "public", isValid: true),
(input: "", isValid: true),
(input: "private(set)", isValid: true),
(input: "override", isValid: true),
(input: "class", isValid: true),
(input: "struct", isValid: false),
]
let fromOptionExpectations: [OptionArgumentMapping<[String]>] = [
(optionValue: [], argumentValue: ""),
(optionValue: ["public(set)", "override"], argumentValue: "public(set),override"),
]
validateFromOptions(descriptor, keyPath: \FormatOptions.specifierOrder, expectations: fromOptionExpectations)
validateArgumentsFreeTextType(descriptor, expectations: validations)
var options = FormatOptions()
XCTAssertThrowsError(try descriptor.toOptions("public,open,public", &options)) { error in
XCTAssert(error.localizedDescription.contains("Duplicate"))
}
}
// MARK: Deprecated
func testInsertBlankLines() {
let descriptor = FormatOptions.Descriptor.insertBlankLines
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "enabled"),
(optionValue: false, argumentValue: "disabled"),
]
validateDescriptor(descriptor, displayName: "Insert Lines", argumentName: "insertlines", propertyName: "insertBlankLines")
validateArgumentsBinaryType(descriptor, controlTrue: ["enabled", "true"], controlFalse: ["disabled", "false"])
validateFromOptions(descriptor, keyPath: \FormatOptions.insertBlankLines, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.insertBlankLines)
validateDescriptorThrowsOptionsError(descriptor)
}
func testRemoveBlankLines() {
let descriptor = FormatOptions.Descriptor.removeBlankLines
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "enabled"),
(optionValue: false, argumentValue: "disabled"),
]
validateDescriptor(descriptor, displayName: "Remove Lines", argumentName: "removelines", propertyName: "removeBlankLines")
validateArgumentsBinaryType(descriptor, controlTrue: ["enabled", "true"], controlFalse: ["disabled", "false"])
validateFromOptions(descriptor, keyPath: \FormatOptions.removeBlankLines, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.removeBlankLines)
validateDescriptorThrowsOptionsError(descriptor)
}
func testHexliterals() {
let descriptor = FormatOptions.Descriptor.hexLiterals
let fromOptionsExpectation: [OptionArgumentMapping<Bool>] = [
(optionValue: true, argumentValue: "uppercase"),
(optionValue: false, argumentValue: "lowercase"),
]
validateDescriptor(descriptor, displayName: "hexliterals", argumentName: "hexliterals", propertyName: "uppercaseHex")
validateArgumentsBinaryType(descriptor, controlTrue: ["uppercase", "upper"], controlFalse: ["lowercase", "lower"])
validateFromOptions(descriptor, keyPath: \FormatOptions.uppercaseHex, expectations: fromOptionsExpectation)
validateFromArgumentsBinaryType(descriptor, keyPath: \FormatOptions.uppercaseHex)
validateDescriptorThrowsOptionsError(descriptor)
}
func testWrapElements() {
let descriptor = FormatOptions.Descriptor.wrapElements
let expectedMapping: [OptionArgumentMapping<WrapMode>] = [
(optionValue: .beforeFirst, argumentValue: "before-first"),
(optionValue: .afterFirst, argumentValue: "after-first"),
(optionValue: .preserve, argumentValue: "preserve"),
(optionValue: .disabled, argumentValue: "disabled"),
]
let alternateMapping: [OptionArgumentMapping<WrapMode>] = [
(optionValue: .beforeFirst, argumentValue: "beforefirst"),
(optionValue: .afterFirst, argumentValue: "afterfirst"),
]
validateDescriptor(descriptor, displayName: "Wrap Elements", argumentName: "wrapelements", propertyName: "wrapCollections")
validateArgumentsListType(descriptor, validArguments: [
"before-first", "after-first", "preserve", "disabled",
])
validateFromOptions(descriptor, keyPath: \FormatOptions.wrapCollections, expectations: expectedMapping)
validateFromArguments(descriptor, keyPath: \FormatOptions.wrapCollections, expectations: expectedMapping + alternateMapping)
validateDescriptorThrowsOptionsError(descriptor)
}
}
-33
View File
@@ -292,44 +292,11 @@ extension OptionsDescriptorTests {
// to regenerate.
static let __allTests__OptionsDescriptorTests = [
("testAllDescriptorsHaveProperty", testAllDescriptorsHaveProperty),
("testAllmanBraces", testAllmanBraces),
("testAllowInlineSemicolons", testAllowInlineSemicolons),
("testAllPropertiesHaveDescriptor", testAllPropertiesHaveDescriptor),
("testBinaryGrouping", testBinaryGrouping),
("testDecimalGrouping", testDecimalGrouping),
("testElsePosition", testElsePosition),
("testExperimentalRules", testExperimentalRules),
("testExplicitSelf", testExplicitSelf),
("testExponentCase", testExponentCase),
("testExponentGrouping", testExponentGrouping),
("testFileHeader", testFileHeader),
("testFractionGrouping", testFractionGrouping),
("testFragment", testFragment),
("testHexGrouping", testHexGrouping),
("testHexLiteralCase", testHexLiteralCase),
("testHexliterals", testHexliterals),
("testIfdefIndent", testIfdefIndent),
("testIgnoreConflictMarkers", testIgnoreConflictMarkers),
("testIndentation", testIndentation),
("testIndentCase", testIndentCase),
("testIndentComments", testIndentComments),
("testInsertBlankLines", testInsertBlankLines),
("testLetPatternPlacement", testLetPatternPlacement),
("testLinebreakChar", testLinebreakChar),
("testNoSpaceOperators", testNoSpaceOperators),
("testNoWrapOperators", testNoWrapOperators),
("testOctalGrouping", testOctalGrouping),
("testRemoveBlankLines", testRemoveBlankLines),
("testSpaceAroundOperatorDeclarations", testSpaceAroundOperatorDeclarations),
("testSpaceAroundRangeOperators", testSpaceAroundRangeOperators),
("testSpecifierOrder", testSpecifierOrder),
("testStripUnusedArguments", testStripUnusedArguments),
("testTrailingCommas", testTrailingCommas),
("testTruncateBlankLines", testTruncateBlankLines),
("testUseVoid", testUseVoid),
("testWrapArguments", testWrapArguments),
("testWrapCollections", testWrapCollections),
("testWrapElements", testWrapElements),
]
}