<commit_before>(ns howl.core-test
  "Test core functions."
  (:require [clojure.test :refer :all]
            [clojure.string :as string]
            [howl.core :refer :all]))

(deftest test-locate
  (testing "file, number, line"
    (is (= (locate {:file-name "local" :line-number 3 :line "FOO"})
           "in 'local' at '3':\nFOO")))
  (testing "number and line"
    (is (= (locate {:line-number 3 :line "FOO"})
           "at '3':\nFOO")))
  (testing "number and block"
    (is (= (locate {:line-number 3 :block #{"FOO"}})
           "at '3':\n#{\"FOO\"}")))
  (testing "just state"
    (is (= (locate :just-a-state)
           ":just-a-state"))))

(def test-merge "
A
  indented
   
  (that was a blank line)

B
C
  ")

(deftest test-merge-lines
  (testing "merge line"
    (is (= (merge-line {} "1")
           {:block {:line ""}
            :line-number 1
            :merging-lines ["1"]}))
    (is (= (merge-line {:merging-lines ["1"]} "2")
           {:block {:line "1"}
            :line-number 2
            :merging-lines ["2"]}))
    (is (= (merge-line
            {:merging-lines ["1"]
             :line-number 10}
            "2")
           {:block {:line "1"}
            :line-number 11
            :merging-lines ["2"]})))
  #_(testing "merge lines"
    (is (= (transduce
            (merge-lines "test")
            conj
            (line-seq (java.io.BufferedReader. (java.io.StringReader. test-merge))))
           [["test" 1 ""]
            ["test" 2 "A\nindented\n \n(that was a blank line)\n"]
            ["test" 7 "B"]
            ["test" 8 "C\n"]]))))

(deftest test-parse
  (testing "basics"
    (is (= (parse-block {:block {:line "BASE http://foo.com"}})
           {:block
            {:line "BASE http://foo.com"
             :parse
             [:BASE_BLOCK
              "BASE"
              [:SPACES " "]
              [:BASE [:ABSOLUTE_IRI "http://foo.com"]]
              [:EOL ""]]}}))))

(deftest test-annotate
  (testing "basics"
    (is (= (annotate-block
           {:block
            {:line "BASE http://foo.com"
             :parse
             [:BASE_BLOCK
               "BASE"<commit_msg>Clean some tests<commit_after>(ns howl.core-test
  "Test core functions."
  (:require [clojure.test :refer :all]
            [clojure.string :as string]
            [howl.core :refer :all]))

(deftest test-locate
  (testing "file, number, line"
    (is (= (locate {:file-name "local" :line-number 3 :line "FOO"})
           "in 'local' at '3':\nFOO")))
  (testing "number and line"
    (is (= (locate {:line-number 3 :line "FOO"})
           "at '3':\nFOO")))
  (testing "number and block"
    (is (= (locate {:line-number 3 :block #{"FOO"}})
           "at '3':\n#{\"FOO\"}")))
  (testing "just state"
    (is (= (locate :just-a-state)
           ":just-a-state"))))

(def test-merge "
A
  indented
   
  (that was a blank line)

B
C
  ")

(deftest test-merge-lines
  (testing "merge line"
    (is (= (merge-line {} "1")
           {:block {:line ""}
            :line-number 1
            :merging-lines ["1"]}))
    (is (= (merge-line {:merging-lines ["1"]} "2")
           {:block {:line "1"}
            :line-number 2
            :merging-lines ["2"]}))
    (is (= (merge-line
            {:line-number 10
             :merging-lines ["1"]}
            "2")
           {:block {:line "1"}
            :line-number 11
            :merging-lines ["2"]}))))

(deftest test-parse
  (testing "empty"
    (is (= (parse-block {:empty nil})
           {:empty nil})))
  (testing "basics"
    (is (= (parse-block {:block {:line "BASE http://foo.com"}})
           {:block
            {:line "BASE http://foo.com"
             :parse
             [:BASE_BLOCK
              "BASE"
              [:SPACES " "]
              [:BASE [:ABSOLUTE_IRI "http://foo.com"]]
              [:EOL ""]]}}))))

(deftest test-annotate
  (testing "basics"
    (is (= (annotate-block
           {:block
            {:line "BASE http://foo.com"
             :parse
             [:BASE_BLOCK
               "BASE"
{'fraction_non_alphanumeric': 0.19116186693147963, 'fraction_numerical': 0.011916583912611719, 'mean_word_length': 1.6985934360348292, 'pattern_counts': {'":': 2, '<': 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': '6926548', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1390, 'n_words': 337}