From 87437d74256c4aa172c0e7e7f6a0e899a97d94f1 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Fri, 8 Mar 2019 17:26:10 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20treat=20.init()=20as=20an=20enu?= =?UTF-8?q?m?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change adds a special condition not to treat `.init()` as an enum (or any other kind of dot access), just like we previously had for `self`. --- Sources/Splash/Grammar/SwiftGrammar.swift | 2 +- .../SplashTests/Tests/FunctionCallTests.swift | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index f50e5ef..1a9a628 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -286,7 +286,7 @@ private extension SwiftGrammar { return false } - guard segment.tokens.current != "self" else { + guard !segment.tokens.current.isAny(of: "self", "init") else { return false } diff --git a/Tests/SplashTests/Tests/FunctionCallTests.swift b/Tests/SplashTests/Tests/FunctionCallTests.swift index 13b52e4..7d46283 100644 --- a/Tests/SplashTests/Tests/FunctionCallTests.swift +++ b/Tests/SplashTests/Tests/FunctionCallTests.swift @@ -55,6 +55,24 @@ final class FunctionCallTests: SyntaxHighlighterTestCase { ]) } + func testDotSyntaxInitializerCall() { + let components = highlighter.highlight("let string: String = .init()") + + XCTAssertEqual(components, [ + .token("let", .keyword), + .whitespace(" "), + .plainText("string:"), + .whitespace(" "), + .token("String", .type), + .whitespace(" "), + .plainText("="), + .whitespace(" "), + .plainText("."), + .token("init", .keyword), + .plainText("()") + ]) + } + func testAccessingPropertyAfterFunctionCallWithoutArguments() { let components = highlighter.highlight("call().property") @@ -112,6 +130,7 @@ extension FunctionCallTests { ("testFunctionCallWithIntegers", testFunctionCallWithIntegers), ("testImplicitInitializerCall", testImplicitInitializerCall), ("testExplicitInitializerCall", testExplicitInitializerCall), + ("testDotSyntaxInitializerCall", testDotSyntaxInitializerCall), ("testAccessingPropertyAfterFunctionCallWithoutArguments", testAccessingPropertyAfterFunctionCallWithoutArguments), ("testAccessingPropertyAfterFunctionCallWithArguments", testAccessingPropertyAfterFunctionCallWithArguments), ("testCallingStaticMethodOnGenericType", testCallingStaticMethodOnGenericType),