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:
parent
c73767a0bc
commit
a86694802e
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user