Fix highlighting for #available checks (#72)

This patch makes availability checks using `#available` highlight correctly,
by treating `#available` like a keyword.
This commit is contained in:
John Sundell 2019-06-18 12:28:11 +02:00 committed by GitHub
parent d978081933
commit 0b22fa3dcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

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

View File

@ -62,6 +62,24 @@ final class PreprocessorTests: SyntaxHighlighterTestCase {
]) ])
} }
func testAvailabilityCheck() {
let components = highlighter.highlight("if #available(iOS 13, *) {}")
XCTAssertEqual(components, [
.token("if", .keyword),
.whitespace(" "),
.token("#available", .keyword),
.plainText("(iOS"),
.whitespace(" "),
.token("13", .number),
.plainText(","),
.whitespace(" "),
.plainText("*)"),
.whitespace(" "),
.plainText("{}")
])
}
func testAllTestsRunOnLinux() { func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests)) XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
} }
@ -72,7 +90,8 @@ extension PreprocessorTests {
return [ return [
("testPreprocessing", testPreprocessing), ("testPreprocessing", testPreprocessing),
("testSelector", testSelector), ("testSelector", testSelector),
("testFunctionAttribute", testFunctionAttribute) ("testFunctionAttribute", testFunctionAttribute),
("testAvailabilityCheck", testAvailabilityCheck)
] ]
} }
} }