diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index 7ea72bd..fa05fa1 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -48,7 +48,7 @@ private extension SwiftGrammar { "#selector", "required", "willSet", "didSet", "lazy", "subscript", "defer", "inout", "while", "continue", "fallthrough", "repeat", "indirect", - "deinit" + "deinit", "is" ] as Set).union(accessControlKeywords) static let accessControlKeywords: Set = [ diff --git a/Tests/SplashTests/Tests/StatementTests.swift b/Tests/SplashTests/Tests/StatementTests.swift index 0e64a92..250bfe8 100644 --- a/Tests/SplashTests/Tests/StatementTests.swift +++ b/Tests/SplashTests/Tests/StatementTests.swift @@ -169,6 +169,39 @@ final class StatementTests: SyntaxHighlighterTestCase { ]) } + func testSwitchStatementWithTypePatternMatching() { + let components = highlighter.highlight(""" + switch variable { + case is MyType: break + default: break + } + """) + + XCTAssertEqual(components, [ + .token("switch", .keyword), + .whitespace(" "), + .plainText("variable"), + .whitespace(" "), + .plainText("{"), + .whitespace("\n"), + .token("case", .keyword), + .whitespace(" "), + .token("is", .keyword), + .whitespace(" "), + .token("MyType", .type), + .plainText(":"), + .whitespace(" "), + .token("break", .keyword), + .whitespace("\n"), + .token("default", .keyword), + .plainText(":"), + .whitespace(" "), + .token("break", .keyword), + .whitespace("\n"), + .plainText("}") + ]) + } + func testForStatementWithStaticProperty() { let components = highlighter.highlight("for value in Enum.allCases { }") @@ -272,6 +305,7 @@ extension StatementTests { ("testSwitchStatement", testSwitchStatement), ("testSwitchStatementWithAssociatedValues", testSwitchStatementWithAssociatedValues), ("testSwitchStatementWithFallthrough", testSwitchStatementWithFallthrough), + ("testSwitchStatementWithTypePatternMatching", testSwitchStatementWithTypePatternMatching), ("testForStatementWithStaticProperty", testForStatementWithStaticProperty), ("testForStatementWithContinue", testForStatementWithContinue), ("testRepeatWhileStatement", testRepeatWhileStatement)