Merge pull request #1 from JohnSundell/function-call-property-fix

Correctly highlight properties after function calls
This commit is contained in:
John Sundell 2018-08-25 13:00:29 +02:00 committed by GitHub
commit 54598263bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View File

@ -193,7 +193,7 @@ private extension SwiftGrammar {
}
}
return segment.tokens.next.isAny(of: "(", "()", "())", "(.", "({")
return segment.tokens.next.isAny(of: "(", "()", "())", "(.", "({", "().")
}
}
@ -268,7 +268,7 @@ private extension SwiftGrammar {
return false
}
guard segment.tokens.previous.isAny(of: ".", "?.") else {
guard segment.tokens.previous.isAny(of: ".", "?.", "().", ").") else {
return false
}

View File

@ -55,6 +55,26 @@ final class FunctionCallTests: SyntaxHighlighterTestCase {
])
}
func testAccessingPropertyAfterFunctionCallWithoutArguments() {
let components = highlighter.highlight("call().property")
XCTAssertEqual(components, [
.token("call", .call),
.plainText("()."),
.token("property", .property)
])
}
func testAccessingPropertyAfterFunctionCallWithArguments() {
let components = highlighter.highlight("call(argument).property")
XCTAssertEqual(components, [
.token("call", .call),
.plainText("(argument)."),
.token("property", .property)
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
@ -65,7 +85,9 @@ extension FunctionCallTests {
return [
("testFunctionCallWithIntegers", testFunctionCallWithIntegers),
("testImplicitInitializerCall", testImplicitInitializerCall),
("testExplicitInitializerCall", testExplicitInitializerCall)
("testExplicitInitializerCall", testExplicitInitializerCall),
("testAccessingPropertyAfterFunctionCallWithoutArguments", testAccessingPropertyAfterFunctionCallWithoutArguments),
("testAccessingPropertyAfterFunctionCallWithArguments", testAccessingPropertyAfterFunctionCallWithArguments)
]
}
}