Merge pull request #39 from JohnSundell/associatedtypes
Correctly highlight associated types
This commit is contained in:
commit
fdc0e22d5f
@ -236,7 +236,8 @@ private extension SwiftGrammar {
|
|||||||
|
|
||||||
private let declarationKeywords: Set<String> = [
|
private let declarationKeywords: Set<String> = [
|
||||||
"class", "struct", "enum", "func",
|
"class", "struct", "enum", "func",
|
||||||
"protocol", "typealias", "import"
|
"protocol", "typealias", "import",
|
||||||
|
"associatedtype"
|
||||||
]
|
]
|
||||||
|
|
||||||
func matches(_ segment: Segment) -> Bool {
|
func matches(_ segment: Segment) -> Bool {
|
||||||
|
@ -291,6 +291,37 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testProtocolDeclarationWithAssociatedTypes() {
|
||||||
|
let components = highlighter.highlight("""
|
||||||
|
protocol Task {
|
||||||
|
associatedtype Input
|
||||||
|
associatedtype Error: Swift.Error
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
|
||||||
|
XCTAssertEqual(components, [
|
||||||
|
.token("protocol", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("Task"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("{"),
|
||||||
|
.whitespace("\n "),
|
||||||
|
.token("associatedtype", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("Input"),
|
||||||
|
.whitespace("\n "),
|
||||||
|
.token("associatedtype", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("Error:"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("Swift", .type),
|
||||||
|
.plainText("."),
|
||||||
|
.token("Error", .type),
|
||||||
|
.whitespace("\n"),
|
||||||
|
.plainText("}")
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
func testExtensionDeclaration() {
|
func testExtensionDeclaration() {
|
||||||
let components = highlighter.highlight("extension UIViewController { }")
|
let components = highlighter.highlight("extension UIViewController { }")
|
||||||
|
|
||||||
@ -636,6 +667,7 @@ extension DeclarationTests {
|
|||||||
("testClassDeclarationWithMultipleProtocolConformances", testClassDeclarationWithMultipleProtocolConformances),
|
("testClassDeclarationWithMultipleProtocolConformances", testClassDeclarationWithMultipleProtocolConformances),
|
||||||
("testSubclassDeclaration", testSubclassDeclaration),
|
("testSubclassDeclaration", testSubclassDeclaration),
|
||||||
("testProtocolDeclaration", testProtocolDeclaration),
|
("testProtocolDeclaration", testProtocolDeclaration),
|
||||||
|
("testProtocolDeclarationWithAssociatedTypes", testProtocolDeclarationWithAssociatedTypes),
|
||||||
("testExtensionDeclaration", testExtensionDeclaration),
|
("testExtensionDeclaration", testExtensionDeclaration),
|
||||||
("testExtensionDeclarationWithConstraint", testExtensionDeclarationWithConstraint),
|
("testExtensionDeclarationWithConstraint", testExtensionDeclarationWithConstraint),
|
||||||
("testLazyPropertyDeclaration", testLazyPropertyDeclaration),
|
("testLazyPropertyDeclaration", testLazyPropertyDeclaration),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user