Correctly highlight enum cases called “some” (#100)

Was previously highlighted as a keyword.
This commit is contained in:
John Sundell 2020-02-11 16:14:53 +01:00 committed by GitHub
parent 2d55b33529
commit 3b546b7dd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -307,6 +307,12 @@ private extension SwiftGrammar {
return true
}
if segment.tokens.current == "some" {
guard segment.tokens.previous != "case" else {
return false
}
}
if segment.tokens.next == ":" {
// Nil pattern matching inside of a switch statement case
if segment.tokens.current == "nil" {

View File

@ -1023,6 +1023,26 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
])
}
func testEnumDeclarationWithSomeCase() {
let components = highlighter.highlight("""
enum MyEnum { case some }
""")
XCTAssertEqual(components, [
.token("enum", .keyword),
.whitespace(" "),
.plainText("MyEnum"),
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
.token("case", .keyword),
.whitespace(" "),
.plainText("some"),
.whitespace(" "),
.plainText("}")
])
}
func testIndirectEnumDeclaration() {
let components = highlighter.highlight("""
indirect enum Content {
@ -1135,6 +1155,7 @@ extension DeclarationTests {
("testRethrowingFunctionDeclaration", testRethrowingFunctionDeclaration),
("testFunctionDeclarationWithOpaqueReturnType", testFunctionDeclarationWithOpaqueReturnType),
("testPrefixFunctionDeclaration", testPrefixFunctionDeclaration),
("testEnumDeclarationWithSomeCase", testEnumDeclarationWithSomeCase),
("testIndirectEnumDeclaration", testIndirectEnumDeclaration),
("testWrappedPropertyDeclarations", testWrappedPropertyDeclarations)
]