Merge pull request #10 from JohnSundell/enum-subscripting

Highlight enums used as subscripting keys
This commit is contained in:
John Sundell 2018-08-27 18:21:07 +02:00 committed by GitHub
commit fd160ba1ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -262,7 +262,7 @@ private extension SwiftGrammar {
var tokenType: TokenType { return .dotAccess }
func matches(_ segment: Segment) -> Bool {
guard segment.tokens.previous.isAny(of: ".", "(.") else {
guard segment.tokens.previous.isAny(of: ".", "(.", "[.") else {
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() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
@ -58,7 +68,8 @@ extension EnumTests {
return [
("testEnumDotSyntaxInAssignment", testEnumDotSyntaxInAssignment),
("testEnumDotSyntaxAsArgument", testEnumDotSyntaxAsArgument),
("testEnumDotSyntaxWithAssociatedValue", testEnumDotSyntaxWithAssociatedValue)
("testEnumDotSyntaxWithAssociatedValue", testEnumDotSyntaxWithAssociatedValue),
("testUsingEnumInSubscript", testUsingEnumInSubscript)
]
}
}