diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index ff6152f..b6110ef 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -47,7 +47,7 @@ private extension SwiftGrammar { "super", "self", "set", "true", "false", "nil", "override", "where", "_", "default", "break", "#selector", "required", "willSet", "didSet", - "lazy", "subscript" + "lazy", "subscript", "defer" ] struct PreprocessingRule: SyntaxRule { diff --git a/Tests/SplashTests/Tests/DeclarationTests.swift b/Tests/SplashTests/Tests/DeclarationTests.swift index 1480ee4..aee04e9 100644 --- a/Tests/SplashTests/Tests/DeclarationTests.swift +++ b/Tests/SplashTests/Tests/DeclarationTests.swift @@ -475,6 +475,25 @@ final class DeclarationTests: SyntaxHighlighterTestCase { .plainText("}") ]) } + + func testDeferDeclaration() { + let components = highlighter.highlight("func hello() { defer {} }") + + XCTAssertEqual(components, [ + .token("func", .keyword), + .whitespace(" "), + .plainText("hello()"), + .whitespace(" "), + .plainText("{"), + .whitespace(" "), + .token("defer", .keyword), + .whitespace(" "), + .plainText("{}"), + .whitespace(" "), + .plainText("}") + ]) + + } func testAllTestsRunOnLinux() { XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests)) @@ -503,7 +522,8 @@ extension DeclarationTests { ("testGenericPropertyDeclaration", testGenericPropertyDeclaration), ("testPropertyDeclarationWithWillSet", testPropertyDeclarationWithWillSet), ("testPropertyDeclarationWithDidSet", testPropertyDeclarationWithDidSet), - ("testSubscriptDeclaration", testSubscriptDeclaration) + ("testSubscriptDeclaration", testSubscriptDeclaration), + ("testDeferDeclaration", testDeferDeclaration) ] } }