From dc9b0062b3472ec5227aff271acaaa6f7f1cb56e Mon Sep 17 00:00:00 2001 From: Adam Mertzenich Date: Fri, 8 Mar 2024 23:02:17 -0600 Subject: [PATCH 1/2] 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)) From d5fea4b827653954fed84d4e8f4e11cd7b7a99c0 Mon Sep 17 00:00:00 2001 From: Adam Mertzenich Date: Fri, 8 Mar 2024 23:02:40 -0600 Subject: [PATCH 2/2] fix: find-in-text retun value (string -> hzip-loc) --- src/cljc/hickory/select.cljc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cljc/hickory/select.cljc b/src/cljc/hickory/select.cljc index ad8cfc8..90ef38d 100644 --- a/src/cljc/hickory/select.cljc +++ b/src/cljc/hickory/select.cljc @@ -288,9 +288,11 @@ selected." [re] (fn [hzip-loc] - (some #(re-find re %) (->> (zip/node hzip-loc) - :content - (filter string?))))) + (when (some #(re-find re %) + (->> (zip/node hzip-loc) + :content + (filter string?))) + hzip-loc))) (defn n-moves-until "This selector returns a selector function that selects its argument if