Correctly highlight the “try” keyword when used within a function call (#104)

This change makes Splash highlight the `try` keyword when it appears
within a function’s argument list.
This commit is contained in:
John Sundell 2020-05-22 01:14:37 +02:00 committed by GitHub
parent 03ea9bdcbb
commit b6c489c980
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -354,7 +354,7 @@ private extension SwiftGrammar {
}
// Don't highlight most keywords when used as a parameter label
if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false", "inout", "nil") {
if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false", "inout", "nil", "try") {
guard !previousToken.isAny(of: "(", ",", ">(") else {
return false
}

View File

@ -170,6 +170,19 @@ final class FunctionCallTests: SyntaxHighlighterTestCase {
])
}
func testUsingTryKeywordWithinFunctionCall() {
let components = highlighter.highlight("XCTAssertThrowsError(try function())")
XCTAssertEqual(components, [
.token("XCTAssertThrowsError", .call),
.plainText("("),
.token("try", .keyword),
.whitespace(" "),
.token("function", .call),
.plainText("())")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
@ -189,7 +202,8 @@ extension FunctionCallTests {
("testPassingTypeToFunction", testPassingTypeToFunction),
("testPassingBoolToUnnamedArgument", testPassingBoolToUnnamedArgument),
("testIndentedFunctionCalls", testIndentedFunctionCalls),
("testXCTAssertCalls", testXCTAssertCalls)
("testXCTAssertCalls", testXCTAssertCalls),
("testUsingTryKeywordWithinFunctionCall", testUsingTryKeywordWithinFunctionCall)
]
}
}