Correctly highlight comments that are preceded by a comma (#113)

Don’t merge “,” and “/“ pairs when handling delimiters.
This commit is contained in:
John Sundell 2020-06-28 13:33:09 +02:00 committed by GitHub
parent b2b8be4efa
commit 73a4cf178b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -53,7 +53,7 @@ public struct SwiftGrammar: Grammar {
return false
case ("(", _) where delimiterB != ".":
return false
case (".", "/"):
case (".", "/"), (",", "/"):
return false
case ("{", "/"), ("}", "/"):
return false

View File

@ -135,6 +135,35 @@ final class CommentTests: SyntaxHighlighterTestCase {
.plainText("{}")
])
}
func testCommentPrecededByComma() {
let components = highlighter.highlight("""
func find(
string: String,//TODO: Remove
options: Options
)
""")
XCTAssertEqual(components, [
.token("func", .keyword),
.whitespace(" "),
.plainText("find("),
.whitespace("\n "),
.plainText("string:"),
.whitespace(" "),
.token("String", .type),
.plainText(","),
.token("//TODO:", .comment),
.whitespace(" "),
.token("Remove", .comment),
.whitespace("\n "),
.plainText("options:"),
.whitespace(" "),
.token("Options", .type),
.whitespace("\n"),
.plainText(")")
])
}
func testCommentWithNumber() {
let components = highlighter.highlight("// 1")
@ -204,6 +233,7 @@ extension CommentTests {
("testMutliLineDocumentationComment", testMutliLineDocumentationComment),
("testCommentStartingWithPunctuation", testCommentStartingWithPunctuation),
("testCommentEndingWithComma", testCommentEndingWithComma),
("testCommentPrecededByComma", testCommentPrecededByComma),
("testCommentWithNumber", testCommentWithNumber),
("testCommentWithNoWhiteSpaceToPunctuation", testCommentWithNoWhiteSpaceToPunctuation),
("testCommentsNextToCurlyBrackets", testCommentsNextToCurlyBrackets)