From 9d64cbe122f94b550cf2292543e80ce8e5de74e6 Mon Sep 17 00:00:00 2001 From: Adam Mertzenich Date: Fri, 8 Mar 2024 23:02:17 -0600 Subject: [PATCH] tests: find-in-text in a child selector assertion --- test/cljc/hickory/test/select.cljc | 70 ++++++++++++++++-------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/test/cljc/hickory/test/select.cljc b/test/cljc/hickory/test/select.cljc index cd92257..47474e1 100644 --- a/test/cljc/hickory/test/select.cljc +++ b/test/cljc/hickory/test/select.cljc @@ -8,40 +8,38 @@ (def html1 " - - - - -

Heading

-

Paragraph

-Link -
- -
Div
-
- -Span -
- -") + + + + +

Heading

+

Paragraph

+ Link +
+ +
Div
+
+ + Span +
+ + ") (def html2 " - - - -

Paragraph 1

-

Paragraph 2

-

Paragraph 3

-

Paragraph 4

-

Paragraph 5

-

Paragraph 6

-

Paragraph 7

-

Paragraph 8

- -") + + + +

Paragraph 1

+

Paragraph 2

+

Paragraph 3

+

Paragraph 4

+

Paragraph 5

+

Paragraph 6

+

Paragraph 7

+

Paragraph 8

+ + ") (deftest select-next-loc-test (testing "The select-next-loc function." @@ -232,7 +230,15 @@ cool\">Span (= :h1 (-> selection first :tag))))) (let [selection (select/select (select/find-in-text #"Div") htree)] (is (and (= 1 (count selection)) - (= :div (-> selection first :tag)))))) + (= :div (-> selection first :tag))))) + (let [selection-locs (select/select-locs + (select/child (select/tag :body) + (select/find-in-text #"Paragraph")) + htree) + selection (mapv zip/node selection-locs)] + (is (and (= 1 (count selection)) + (= :p (-> selection first :tag)) + (= :body (-> selection-locs first zip/up zip/node :tag)))))) (let [htree (hickory/as-hickory (hickory/parse html2))] (let [selection (select/select (select/find-in-text #"Paragraph") htree)] (is (and (= 8 (count selection))