Don’t highlight generic parameter types used in initializer declarations (#107)

This change makes Splash stop highlighting generic types that are attached
to an initializer declaration, and instead now only highlights their
constraints, just like within other kinds of generic type lists.
This commit is contained in:
John Sundell 2020-05-25 00:54:25 +02:00 committed by GitHub
parent 9798c4fd6b
commit 3e400c0874
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View File

@ -87,7 +87,7 @@ private extension SwiftGrammar {
static let declarationKeywords: Set<String> = [
"class", "struct", "enum", "func",
"protocol", "typealias", "import",
"associatedtype", "subscript"
"associatedtype", "subscript", "init"
]
struct PreprocessingRule: SyntaxRule {

View File

@ -1106,6 +1106,35 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
])
}
func testGenericInitializerDeclaration() {
let components = highlighter.highlight("""
struct Box {
init<T: Model>(model: T) {}
}
""")
XCTAssertEqual(components, [
.token("struct", .keyword),
.whitespace(" "),
.plainText("Box"),
.whitespace(" "),
.plainText("{"),
.whitespace("\n "),
.token("init", .keyword),
.plainText("<T:"),
.whitespace(" "),
.token("Model", .type),
.plainText(">(model:"),
.whitespace(" "),
.token("T", .type),
.plainText(")"),
.whitespace(" "),
.plainText("{}"),
.whitespace("\n"),
.plainText("}")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
@ -1157,7 +1186,8 @@ extension DeclarationTests {
("testPrefixFunctionDeclaration", testPrefixFunctionDeclaration),
("testEnumDeclarationWithSomeCase", testEnumDeclarationWithSomeCase),
("testIndirectEnumDeclaration", testIndirectEnumDeclaration),
("testWrappedPropertyDeclarations", testWrappedPropertyDeclarations)
("testWrappedPropertyDeclarations", testWrappedPropertyDeclarations),
("testGenericInitializerDeclaration", testGenericInitializerDeclaration)
]
}
}