Files
ghostgram/submodules/TextFormat/Tests/SyntaxHighlightLanguageCasingTests.swift
ichmagmaus111andClaude Opus 5.5 0622057a4f Ghostgram: open-source release
Ghostgram for iOS, rebuilt from scratch on Telegram iOS 13.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 17:57:09 +01:00

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)
}
}