#include #include "html/html.h" TEST_CASE("html::parse returns elements from valid HTML", "[html]") { auto elements = html::parse("

Title

Body

"); REQUIRE(elements.size() >= 2); bool found_h1 = false; bool found_p = false; for (const auto &el : elements) { if (el.tag == "h1" && el.text == "Title") found_h1 = true; if (el.tag == "p" && el.text == "Body") found_p = true; } CHECK(found_h1); CHECK(found_p); } TEST_CASE("html::parse returns empty for empty input", "[html]") { auto elements = html::parse(""); // Empty or minimal — parser may produce an empty body REQUIRE(elements.empty()); } TEST_CASE("html::parse handles nested elements", "[html]") { auto elements = html::parse("
Nested
"); // Parent nodes (body, div) also get text "Nested" via node_text. // Just verify that the span element is present among the results. bool found_span = false; for (const auto &el : elements) { if (el.tag == "span" && el.text == "Nested") { found_span = true; } } CHECK(found_span); } TEST_CASE("html::select finds elements by CSS selector", "[html][select]") { auto matches = html::select("", "li"); REQUIRE(matches.size() == 3); CHECK(matches[0] == "A"); CHECK(matches[1] == "B"); CHECK(matches[2] == "C"); } TEST_CASE("html::select returns empty for no matches", "[html][select]") { auto matches = html::select("

Hello

", "h1"); REQUIRE(matches.empty()); } TEST_CASE("html::select works with class selector", "[html][select]") { auto matches = html::select( R"(
XY
)", ".a"); REQUIRE(matches.size() == 1); CHECK(matches[0] == "X"); }