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",
"override", "where", "_", "default", "break",
"#selector", "required", "willSet", "didSet",
"lazy", "subscript"
"lazy", "subscript", "defer"
]
struct PreprocessingRule: SyntaxRule {

View File

@ -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)
]
}
}