Merge pull request #43 from JohnSundell/type-pattern-matching

Support ‘is’ keyword
This commit is contained in:
John Sundell 2019-03-08 22:11:06 +01:00 committed by GitHub
commit c9425f5b60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

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

View File

@ -169,6 +169,39 @@ final class StatementTests: SyntaxHighlighterTestCase {
])
}
func testSwitchStatementWithTypePatternMatching() {
let components = highlighter.highlight("""
switch variable {
case is MyType: break
default: break
}
""")
XCTAssertEqual(components, [
.token("switch", .keyword),
.whitespace(" "),
.plainText("variable"),
.whitespace(" "),
.plainText("{"),
.whitespace("\n"),
.token("case", .keyword),
.whitespace(" "),
.token("is", .keyword),
.whitespace(" "),
.token("MyType", .type),
.plainText(":"),
.whitespace(" "),
.token("break", .keyword),
.whitespace("\n"),
.token("default", .keyword),
.plainText(":"),
.whitespace(" "),
.token("break", .keyword),
.whitespace("\n"),
.plainText("}")
])
}
func testForStatementWithStaticProperty() {
let components = highlighter.highlight("for value in Enum.allCases { }")
@ -272,6 +305,7 @@ extension StatementTests {
("testSwitchStatement", testSwitchStatement),
("testSwitchStatementWithAssociatedValues", testSwitchStatementWithAssociatedValues),
("testSwitchStatementWithFallthrough", testSwitchStatementWithFallthrough),
("testSwitchStatementWithTypePatternMatching", testSwitchStatementWithTypePatternMatching),
("testForStatementWithStaticProperty", testForStatementWithStaticProperty),
("testForStatementWithContinue", testForStatementWithContinue),
("testRepeatWhileStatement", testRepeatWhileStatement)