Add support for the ‘convenience’ keyword (#76)

This patch makes Splash correctly highlight the ‘convenience’ keyword.
This commit is contained in:
John Sundell 2019-07-21 13:44:11 +02:00 committed by GitHub
parent 370f685cb1
commit 5280f4abc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -53,7 +53,7 @@ private extension SwiftGrammar {
"lazy", "subscript", "defer", "inout", "while", "lazy", "subscript", "defer", "inout", "while",
"continue", "fallthrough", "repeat", "indirect", "continue", "fallthrough", "repeat", "indirect",
"deinit", "is", "#file", "#line", "#function", "deinit", "is", "#file", "#line", "#function",
"dynamic", "some", "#available" "dynamic", "some", "#available", "convenience"
] as Set<String>).union(accessControlKeywords) ] as Set<String>).union(accessControlKeywords)
static let accessControlKeywords: Set<String> = [ static let accessControlKeywords: Set<String> = [

View File

@ -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() { func testExtensionDeclarationWithConstraint() {
let components = highlighter.highlight("extension Hello where Foo == String, Bar: Numeric { }") let components = highlighter.highlight("extension Hello where Foo == String, Bar: Numeric { }")
@ -974,6 +1007,7 @@ extension DeclarationTests {
("testProtocolDeclaration", testProtocolDeclaration), ("testProtocolDeclaration", testProtocolDeclaration),
("testProtocolDeclarationWithAssociatedTypes", testProtocolDeclarationWithAssociatedTypes), ("testProtocolDeclarationWithAssociatedTypes", testProtocolDeclarationWithAssociatedTypes),
("testExtensionDeclaration", testExtensionDeclaration), ("testExtensionDeclaration", testExtensionDeclaration),
("testExtensionDeclarationWithConvenienceInitializer", testExtensionDeclarationWithConvenienceInitializer),
("testExtensionDeclarationWithConstraint", testExtensionDeclarationWithConstraint), ("testExtensionDeclarationWithConstraint", testExtensionDeclarationWithConstraint),
("testLazyPropertyDeclaration", testLazyPropertyDeclaration), ("testLazyPropertyDeclaration", testLazyPropertyDeclaration),
("testDynamicPropertyDeclaration", testDynamicPropertyDeclaration), ("testDynamicPropertyDeclaration", testDynamicPropertyDeclaration),