Skip to content

Commit

Permalink
Correctly highlight subclasses inheriting from a generic superclass (#…
Browse files Browse the repository at this point in the history
…108)

This change fixes syntax highlighting in situations when a subclass is
inheriting from a superclass that’s generic.
  • Loading branch information
JohnSundell committed May 24, 2020
1 parent 3e400c0 commit ca9a1b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Splash/Grammar/SwiftGrammar.swift
Expand Up @@ -419,7 +419,7 @@ private extension SwiftGrammar {
}

// Handling generic lists for parameters, rather than declarations
if foundOpeningBracket && token == ":" {
if foundOpeningBracket && token.isAny(of: ":", ">:") {
return true
}

Expand Down
18 changes: 18 additions & 0 deletions Tests/SplashTests/Tests/DeclarationTests.swift
Expand Up @@ -368,6 +368,23 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
])
}

func testGenericSubclassDeclaration() {
let components = highlighter.highlight("class Promise<Value>: Future<Value> {}")

XCTAssertEqual(components, [
.token("class", .keyword),
.whitespace(" "),
.plainText("Promise<Value>:"),
.whitespace(" "),
.token("Future", .type),
.plainText("<"),
.token("Value", .type),
.plainText(">"),
.whitespace(" "),
.plainText("{}")
])
}

func testProtocolDeclaration() {
let components = highlighter.highlight("""
protocol Hello {
Expand Down Expand Up @@ -1161,6 +1178,7 @@ extension DeclarationTests {
("testClassDeclarationWithDeinit", testClassDeclarationWithDeinit),
("testClassDeclarationWithMultipleProtocolConformances", testClassDeclarationWithMultipleProtocolConformances),
("testSubclassDeclaration", testSubclassDeclaration),
("testGenericSubclassDeclaration", testGenericSubclassDeclaration),
("testProtocolDeclaration", testProtocolDeclaration),
("testProtocolDeclarationWithAssociatedTypes", testProtocolDeclarationWithAssociatedTypes),
("testExtensionDeclaration", testExtensionDeclaration),
Expand Down

0 comments on commit ca9a1b7

Please sign in to comment.