From c1465b0a65531fdba143440f4d53dda49f43bdc2 Mon Sep 17 00:00:00 2001 From: wangchi Date: Tue, 28 Aug 2018 16:06:43 +0800 Subject: [PATCH] =?UTF-8?q?added=20=E2=80=9Cdefer=E2=80=9D=20as=20a=20keyw?= =?UTF-8?q?ord?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Splash/Grammar/SwiftGrammar.swift | 2 +- .../SplashTests/Tests/DeclarationTests.swift | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) 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) ] } }