From 5f163f2b62613368714d8a1e8b342daaac0f89d5 Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Sat, 20 Sep 2025 20:25:34 +0300 Subject: Fix issue with node name capture, add another test case. --- test/dompa/coordinates_test.cljc | 74 +++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 24 deletions(-) (limited to 'test/dompa') diff --git a/test/dompa/coordinates_test.cljc b/test/dompa/coordinates_test.cljc index eb118d2..d6528a0 100644 --- a/test/dompa/coordinates_test.cljc +++ b/test/dompa/coordinates_test.cljc @@ -5,101 +5,101 @@ (deftest compose-test (testing "Create coordinates" (let [html "
hello
"] - (is (= {:html html + (is (= {:html html :coordinates [[0 4] [5 9] [10 15]]} (coordinates/compose html))))) (testing "Create coordinates with invalid HTML" (let [html "
hello"] - (is (= {:html html + (is (= {:html html :coordinates [[0 4] [5 9]]} (coordinates/compose html)))) (let [html "
hello"] - (is (= {:html html + (is (= {:html html :coordinates [[0 4] [5 9] [10 16]]} (coordinates/compose html)))) (let [html ""] - (is (= {:html html + (is (= {:html html :coordinates [[0 3]]} (coordinates/compose html)))) (let [html "<>"] - (is (= {:html html + (is (= {:html html :coordinates [[0 1]]} (coordinates/compose html))))) (testing "Create coordinates with just text" (let [html "hello"] - (is (= {:html html + (is (= {:html html :coordinates [[0 4]]} (coordinates/compose html))))) (testing "Create coordinates with text starting" (let [html "hello
"] - (is (= {:html html + (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 + (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 + (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 + (is (= {:html html :coordinates [[0 4] [5 9]]} (-> (coordinates/compose html) coordinates/unify)))) (let [html "
hello"] - (is (= {:html html + (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 + (is (= {:html html :coordinates [[0 4]]} (-> (coordinates/compose html) coordinates/unify))))) (testing "Unify coordinates with text starting" (let [html "hello
"] - (is (= {:html html + (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 + (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 + (is (= [{:name :div + :attrs {} + :children [{:name :dompa/text :value "hello"}]}] (-> "
hello
" coordinates/compose @@ -107,13 +107,39 @@ coordinates/->nodes)))) (testing "Create nodes with attributes" - (is (= [{:attrs {:class "some test classes" - :data-attr "something" - :checked true} - :children [{:name :dompa/text - :value "hello"}] - :name :div}] + (is (= [{:name :div + :attrs {:class "some test classes" + :data-attr "something" + :checked true} + :children [{:name :dompa/text + :value "hello"}]}] (-> "
hello
" + coordinates/compose + coordinates/unify + coordinates/->nodes)))) + + (testing "Create nested nodes" + (is (= [{:name :b + :attrs {} + :children [{:name :dompa/text + :value "bold"}]} + {:name :img + :attrs {:src "img.png"}} + {:name :dompa/text + :value "Hello, "} + {:name :span + :attrs {} + :children [{:name :dompa/text + :value "wor"} + {:name :i + :attrs {} + :children [{:name :dompa/text + :value "l"} + {:name :b + :attrs {} + :children [{:name :dompa/text + :value "d"}]}]}]}] + (-> "boldHello, world" coordinates/compose coordinates/unify coordinates/->nodes))))) \ No newline at end of file -- cgit v1.2.3