Correctly highlight key paths passed as arguments (#64)

This makes Splash correctly highlight key paths that are passed as arguments
to a function, especially when there’s no external parameter label for that
argument.
This commit is contained in:
John Sundell 2019-03-31 22:40:37 +02:00 committed by GitHub
parent f9cb0db662
commit c05038072a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -231,7 +231,7 @@ private extension SwiftGrammar {
}
}
return segment.tokens.next.isAny(of: "(", "()", "())", "(.", "({", "().")
return segment.tokens.next.isAny(of: "(", "()", "())", "(.", "({", "().", #"(\."#)
}
}
@ -377,7 +377,7 @@ private extension SwiftGrammar {
var tokenType: TokenType { return .property }
func matches(_ segment: Segment) -> Bool {
return segment.tokens.previous == "\\."
return segment.tokens.previous.isAny(of: #"\."#, #"(\."#)
}
}

View File

@ -223,6 +223,24 @@ final class LiteralTests: SyntaxHighlighterTestCase {
])
}
func testKeyPathLiteralsAsArguments() {
let components = highlighter.highlight(#"user.bind(\.name, to: \.text)"#)
XCTAssertEqual(components, [
.plainText("user."),
.token("bind", .call),
.plainText(#"(\."#),
.token("name", .property),
.plainText(","),
.whitespace(" "),
.plainText("to:"),
.whitespace(" "),
.plainText(#"\."#),
.token("text", .property),
.plainText(")")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
@ -242,7 +260,8 @@ extension LiteralTests {
("testMultiLineRawStringLiteral", testMultiLineRawStringLiteral),
("testDoubleLiteral", testDoubleLiteral),
("testIntegerLiteralWithSeparators", testIntegerLiteralWithSeparators),
("testKeyPathLiteral", testKeyPathLiteral)
("testKeyPathLiteral", testKeyPathLiteral),
("testKeyPathLiteralsAsArguments", testKeyPathLiteralsAsArguments)
]
}
}