added “defer” as a keyword

This commit is contained in:
wangchi 2018-08-28 16:06:43 +08:00
parent 1559117b5a
commit c1465b0a65
2 changed files with 22 additions and 2 deletions

View File

@ -47,7 +47,7 @@ private extension SwiftGrammar {
"super", "self", "set", "true", "false", "nil", "super", "self", "set", "true", "false", "nil",
"override", "where", "_", "default", "break", "override", "where", "_", "default", "break",
"#selector", "required", "willSet", "didSet", "#selector", "required", "willSet", "didSet",
"lazy", "subscript" "lazy", "subscript", "defer"
] ]
struct PreprocessingRule: SyntaxRule { struct PreprocessingRule: SyntaxRule {

View File

@ -476,6 +476,25 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
]) ])
} }
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() { func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests)) XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
} }
@ -503,7 +522,8 @@ extension DeclarationTests {
("testGenericPropertyDeclaration", testGenericPropertyDeclaration), ("testGenericPropertyDeclaration", testGenericPropertyDeclaration),
("testPropertyDeclarationWithWillSet", testPropertyDeclarationWithWillSet), ("testPropertyDeclarationWithWillSet", testPropertyDeclarationWithWillSet),
("testPropertyDeclarationWithDidSet", testPropertyDeclarationWithDidSet), ("testPropertyDeclarationWithDidSet", testPropertyDeclarationWithDidSet),
("testSubscriptDeclaration", testSubscriptDeclaration) ("testSubscriptDeclaration", testSubscriptDeclaration),
("testDeferDeclaration", testDeferDeclaration)
] ]
} }
} }