//
// Test.swift
// HRW
//
// Created by Isaac Paul on 9/16/25.
// Non-commercial license, see LICENSE.MD in the project root for details
//
import XCTest
@testable import HRW
let test = """
My First Heading
My first paragraph.
"""
let test2 = """
Unload Event Example
Welcome to my page!
This is some content within the body.
"""
public extension HTMLNode {
func expectChild(_ type:T.Type, _ index:Int) throws -> T {
if (children.count == 0) {
throw AppError("No children")
}
if (index >= children.count) {
throw AppError("No child at index \(index)")
}
let child = children[index]
guard let result = child as? T else {
throw AppError("Child is not correct expected type of \(String(describing: type))")
}
return result
}
}
final class HRWTests: XCTestCase {
func testExample() throws {
guard let xmlReader = XMLParser(str: test) else { throw EmptyStringError() }
let rootNodes = try xmlReader.readObjects()
let htmlRoot = rootNodes[2]
let cType = htmlRoot as! Html
let body = try cType.expectChild(Body.self, 0)
let h1 = try body.expectChild(H1.self, 1)
let text = try h1.expectChild(HTMLText.self, 0)
XCTAssertEqual(text.content, "My First Heading")
print(htmlRoot.toString())
}
func testSerialization() throws {
guard let xmlReader = XMLParser(str: test2) else { throw EmptyStringError() }
let rootNodes = try xmlReader.readObjects()
let htmlRoot = rootNodes[2]
print(htmlRoot.toString())
}
func testBindingGenerator() throws {
IHtmlNodeContainerUtility.sharedInstance.defaultBaseDir = "/Users/isaacpaul/Projects/swift-projects/HRW/Tests/HRWTests"
let idk = try Example()
print(idk.error_container.renderAttributes())
idk.rootNode.accept_charset = nil
}
}