From 9f31cc6a5aae83f7986e733603e62e91eae31196 Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Sat, 20 Sep 2025 19:58:00 +0300 Subject: Many fixes to coordinates logic in capturing attributes, and more tests. Coordinates ns is shaping up well. --- test/dompa/coordinates_test.cljc | 118 ++++++++++++++++++++++++++++++++++----- 1 file changed, 103 insertions(+), 15 deletions(-) (limited to 'test/dompa/coordinates_test.cljc') diff --git a/test/dompa/coordinates_test.cljc b/test/dompa/coordinates_test.cljc index a827968..eb118d2 100644 --- a/test/dompa/coordinates_test.cljc +++ b/test/dompa/coordinates_test.cljc @@ -4,28 +4,116 @@ (deftest compose-test (testing "Create coordinates" - (is (= [[0 4] [5 9] [10 15]] - (coordinates/compose "
hello
")))) + (let [html "
hello
"] + (is (= {:html html + :coordinates [[0 4] [5 9] [10 15]]} + (coordinates/compose html))))) (testing "Create coordinates with invalid HTML" - (is (= [[0 4] [5 9]] - (coordinates/compose "
hello"))) + (let [html "
hello"] + (is (= {:html html + :coordinates [[0 4] [5 9]]} + (coordinates/compose html)))) - (is (= [] - (coordinates/compose "hello"] + (is (= {:html html + :coordinates [[0 4] [5 9] [10 16]]} + (coordinates/compose html)))) - (is (= [[0 3]] - (coordinates/compose "div>"))) + (let [html "")))) + (let [html "div>"] + (is (= {:html html + :coordinates [[0 3]]} + (coordinates/compose html)))) + + (let [html "<>"] + (is (= {:html html + :coordinates [[0 1]]} + (coordinates/compose html))))) (testing "Create coordinates with just text" - (is (= [[0 4]] - (coordinates/compose "hello")))) + (let [html "hello"] + (is (= {:html html + :coordinates [[0 4]]} + (coordinates/compose html))))) (testing "Create coordinates with text starting" - (is (= [[0 4] [5 9] [10 15]] - (coordinates/compose "hello
"))))) + (let [html "hello
"] + (is (= {:html html + :coordinates [[0 4] [5 9] [10 15]]} + (coordinates/compose html))))) + + (testing "Create coordinates with text ending" + (let [html "
hello"] + (is (= {:html html + :coordinates [[0 4] [5 10] [11 15]]} + (coordinates/compose html)))))) + +(deftest unify-test + (testing "Unify coordinates" + (let [html "
hello
"] + (is (= {:html html + :coordinates [[0 15] [5 9]]} + (-> (coordinates/compose html) + coordinates/unify))))) + + (testing "Unify coordinates with invalid HTML" + (let [html "
hello"] + (is (= {:html html + :coordinates [[0 4] [5 9]]} + (-> (coordinates/compose html) + coordinates/unify)))) + + (let [html "
hello"] + (is (= {:html html + :coordinates [[0 4] [5 9]]} + (-> (coordinates/compose html) + coordinates/unify))))) + + (testing "Unify coordinates with just text" + (let [html "hello"] + (is (= {:html html + :coordinates [[0 4]]} + (-> (coordinates/compose html) + coordinates/unify))))) + + (testing "Unify coordinates with text starting" + (let [html "hello
"] + (is (= {:html html + :coordinates [[0 4] [5 15]]} + (-> (coordinates/compose html) + coordinates/unify))))) + + (testing "Unify coordinates with text ending" + (let [html "
hello"] + (is (= {:html html + :coordinates [[0 10] [11 15]]} + (-> (coordinates/compose html) + coordinates/unify)))))) + +(deftest nodes-test + (testing "Create nodes" + (is (= [{:name :div + :attrs {} + :children [{:name :dompa/text + :value "hello"}]}] + (-> "
hello
" + coordinates/compose + coordinates/unify + coordinates/->nodes)))) -(deftest unify-test) \ No newline at end of file + (testing "Create nodes with attributes" + (is (= [{:attrs {:class "some test classes" + :data-attr "something" + :checked true} + :children [{:name :dompa/text + :value "hello"}] + :name :div}] + (-> "
hello
" + coordinates/compose + coordinates/unify + coordinates/->nodes))))) \ No newline at end of file -- cgit v1.2.3