Highlight enums used as subscripting keys

This patch fixes highlighting when an enum is used as a dictionary key, like this:

```
let value = dictionary[.key]
```
This commit is contained in:
John Sundell 2018-08-27 18:14:17 +02:00
parent c73767a0bc
commit a86694802e
2 changed files with 13 additions and 2 deletions

View File

@ -262,7 +262,7 @@ private extension SwiftGrammar {
var tokenType: TokenType { return .dotAccess } var tokenType: TokenType { return .dotAccess }
func matches(_ segment: Segment) -> Bool { func matches(_ segment: Segment) -> Bool {
guard segment.tokens.previous.isAny(of: ".", "(.") else { guard segment.tokens.previous.isAny(of: ".", "(.", "[.") else {
return false return false
} }

View File

@ -48,6 +48,16 @@ final class EnumTests: SyntaxHighlighterTestCase {
]) ])
} }
func testUsingEnumInSubscript() {
let components = highlighter.highlight("dictionary[.key]")
XCTAssertEqual(components, [
.plainText("dictionary[."),
.token("key", .dotAccess),
.plainText("]")
])
}
func testAllTestsRunOnLinux() { func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests)) XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
} }
@ -58,7 +68,8 @@ extension EnumTests {
return [ return [
("testEnumDotSyntaxInAssignment", testEnumDotSyntaxInAssignment), ("testEnumDotSyntaxInAssignment", testEnumDotSyntaxInAssignment),
("testEnumDotSyntaxAsArgument", testEnumDotSyntaxAsArgument), ("testEnumDotSyntaxAsArgument", testEnumDotSyntaxAsArgument),
("testEnumDotSyntaxWithAssociatedValue", testEnumDotSyntaxWithAssociatedValue) ("testEnumDotSyntaxWithAssociatedValue", testEnumDotSyntaxWithAssociatedValue),
("testUsingEnumInSubscript", testUsingEnumInSubscript)
] ]
} }
} }