splash-rs/highlight-swift/Tests/highlight-swift-tests/HighlightTests.swift

30 lines
846 B
Swift

//
// HighlightTests.swift
//
//
// Created by Shadowfacts on 12/10/22.
//
import XCTest
@testable import highlight_swift
class HighlightTests: XCTestCase {
static var allTests = [
("testHighlight", testHighlight),
]
func testHighlight() {
var code = "1+1"
var len: UInt64 = 0
let result = code.withUTF8 { codePtr in
withUnsafeMutablePointer(to: &len) { lenPtr in
highlight(codePtr: codePtr.baseAddress!, codeLen: UInt64(codePtr.count), htmlLenPtr: lenPtr)
}
}
let htmlPtr = UnsafeBufferPointer(start: result, count: Int(len))
let data = Data(buffer: htmlPtr)
let expected = "<span class=\"hl-num\">1</span>+<span class=\"hl-num\">1</span>"
XCTAssertEqual(String(data: data, encoding: .utf8), expected)
}
}