adding support for "dynamic" keyword (#48)

* adding support for "dynamic" keyword

* adding test for linux

* Fixing alignment issue
This commit is contained in:
Marco Capano 2019-03-11 13:57:33 +01:00 committed by John Sundell
parent f50a610849
commit 892d6ae39c
2 changed files with 34 additions and 1 deletions

View File

@ -48,7 +48,8 @@ private extension SwiftGrammar {
"#selector", "required", "willSet", "didSet",
"lazy", "subscript", "defer", "inout", "while",
"continue", "fallthrough", "repeat", "indirect",
"deinit", "is", "#file", "#line", "#function"
"deinit", "is", "#file", "#line", "#function",
"dynamic"
] as Set<String>).union(accessControlKeywords)
static let accessControlKeywords: Set<String> = [

View File

@ -409,6 +409,37 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
.plainText("}")
])
}
func testDynamicPropertyDeclaration() {
let components = highlighter.highlight("""
class Hello {
@objc dynamic var property = 0
}
""")
XCTAssertEqual(components, [
.token("class", .keyword),
.whitespace(" "),
.plainText("Hello"),
.whitespace(" "),
.plainText("{"),
.whitespace("\n "),
.token("@objc", .keyword),
.whitespace(" "),
.token("dynamic", .keyword),
.whitespace(" "),
.token("var", .keyword),
.whitespace(" "),
.plainText("property"),
.whitespace(" "),
.plainText("="),
.whitespace(" "),
.token("0", .number),
.whitespace("\n"),
.plainText("}")
])
}
func testGenericPropertyDeclaration() {
let components = highlighter.highlight("class Hello { var array: Array<String> = [] }")
@ -751,6 +782,7 @@ extension DeclarationTests {
("testExtensionDeclaration", testExtensionDeclaration),
("testExtensionDeclarationWithConstraint", testExtensionDeclarationWithConstraint),
("testLazyPropertyDeclaration", testLazyPropertyDeclaration),
("testDynamicPropertyDeclaration", testDynamicPropertyDeclaration),
("testGenericPropertyDeclaration", testGenericPropertyDeclaration),
("testPropertyDeclarationWithWillSet", testPropertyDeclarationWithWillSet),
("testPropertyDeclarationWithDidSet", testPropertyDeclarationWithDidSet),