From 5280f4abc7a15b6ef51c6f3f361c36b7ae8d05c3 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Sun, 21 Jul 2019 13:44:11 +0200 Subject: [PATCH] =?UTF-8?q?Add=20support=20for=20the=20=E2=80=98convenienc?= =?UTF-8?q?e=E2=80=99=20keyword=20(#76)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch makes Splash correctly highlight the ‘convenience’ keyword. --- Sources/Splash/Grammar/SwiftGrammar.swift | 2 +- .../SplashTests/Tests/DeclarationTests.swift | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index 3217478..f09b53f 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -53,7 +53,7 @@ private extension SwiftGrammar { "lazy", "subscript", "defer", "inout", "while", "continue", "fallthrough", "repeat", "indirect", "deinit", "is", "#file", "#line", "#function", - "dynamic", "some", "#available" + "dynamic", "some", "#available", "convenience" ] as Set).union(accessControlKeywords) static let accessControlKeywords: Set = [ diff --git a/Tests/SplashTests/Tests/DeclarationTests.swift b/Tests/SplashTests/Tests/DeclarationTests.swift index aa48b46..917a799 100644 --- a/Tests/SplashTests/Tests/DeclarationTests.swift +++ b/Tests/SplashTests/Tests/DeclarationTests.swift @@ -428,6 +428,39 @@ final class DeclarationTests: SyntaxHighlighterTestCase { ]) } + func testExtensionDeclarationWithConvenienceInitializer() { + let components = highlighter.highlight(""" + extension Node { convenience init(name: String) { self.init() } } + """) + + XCTAssertEqual(components, [ + .token("extension", .keyword), + .whitespace(" "), + .token("Node", .type), + .whitespace(" "), + .plainText("{"), + .whitespace(" "), + .token("convenience", .keyword), + .whitespace(" "), + .token("init", .keyword), + .plainText("(name:"), + .whitespace(" "), + .token("String", .type), + .plainText(")"), + .whitespace(" "), + .plainText("{"), + .whitespace(" "), + .token("self", .keyword), + .plainText("."), + .token("init", .call), + .plainText("()"), + .whitespace(" "), + .plainText("}"), + .whitespace(" "), + .plainText("}") + ]) + } + func testExtensionDeclarationWithConstraint() { let components = highlighter.highlight("extension Hello where Foo == String, Bar: Numeric { }") @@ -974,6 +1007,7 @@ extension DeclarationTests { ("testProtocolDeclaration", testProtocolDeclaration), ("testProtocolDeclarationWithAssociatedTypes", testProtocolDeclarationWithAssociatedTypes), ("testExtensionDeclaration", testExtensionDeclaration), + ("testExtensionDeclarationWithConvenienceInitializer", testExtensionDeclarationWithConvenienceInitializer), ("testExtensionDeclarationWithConstraint", testExtensionDeclarationWithConstraint), ("testLazyPropertyDeclaration", testLazyPropertyDeclaration), ("testDynamicPropertyDeclaration", testDynamicPropertyDeclaration),