From 45740696d057e26b03576d2e4e7b5844c627ebb7 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Fri, 8 Mar 2019 18:32:12 +0100 Subject: [PATCH] Correctly highlight Bools passed as unnamed function arguments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch fixes highlighting of `Bool` values passed as arguments that don’t have an external parameter label. --- Sources/Splash/Grammar/SwiftGrammar.swift | 2 +- Tests/SplashTests/Tests/FunctionCallTests.swift | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index 3ef2f92..8e0570e 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -216,7 +216,7 @@ private extension SwiftGrammar { if let previousToken = segment.tokens.previous { // 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 { return false } diff --git a/Tests/SplashTests/Tests/FunctionCallTests.swift b/Tests/SplashTests/Tests/FunctionCallTests.swift index 7d46283..48ef8c4 100644 --- a/Tests/SplashTests/Tests/FunctionCallTests.swift +++ b/Tests/SplashTests/Tests/FunctionCallTests.swift @@ -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() { XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests)) } @@ -134,7 +145,8 @@ extension FunctionCallTests { ("testAccessingPropertyAfterFunctionCallWithoutArguments", testAccessingPropertyAfterFunctionCallWithoutArguments), ("testAccessingPropertyAfterFunctionCallWithArguments", testAccessingPropertyAfterFunctionCallWithArguments), ("testCallingStaticMethodOnGenericType", testCallingStaticMethodOnGenericType), - ("testPassingTypeToFunction", testPassingTypeToFunction) + ("testPassingTypeToFunction", testPassingTypeToFunction), + ("testPassingBoolToUnnamedArgument", testPassingBoolToUnnamedArgument) ] } }