Correctly highlight generic subscript type lists (#86)

This patch fixes highlighting for types that appear within a list of a
subscript’s generic types.
This commit is contained in:
John Sundell 2019-09-05 14:17:48 +02:00 committed by GitHub
parent 8ef48daff9
commit 19df647082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View File

@ -335,7 +335,7 @@ private extension SwiftGrammar {
private let declarationKeywords: Set<String> = [
"class", "struct", "enum", "func",
"protocol", "typealias", "import",
"associatedtype"
"associatedtype", "subscript"
]
func matches(_ segment: Segment) -> Bool {

View File

@ -706,6 +706,45 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
])
}
func testGenericSubscriptDeclaration() {
let components = highlighter.highlight("""
extension Collection {
subscript<T>(key: Key<T>) -> T? { return nil }
}
""")
XCTAssertEqual(components, [
.token("extension", .keyword),
.whitespace(" "),
.token("Collection", .type),
.whitespace(" "),
.plainText("{"),
.whitespace("\n "),
.token("subscript", .keyword),
.plainText("<T>(key:"),
.whitespace(" "),
.token("Key", .type),
.plainText("<"),
.token("T", .type),
.plainText(">)"),
.whitespace(" "),
.plainText("->"),
.whitespace(" "),
.token("T", .type),
.plainText("?"),
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
.token("return", .keyword),
.whitespace(" "),
.token("nil", .keyword),
.whitespace(" "),
.plainText("}"),
.whitespace("\n"),
.plainText("}")
])
}
func testDeferDeclaration() {
let components = highlighter.highlight("func hello() { defer {} }")
@ -1016,6 +1055,7 @@ extension DeclarationTests {
("testPropertyDeclarationWithDidSet", testPropertyDeclarationWithDidSet),
("testPropertyWithSetterAccessLevel", testPropertyWithSetterAccessLevel),
("testSubscriptDeclaration", testSubscriptDeclaration),
("testGenericSubscriptDeclaration", testGenericSubscriptDeclaration),
("testDeferDeclaration", testDeferDeclaration),
("testFunctionDeclarationWithInOutParameter", testFunctionDeclarationWithInOutParameter),
("testFunctionDeclarationWithNonEscapedKeywordAsName", testFunctionDeclarationWithNonEscapedKeywordAsName),