Correctly highlight Bools passed as unnamed function arguments

This patch fixes highlighting of `Bool` values passed as arguments that
don’t have an external parameter label.
This commit is contained in:
John Sundell 2019-03-08 18:32:12 +01:00
parent 7f2421cd99
commit 45740696d0
2 changed files with 14 additions and 2 deletions

View File

@ -216,7 +216,7 @@ private extension SwiftGrammar {
if let previousToken = segment.tokens.previous { if let previousToken = segment.tokens.previous {
// Don't highlight most keywords when used as a parameter label // Don't highlight most keywords when used as a parameter label
if !segment.tokens.current.isAny(of: "_", "self", "let", "var") { if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false") {
guard !previousToken.isAny(of: "(", ",") else { guard !previousToken.isAny(of: "(", ",") else {
return false return false
} }

View File

@ -119,6 +119,17 @@ final class FunctionCallTests: SyntaxHighlighterTestCase {
]) ])
} }
func testPassingBoolToUnnamedArgument() {
let components = highlighter.highlight("setCachingEnabled(true)")
XCTAssertEqual(components, [
.token("setCachingEnabled", .call),
.plainText("("),
.token("true", .keyword),
.plainText(")")
])
}
func testAllTestsRunOnLinux() { func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests)) XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
} }
@ -134,7 +145,8 @@ extension FunctionCallTests {
("testAccessingPropertyAfterFunctionCallWithoutArguments", testAccessingPropertyAfterFunctionCallWithoutArguments), ("testAccessingPropertyAfterFunctionCallWithoutArguments", testAccessingPropertyAfterFunctionCallWithoutArguments),
("testAccessingPropertyAfterFunctionCallWithArguments", testAccessingPropertyAfterFunctionCallWithArguments), ("testAccessingPropertyAfterFunctionCallWithArguments", testAccessingPropertyAfterFunctionCallWithArguments),
("testCallingStaticMethodOnGenericType", testCallingStaticMethodOnGenericType), ("testCallingStaticMethodOnGenericType", testCallingStaticMethodOnGenericType),
("testPassingTypeToFunction", testPassingTypeToFunction) ("testPassingTypeToFunction", testPassingTypeToFunction),
("testPassingBoolToUnnamedArgument", testPassingBoolToUnnamedArgument)
] ]
} }
} }