From 896a56b682b38bc85c12343745c70cd38603b567 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Sat, 25 Aug 2018 12:56:34 +0200 Subject: [PATCH] Correctly highlight properties after function calls This patch fixes highlighting in the following scenarios: ``` call().property call(argument).property ``` --- Sources/Splash/Grammar/SwiftGrammar.swift | 4 ++-- .../SplashTests/Tests/FunctionCallTests.swift | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index a48f512..a6d4cad 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -193,7 +193,7 @@ private extension SwiftGrammar { } } - return segment.tokens.next.isAny(of: "(", "()", "())", "(.", "({") + return segment.tokens.next.isAny(of: "(", "()", "())", "(.", "({", "().") } } @@ -268,7 +268,7 @@ private extension SwiftGrammar { return false } - guard segment.tokens.previous.isAny(of: ".", "?.") else { + guard segment.tokens.previous.isAny(of: ".", "?.", "().", ").") else { return false } diff --git a/Tests/SplashTests/Tests/FunctionCallTests.swift b/Tests/SplashTests/Tests/FunctionCallTests.swift index 44c5609..f47ac4c 100644 --- a/Tests/SplashTests/Tests/FunctionCallTests.swift +++ b/Tests/SplashTests/Tests/FunctionCallTests.swift @@ -55,6 +55,26 @@ final class FunctionCallTests: SyntaxHighlighterTestCase { ]) } + func testAccessingPropertyAfterFunctionCallWithoutArguments() { + let components = highlighter.highlight("call().property") + + XCTAssertEqual(components, [ + .token("call", .call), + .plainText("()."), + .token("property", .property) + ]) + } + + func testAccessingPropertyAfterFunctionCallWithArguments() { + let components = highlighter.highlight("call(argument).property") + + XCTAssertEqual(components, [ + .token("call", .call), + .plainText("(argument)."), + .token("property", .property) + ]) + } + func testAllTestsRunOnLinux() { XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests)) } @@ -65,7 +85,9 @@ extension FunctionCallTests { return [ ("testFunctionCallWithIntegers", testFunctionCallWithIntegers), ("testImplicitInitializerCall", testImplicitInitializerCall), - ("testExplicitInitializerCall", testExplicitInitializerCall) + ("testExplicitInitializerCall", testExplicitInitializerCall), + ("testAccessingPropertyAfterFunctionCallWithoutArguments", testAccessingPropertyAfterFunctionCallWithoutArguments), + ("testAccessingPropertyAfterFunctionCallWithArguments", testAccessingPropertyAfterFunctionCallWithArguments) ] } }