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

30 lines
846 B
Swift
Raw Normal View History

2022-12-10 20:36:48 +00:00
//
// 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
2022-12-10 20:42:28 +00:00
highlight(codePtr: codePtr.baseAddress!, codeLen: UInt64(codePtr.count), htmlLenPtr: lenPtr)
2022-12-10 20:36:48 +00:00
}
}
2023-01-02 18:38:12 +00:00
let htmlPtr = UnsafeBufferPointer(start: result, count: Int(len))
2022-12-10 20:36:48 +00:00
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)
}
}