mirror of
https://github.com/ichmagmaus111/ghostgram.git
synced 2026-11-03 22:27:13 +01:00
Ghostgram for iOS, rebuilt from scratch on Telegram iOS 13.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.9 KiB
Swift
40 lines
1.9 KiB
Swift
import XCTest
|
|
import SwiftSignalKit
|
|
@testable import TextFormat
|
|
|
|
/// End-to-end against the real libprisma engine (the grammars ship with the library).
|
|
final class SyntaxHighlightLanguageCasingTests: XCTestCase {
|
|
private func entities(language: String, text: String) -> [MessageSyntaxHighlight.Entity] {
|
|
let spec = CachedMessageSyntaxHighlight.Spec(language: language, text: text)
|
|
var result: [MessageSyntaxHighlight.Entity] = []
|
|
let expectation = XCTestExpectation(description: "highlight")
|
|
let disposable = asyncStanaloneSyntaxHighlight(current: nil, specs: [spec]).start(next: { value in
|
|
result = value.values[spec]?.entities ?? []
|
|
expectation.fulfill()
|
|
})
|
|
wait(for: [expectation], timeout: 10.0)
|
|
disposable.dispose()
|
|
return result
|
|
}
|
|
|
|
/// The control: the engine works and this text has something to colour.
|
|
func testLowercaseLanguageIsHighlighted() {
|
|
XCTAssertFalse(entities(language: "swift", text: "let x = 1").isEmpty,
|
|
"precondition: libprisma highlights `swift`")
|
|
}
|
|
|
|
/// `LanguageTree::find` is an exact std::map lookup and prisma's grammar keys are lowercase, so a
|
|
/// capitalized language silently produced NO tokens — and the code-block language field stores what
|
|
/// the author typed, so "Swift" reaches this path routinely.
|
|
func testCapitalizedLanguageIsHighlightedTheSame() {
|
|
XCTAssertEqual(entities(language: "Swift", text: "let x = 1").count,
|
|
entities(language: "swift", text: "let x = 1").count,
|
|
"a capitalized language must resolve to the same grammar")
|
|
}
|
|
|
|
func testSurroundingWhitespaceInTheLanguageIsIgnored() {
|
|
XCTAssertEqual(entities(language: " swift ", text: "let x = 1").count,
|
|
entities(language: "swift", text: "let x = 1").count)
|
|
}
|
|
}
|