diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index 8e0570e..314ada7 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -236,7 +236,8 @@ private extension SwiftGrammar { private let declarationKeywords: Set = [ "class", "struct", "enum", "func", - "protocol", "typealias", "import" + "protocol", "typealias", "import", + "associatedtype" ] func matches(_ segment: Segment) -> Bool { diff --git a/Tests/SplashTests/Tests/DeclarationTests.swift b/Tests/SplashTests/Tests/DeclarationTests.swift index feb961f..12dda13 100644 --- a/Tests/SplashTests/Tests/DeclarationTests.swift +++ b/Tests/SplashTests/Tests/DeclarationTests.swift @@ -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() { let components = highlighter.highlight("extension UIViewController { }") @@ -636,6 +667,7 @@ extension DeclarationTests { ("testClassDeclarationWithMultipleProtocolConformances", testClassDeclarationWithMultipleProtocolConformances), ("testSubclassDeclaration", testSubclassDeclaration), ("testProtocolDeclaration", testProtocolDeclaration), + ("testProtocolDeclarationWithAssociatedTypes", testProtocolDeclarationWithAssociatedTypes), ("testExtensionDeclaration", testExtensionDeclaration), ("testExtensionDeclarationWithConstraint", testExtensionDeclarationWithConstraint), ("testLazyPropertyDeclaration", testLazyPropertyDeclaration),