This is a link.
)"; auto tree1 = parser.parse_tree(html1, "https://test.com"); std::cout << " ✓ Title: " << tree1.title << std::endl; std::cout << " ✓ Links found: " << tree1.links.size() << std::endl; if (tree1.title == "Test Page" && tree1.links.size() == 1) { std::cout << " ✓ Basic parsing passed" << std::endl; } else { std::cout << " ✗ Basic parsing failed" << std::endl; return 1; } // Test 2: Link URL resolution std::cout << "\n[Test 2] Link URL resolution..." << std::endl; std::string html2 = R"( Relative Absolute Same dir )"; auto tree2 = parser.parse_tree(html2, "https://base.com/dir/"); std::cout << " Found " << tree2.links.size() << " links:" << std::endl; for (const auto& link : tree2.links) { std::cout << " - " << link.url << std::endl; } if (tree2.links.size() == 3) { std::cout << " ✓ Link resolution passed" << std::endl; } else { std::cout << " ✗ Link resolution failed" << std::endl; return 1; } // Test 3: Form parsing std::cout << "\n[Test 3] Form parsing..." << std::endl; std::string html3 = R"( )"; auto tree3 = parser.parse_tree(html3, "https://form.com"); std::cout << " Form fields found: " << tree3.form_fields.size() << std::endl; if (tree3.form_fields.size() >= 2) { std::cout << " ✓ Form parsing passed" << std::endl; } else { std::cout << " ✗ Form parsing failed" << std::endl; return 1; } // Test 4: Image parsing std::cout << "\n[Test 4] Image parsing..." << std::endl; std::string html4 = R"(
)";
auto tree4 = parser.parse_tree(html4, "https://images.com/page/");
std::cout << " Images found: " << tree4.images.size() << std::endl;
if (tree4.images.size() == 2) {
std::cout << " ✓ Image parsing passed" << std::endl;
} else {
std::cout << " ✗ Image parsing failed" << std::endl;
return 1;
}
// Test 5: Unicode content
std::cout << "\n[Test 5] Unicode content..." << std::endl;
std::string html5 = R"(
한국어 테스트
)"; auto tree5 = parser.parse_tree(html5, "https://unicode.com"); std::cout << " ✓ Title: " << tree5.title << std::endl; if (tree5.title == "中文标题") { std::cout << " ✓ Unicode parsing passed" << std::endl; } else { std::cout << " ✗ Unicode parsing failed" << std::endl; return 1; } std::cout << "\n=== All HTML parser tests passed! ===" << std::endl; return 0; }