Correctly highlight properties after function calls

This patch fixes highlighting in the following scenarios:

```
call().property
call(argument).property
```
This commit is contained in:
John Sundell 2018-08-25 12:56:34 +02:00
parent 8645db8de0
commit 896a56b682
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 return false
} }
guard segment.tokens.previous.isAny(of: ".", "?.") else { guard segment.tokens.previous.isAny(of: ".", "?.", "().", ").") else {
return false 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() { func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests)) XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
} }
@ -65,7 +85,9 @@ extension FunctionCallTests {
return [ return [
("testFunctionCallWithIntegers", testFunctionCallWithIntegers), ("testFunctionCallWithIntegers", testFunctionCallWithIntegers),
("testImplicitInitializerCall", testImplicitInitializerCall), ("testImplicitInitializerCall", testImplicitInitializerCall),
("testExplicitInitializerCall", testExplicitInitializerCall) ("testExplicitInitializerCall", testExplicitInitializerCall),
("testAccessingPropertyAfterFunctionCallWithoutArguments", testAccessingPropertyAfterFunctionCallWithoutArguments),
("testAccessingPropertyAfterFunctionCallWithArguments", testAccessingPropertyAfterFunctionCallWithArguments)
] ]
} }
} }