import PlakCore
import Testing
@Suite struct CodeHighlighterTests {
/// The tokens of `body` as (kind, text) pairs.
private func pieces(_ body: String, _ kind: FenceKind) -> [(CodeTokenKind, String)] {
let units = Array(body.utf16)
return CodeHighlighter.tokens(body, kind: kind).map { token in
(token.kind, String(decoding: units[token.range], as: UTF16.self))
}
}
private func expect(_ body: String, _ kind: FenceKind, _ expected: [(CodeTokenKind, String)]) {
let found = pieces(body, kind)
#expect(found.map(\.0) == expected.map(\.0), "\(found)")
#expect(found.map(\.1) == expected.map(\.1), "\(found)")
}
@Test("PHP: tags, comments, variables, strings, numbers, keywords and a heredoc")
func php() {
let body = ""#, .xml, [
(.comment, ""), (.tag, ""), (.string, ""), (.tag, ""),
])
}
@Test("ranges count UTF-16 units, so text before a token can hold any character")
func utf16() {
let tokens = CodeHighlighter.tokens("{\"é😀\": 1}", kind: .json)
#expect(tokens.map(\.range) == [1..<6, 8..<9])
}
}