@@ -10,7 +10,7 @@
#include "css/property_id.h"
#include "dom/dom.h"
#include "dom/xpath.h"
#include "etest/etest.h"
#include "etest/etest2.h"
#include "style/styled_node.h"
#include <cstddef>
@@ -19,8 +19,6 @@
#include <utility>
#include <vector>
using etest::expect;
using etest::expect_eq;
using namespace std::literals;
namespace {
@@ -37,7 +35,8 @@ void set_up_parent_ptrs(style::StyledNode &parent) {
} // namespace
int main() {
etest::test("text", [] {
etest::Suite s{};
s.add_test("text", [](etest::IActions &a) {
dom::Node dom_root =
dom::Element{"html", {}, {dom::Element{"body", {}, {dom::Text{"hello"}, dom::Text{"goodbye"}}}}};
@@ -69,13 +68,13 @@ int main() {
}}};
auto layout_root = layout::create_layout(style_root, 100);
expect(expected_layout == layout_root);
a.expect(expected_layout == layout_root);
expect_eq(expected_layout.children.at(0).children.at(0).children.at(0).text(), "hello");
expect_eq(expected_layout.children.at(0).children.at(0).children.at(1).text(), "goodbye");
a.expect_eq(expected_layout.children.at(0).children.at(0).children.at(0).text(), "hello");
a.expect_eq(expected_layout.children.at(0).children.at(0).children.at(1).text(), "goodbye");
});
etest::test("box_at_position", [] {
s.add_test("box_at_position", [](etest::IActions &a) {
dom::Node dom = dom::Element{"dummy"};
style::StyledNode style{dom, {{css::PropertyId::Display, "block"}}};
std::vector<layout::LayoutBox> children{
@@ -91,20 +90,20 @@ int main() {
},
};
expect(box_at_position(layout, {-1, -1}) == nullptr);
expect(box_at_position(layout, {101, 101}) == nullptr);
a.expect(box_at_position(layout, {-1, -1}) == nullptr);
a.expect(box_at_position(layout, {101, 101}) == nullptr);
expect(box_at_position(layout, {100, 100}) == &layout);
expect(box_at_position(layout, {0, 0}) == &layout);
a.expect(box_at_position(layout, {100, 100}) == &layout);
a.expect(box_at_position(layout, {0, 0}) == &layout);
// We don't want to end up in anonymous blocks, so this should return its parent.
expect(box_at_position(layout, {31, 31}) == &layout.children[0]);
a.expect(box_at_position(layout, {31, 31}) == &layout.children[0]);
expect(box_at_position(layout, {75, 75}) == &layout.children[0]);
expect(box_at_position(layout, {47, 47}) == &layout.children[0].children[1]);
a.expect(box_at_position(layout, {75, 75}) == &layout.children[0]);
a.expect(box_at_position(layout, {47, 47}) == &layout.children[0].children[1]);
});
etest::test("xpath", [] {
s.add_test("xpath", [](etest::IActions &a) {
dom::Node html_node = dom::Element{"html"s};
dom::Node div_node = dom::Element{"div"s};
dom::Node p_node = dom::Element{"p"s};
@@ -125,20 +124,20 @@ int main() {
auto layout = layout::create_layout(styled_node, 123).value();
// Verify that we have a shady anon-box to deal with in here.
expect_eq(layout.children.size(), std::size_t{2});
a.expect_eq(layout.children.size(), std::size_t{2});
auto const &anon_block = layout.children.at(1);
using NodeVec = std::vector<layout::LayoutBox const *>;
expect_eq(dom::nodes_by_xpath(layout, "/html"), NodeVec{&layout});
expect_eq(dom::nodes_by_xpath(layout, "/html/div"), NodeVec{&layout.children[0], &anon_block.children[1]});
expect_eq(dom::nodes_by_xpath(layout, "/html/div/"), NodeVec{});
expect_eq(dom::nodes_by_xpath(layout, "/html/div/p"), NodeVec{&anon_block.children[1].children[0]});
expect_eq(dom::nodes_by_xpath(layout, "/htm/div"), NodeVec{});
expect_eq(dom::nodes_by_xpath(layout, "//div"), NodeVec{&layout.children[0], &anon_block.children[1]});
a.expect_eq(dom::nodes_by_xpath(layout, "/html"), NodeVec{&layout});
a.expect_eq(dom::nodes_by_xpath(layout, "/html/div"), NodeVec{&layout.children[0], &anon_block.children[1]});
a.expect_eq(dom::nodes_by_xpath(layout, "/html/div/"), NodeVec{});
a.expect_eq(dom::nodes_by_xpath(layout, "/html/div/p"), NodeVec{&anon_block.children[1].children[0]});
a.expect_eq(dom::nodes_by_xpath(layout, "/htm/div"), NodeVec{});
a.expect_eq(dom::nodes_by_xpath(layout, "//div"), NodeVec{&layout.children[0], &anon_block.children[1]});
});
etest::test("to_string", [] {
s.add_test("to_string", [](etest::IActions &a) {
auto body = dom::Element{"body", {}, {dom::Element{"p", {}, {dom::Text{"!!!\n\n!!!"}}}, dom::Element{"p"}}};
dom::Node dom_root = dom::Element{.name{"html"}, .children{std::move(body)}};
@@ -183,8 +182,8 @@ int main() {
" inline {0,0,35,25} {0,0,0,0} {0,0,0,0}\n"
" p\n"
" block {0,30,35,0} {5,15,0,0} {0,0,0,0}\n";
expect_eq(to_string(layout::create_layout(style_root, 0).value()), expected);
a.expect_eq(to_string(layout::create_layout(style_root, 0).value()), expected);
});
return etest::run_all_tests();
return s.run();
}