Fix highlighting for comments that appear next to curly brackets (#105)

This change makes Splash correctly highlight comments that are placed
right next to either an opening or closing curly bracket.
This commit is contained in:
John Sundell 2020-05-22 01:24:29 +02:00 committed by GitHub
parent b6c489c980
commit ec37e1042c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -55,6 +55,8 @@ public struct SwiftGrammar: Grammar {
return false
case (".", "/"):
return false
case ("{", "/"), ("}", "/"):
return false
default:
return true
}

View File

@ -173,6 +173,23 @@ final class CommentTests: SyntaxHighlighterTestCase {
])
}
func testCommentsNextToCurlyBrackets() {
let components = highlighter.highlight("""
call {//commentA
}//commentB
""")
XCTAssertEqual(components, [
.token("call", .call),
.whitespace(" "),
.plainText("{"),
.token("//commentA", .comment),
.whitespace("\n"),
.plainText("}"),
.token("//commentB", .comment)
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
@ -188,7 +205,8 @@ extension CommentTests {
("testCommentStartingWithPunctuation", testCommentStartingWithPunctuation),
("testCommentEndingWithComma", testCommentEndingWithComma),
("testCommentWithNumber", testCommentWithNumber),
("testCommentWithNoWhiteSpaceToPunctuation", testCommentWithNoWhiteSpaceToPunctuation)
("testCommentWithNoWhiteSpaceToPunctuation", testCommentWithNoWhiteSpaceToPunctuation),
("testCommentsNextToCurlyBrackets", testCommentsNextToCurlyBrackets)
]
}
}