Support the ‘unowned’ keyword (#95)

This change makes Splash correctly highlight the `unowned` keyword
when used within closure capture lists.
This commit is contained in:
John Sundell 2020-01-29 10:34:17 +01:00 committed by GitHub
parent b7e9141e1b
commit bb8655e6d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 2 deletions

View File

@ -75,7 +75,7 @@ private extension SwiftGrammar {
"lazy", "subscript", "defer", "inout", "while",
"continue", "fallthrough", "repeat", "indirect",
"deinit", "is", "#file", "#line", "#function",
"dynamic", "some", "#available", "convenience"
"dynamic", "some", "#available", "convenience", "unowned"
] as Set<String>).union(accessControlKeywords)
static let accessControlKeywords: Set<String> = [

View File

@ -201,6 +201,46 @@ final class ClosureTests: SyntaxHighlighterTestCase {
])
}
func testClosureWithWeakSelfCaptureList() {
let components = highlighter.highlight("closure { [weak self] in }")
XCTAssertEqual(components, [
.token("closure", .call),
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
.plainText("["),
.token("weak", .keyword),
.whitespace(" "),
.token("self", .keyword),
.plainText("]"),
.whitespace(" "),
.token("in", .keyword),
.whitespace(" "),
.plainText("}")
])
}
func testClosureWithUnownedSelfCaptureList() {
let components = highlighter.highlight("closure { [unowned self] in }")
XCTAssertEqual(components, [
.token("closure", .call),
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
.plainText("["),
.token("unowned", .keyword),
.whitespace(" "),
.token("self", .keyword),
.plainText("]"),
.whitespace(" "),
.token("in", .keyword),
.whitespace(" "),
.plainText("}")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
@ -218,7 +258,9 @@ extension ClosureTests {
("testClosureWithInoutArgument", testClosureWithInoutArgument),
("testPassingClosureAsArgument", testPassingClosureAsArgument),
("testNestedEscapingClosure", testNestedEscapingClosure),
("testClosureArgumentShorthands", testClosureArgumentShorthands)
("testClosureArgumentShorthands", testClosureArgumentShorthands),
("testClosureWithWeakSelfCaptureList", testClosureWithWeakSelfCaptureList),
("testClosureWithUnownedSelfCaptureList", testClosureWithUnownedSelfCaptureList)
]
}
}