<commit_before>(ns hiccup-find.core-test
  (:require #?(:cljs [cljs.test :refer-macros [deftest is]]
               :clj [clojure.test :refer [deftest is]])
            [hiccup-find.core :as hf]))

(deftest test-hiccup-form-matches?
  (is (hf/hiccup-form-matches? :p [:p.lol]))
  (is (hf/hiccup-form-matches? :p [:p {:class "lol"}]))
  (is (hf/hiccup-form-matches? :p.lol [:p.lol]))
  (is (hf/hiccup-form-matches? :p.lol [:p {:class "lol"}]))
  (is (hf/hiccup-form-matches? :p.lol [:p {:class "lol haha"}]))
  (is (hf/hiccup-form-matches? :p.lol.haha [:p {:class "lol haha"}]))
  (is (hf/hiccup-form-matches? :p.lol.haha [:p.lol {:class "haha"}]))
  (is (hf/hiccup-form-matches? :p.lol.haha [:p.haha {:class "lol"}]))
  (is (hf/hiccup-form-matches? :p.lol.haha [:p.haha.lol {}]))
  (is (not (hf/hiccup-form-matches? :p.lol.haha [:p {:class "lol"}])))
  (is (hf/hiccup-form-matches? :p.lol#ok [:p {:class "lol" :id "ok"}]))
  (is (hf/hiccup-form-matches? :p.lol [:p.haha {:class ["lol"]}]))
  (is (hf/hiccup-form-matches? :p.haha.lol [:p.haha {:class ["lol"]}]))
  (is (hf/hiccup-form-matches? :p.lol.haha.hihi [:p.haha {:class ["hihi" "lol"]}]))
  (is (hf/hiccup-form-matches? :p.lol [:p.haha {:class ["hihi" "lol"]}])))

(deftest test-hiccup-symbol-matches?
  (is (hf/hiccup-symbol-matches? :p :p.class))
  (is (not (hf/hiccup-symbol-matches? :p.class :p)))
  (is (hf/hiccup-symbol-matches? :.class :p.class.more))
  (is (hf/hiccup-symbol-matches? :p.more.class :p.class.more)))

(deftest test-hiccup-find
  (is (= (list [:p.image "Yes 1"]
               [:p.image "Yes 2"])
         (hf/hiccup-find
          [:p.image]
          [:html
           [:body
            [:p.img "No"]
            [:p.image "Yes 1"]
            [:p.images "No"]
            [:div.image
             [:p.image "Yes 2"]]]])))

  (is (= (list [:p {:class "image"} "Yes 1"]
               [:p {:class "image"} "Yes 2"])
         (hf/hiccup-find
          [:p.image]
          [:html
           [:body
            [:p.img "No"]
            [:p {:class "image"} "Yes 1"]
            [:p.images "No"]
            [:div.image
             [:p {:class "image"} "Yes 2"]]]])))

  (is (= (list [:p "Yes 1"]
               [:p "Yes 2"])
         (hf/hiccup-find
          [:div :p]
          [:html
           [:body
            [:p "No"]
            [:div [:p "Yes 1"]]
            [:div
             [:table
              [:tr
               [:td
                [:p "Yes 2"]]]]]]])))

  (is (= (list [:p "Yes 1"]
               [:p "Yes 2"]
               [:p "Yes 3"])
         (hf/hiccup-find
          [:div :p]
          [:html
           [:body
            [:div
             [:table
              [:tr
               [:td
                [:p "Yes 1"]]]]]
            [:div
             [:table
              [:tr
               [:td
                [:p "Yes 2"]]]
              [:tr
               [:td
                [:p "Yes 3"]]]]]]])))

  (is (= (list [:p "Yes 1"]
               [:p "Yes 2"]
               [:p "Yes 3"])
         (hf/hiccup-find
          [:div :p]
          [:html
           [:body
            [:div
             [:table
              [:tr
               [:td
                [:p "Yes 1"]]]]]
            [:div
             [:table
              [:tr
               [:td
                [:p "Yes 2"]]]
              [:tr
               [:td
                [:p "Yes 3"]]]]]]]))))

(deftest test-hiccup-text
  (is (= "Text here"
         (hf/hiccup-text [:p "Text here"])))

  (is (= "Text here"
         (hf/hiccup-text [:p [:span "Text here"]])))

  (is (= "Text here"
         (hf/hiccup-text [:p {:class "something"} "Text here"])))

  (is (= "Text here"
         (hf/hiccup-text [:p {:class "something"} "Text " [:strong "here"]])))

  (is (= (str "Welcome, earthling\n"
              "Hope you enjoy your stay")
         (hf/hiccup-text
          [:html
           [:body
            [:h1 "Welcome, earthling"]
            [:p "Hope you " [:strong "enjoy"] " your stay"]]])))

  (is (= "Number 42"
         (hf/hiccup-text
          [:html
           [:body
            [:p "Number " [:strong 42]]]]))))

(deftest test-hiccup-string
  (is (= "Welcome, earthling Hope you enjoy your stay"
         (hf/hiccup-string
          [:html
           [:body
            [:h1 "Welcome, earthling"]
            [:p "Hope you " [:strong "enjoy"] " your stay"]]])))

  (is (= "Welcome! Hope you enjoy your stay"
         (hf/hiccup-string
          [:html
           [:body
            [:h1 "Welcome!"]
            [:p "Hope you   " [:strong "enjoy"] " your stay"]]]))))<commit_msg>Un-yoda tests<commit_after>(ns hiccup-find.core-test
  (:require #?(:cljs [cljs.test :refer-macros [deftest is]]
               :clj [clojure.test :refer [deftest is]])
            [hiccup-find.core :as hf]))

(deftest test-hiccup-form-matches?
  (is (hf/hiccup-form-matches? :p [:p.lol]))
  (is (hf/hiccup-form-matches? :p [:p {:class "lol"}]))
  (is (hf/hiccup-form-matches? :p.lol [:p.lol]))
  (is (hf/hiccup-form-matches? :p.lol [:p {:class "lol"}]))
  (is (hf/hiccup-form-matches? :p.lol [:p {:class "lol haha"}]))
  (is (hf/hiccup-form-matches? :p.lol.haha [:p {:class "lol haha"}]))
  (is (hf/hiccup-form-matches? :p.lol.haha [:p.lol {:class "haha"}]))
  (is (hf/hiccup-form-matches? :p.lol.haha [:p.haha {:class "lol"}]))
  (is (hf/hiccup-form-matches? :p.lol.haha [:p.haha.lol {}]))
  (is (not (hf/hiccup-form-matches? :p.lol.haha [:p {:class "lol"}])))
  (is (hf/hiccup-form-matches? :p.lol#ok [:p {:class "lol" :id "ok"}]))
  (is (hf/hiccup-form-matches? :p.lol [:p.haha {:class ["lol"]}]))
  (is (hf/hiccup-form-matches? :p.haha.lol [:p.haha {:class ["lol"]}]))
  (is (hf/hiccup-form-matches? :p.lol.haha.hihi [:p.haha {:class ["hihi" "lol"]}]))
  (is (hf/hiccup-form-matches? :p.lol [:p.haha {:class ["hihi" "lol"]}])))

(deftest test-hiccup-symbol-matches?
  (is (hf/hiccup-symbol-matches? :p :p.class))
  (is (not (hf/hiccup-symbol-matches? :p.class :p)))
  (is (hf/hiccup-symbol-matches? :.class :p.class.more))
  (is (hf/hiccup-symbol-matches? :p.more.class :p.class.more)))

(deftest test-hiccup-find
  (is (= (hf/hiccup-find
          [:p.image]
          [:html
           [:body
            [:p.img "No"]
            [:p.image "Yes 1"]
            [:p.images "No"]
            [:div.image
             [:p.image "Yes 2"]]]])
         (list [:p.image "Yes 1"]
               [:p.image "Yes 2"])))

  (is (= (hf/hiccup-find
          [:p.image]
          [:html
           [:body
            [:p.img "No"]
            [:p {:class "image"} "Yes 1"]
            [:p.images "No"]
            [:div.image
             [:p {:class "image"} "Yes 2"]]]])
         (list [:p {:class "image"} "Yes 1"]
               [:p {:class "image"} "Yes 2"])))

  (is (= (hf/hiccup-find
          [:div :p]
          [:html
           [:body
            [:p "No"]
            [:div [:p "Yes 1"]]
            [:div
             [:table
              [:tr
               [:td
                [:p "Yes 2"]]]]]]])
         (list [:p "Yes 1"]
               [:p "Yes 2"])))

  (is (= (hf/hiccup-find
          [:div :p]
          [:html
           [:body
            [:div
             [:table
              [:tr
               [:td
                [:p "Yes 1"]]]]]
            [:div
             [:table
              [:tr
               [:td
                [:p "Yes 2"]]]
              [:tr
               [:td
                [:p "Yes 3"]]]]]]])
         (list [:p "Yes 1"]
               [:p "Yes 2"]
               [:p "Yes 3"])))

  (is (= (hf/hiccup-find
          [:div :p]
          [:html
           [:body
            [:div
             [:table
              [:tr
               [:td
                [:p "Yes 1"]]]]]
            [:div
             [:table
              [:tr
               [:td
                [:p "Yes 2"]]]
              [:tr
               [:td
                [:p "Yes 3"]]]]]]])
         (list [:p "Yes 1"]
               [:p "Yes 2"]
               [:p "Yes 3"]))))

(deftest test-hiccup-text
  (is (= (hf/hiccup-text [:p "Text here"])
         "Text here"))

  (is (= (hf/hiccup-text [:p [:span "Text here"]])
         "Text here"))

  (is (= (hf/hiccup-text [:p {:class "something"} "Text here"])
         "Text here"))

  (is (= (hf/hiccup-text [:p {:class "something"} "Text " [:strong "here"]])
         "Text here"))

  (is (= (hf/hiccup-text
          [:html
           [:body
            [:h1 "Welcome, earthling"]
            [:p "Hope you " [:strong "enjoy"] " your stay"]]])
         (str "Welcome, earthling\n"
              "Hope you enjoy your stay")))

  (is (= (hf/hiccup-text
          [:html
           [:body
            [:p "Number " [:strong 42]]]])
         "Number 42")))

(deftest test-hiccup-string
  (is (= (hf/hiccup-string
          [:html
           [:body
            [:h1 "Welcome, earthling"]
            [:p "Hope you " [:strong "enjoy"] " your stay"]]])
         "Welcome, earthling Hope you enjoy your stay"))

  (is (= (hf/hiccup-string
          [:html
           [:body
            [:h1 "Welcome!"]
            [:p "Hope you   " [:strong "enjoy"] " your stay"]]])
         "Welcome! Hope you enjoy your stay")))
{'fraction_non_alphanumeric': 0.21461336828309305, 'fraction_numerical': 0.006771515945827872, 'mean_word_length': 1.5108308198519331, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3287637', 'n_tokens_mistral': 3712, 'n_tokens_neox': 3390, 'n_words': 780}