From 4675ffe963f84e8670808fbe5aaf7e23d1686634 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Mon, 13 May 2019 11:19:15 +0200 Subject: [PATCH] Fix highlighting for inout closure arguments (#68) This patch makes Splash correctly highlight the `inout` keyword when it appears as part of a closure argument definition. --- Sources/Splash/Grammar/SwiftGrammar.swift | 2 +- Tests/SplashTests/Tests/ClosureTests.swift | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index 5c63b32..a64b1f9 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -272,7 +272,7 @@ private extension SwiftGrammar { } // Don't highlight most keywords when used as a parameter label - if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false") { + if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false", "inout") { guard !previousToken.isAny(of: "(", ",", ">(") else { return false } diff --git a/Tests/SplashTests/Tests/ClosureTests.swift b/Tests/SplashTests/Tests/ClosureTests.swift index 45e67fa..b623bd6 100644 --- a/Tests/SplashTests/Tests/ClosureTests.swift +++ b/Tests/SplashTests/Tests/ClosureTests.swift @@ -110,6 +110,27 @@ final class ClosureTests: SyntaxHighlighterTestCase { ]) } + func testClosureWithInoutArgument() { + let components = highlighter.highlight("func add(closure: (inout Value) -> Void)") + + XCTAssertEqual(components, [ + .token("func", .keyword), + .whitespace(" "), + .plainText("add(closure:"), + .whitespace(" "), + .plainText("("), + .token("inout", .keyword), + .whitespace(" "), + .token("Value", .type), + .plainText(")"), + .whitespace(" "), + .plainText("->"), + .whitespace(" "), + .token("Void", .type), + .plainText(")") + ]) + } + func testPassingClosureAsArgument() { let components = highlighter.highlight("object.call({ $0 })") @@ -194,6 +215,7 @@ extension ClosureTests { ("testClosureArgumentWithSingleArgument", testClosureArgumentWithSingleArgument), ("testClosureArgumentWithMultipleArguments", testClosureArgumentWithMultipleArguments), ("testEscapingClosureArgument", testEscapingClosureArgument), + ("testClosureWithInoutArgument", testClosureWithInoutArgument), ("testPassingClosureAsArgument", testPassingClosureAsArgument), ("testNestedEscapingClosure", testNestedEscapingClosure), ("testClosureArgumentShorthands", testClosureArgumentShorthands)