<commit_before>(ns active.clojure.validation-test
  (:require #?(:clj [active.clojure.record :refer [define-record-type]]
               :cljs [active.clojure.cljs.record :refer-macros [define-record-type]])
            #?(:clj [clojure.test :as t]
               :cljs [cljs.test :as t :include-macros true])
            [active.clojure.validation :as v]))

(t/deftest fmap-success-test
  (let [failure (v/make-validation-failure
                 [(v/make-validation-error "candidate" "message" nil)])
        success (v/make-validation-success "candidate")]
    (t/is (= failure (v/fmap-success identity failure)))
    (t/is (= success (v/fmap-success identity success)))))

(t/deftest fmap-result-test
  (letfn [(f [validation-result]
            (v/fmap-result str (fn [error] (v/validation-error-label error :new-label)) validation-result))]
    (t/is (= (v/make-validation-success "42") (f (v/validate-pos-int 42))))
    (t/is (= (v/make-validation-failure [(v/make-validation-error -23 ::v/pos-int :new-label)])
             (f (v/validate-pos-int -23))))))

(t/deftest seq-validation-test
  (let [failure (v/make-validation-failure
                 [(v/make-validation-error "candidate" "message" nil)])
        failure-2 (v/make-validation-failure
                   [(v/make-validation-error "candidate-2" "message-2" nil)])
        flat-success (v/make-validation-success "candidate")]
    (t/testing "failures are concatenated"
      (t/is (= (v/make-validation-failure
                [(v/make-validation-error "candidate" "message" nil)
                 (v/make-validation-error "candidate-2" "message-2" nil)])
               (v/seq-validation failure failure-2))))
    (t/testing "one failure leads to failure"
      (t/is (= failure
               (v/seq-validation (v/pure-validation identity) failure))))
    (t/testing "two successes lead to success"<commit_msg>Write better test to show what's actually supposed to happen.<commit_after>(ns active.clojure.validation-test
  (:require #?(:clj [active.clojure.record :refer [define-record-type]]
               :cljs [active.clojure.cljs.record :refer-macros [define-record-type]])
            #?(:clj [clojure.test :as t]
               :cljs [cljs.test :as t :include-macros true])
            [active.clojure.validation :as v]))

(t/deftest fmap-success-test
  (let [failure (v/make-validation-failure
                 [(v/make-validation-error "candidate" "message" nil)])
        success (v/make-validation-success "candidate")]
    (t/is (= failure (v/fmap-success clojure.string/upper-case failure)))
    (t/is (= (v/make-validation-success "CANDIDATE")
             (v/fmap-success clojure.string/upper-case success)))))

(t/deftest fmap-result-test
  (letfn [(f [validation-result]
            (v/fmap-result str (fn [error] (v/validation-error-label error :new-label)) validation-result))]
    (t/is (= (v/make-validation-success "42") (f (v/validate-pos-int 42))))
    (t/is (= (v/make-validation-failure [(v/make-validation-error -23 ::v/pos-int :new-label)])
             (f (v/validate-pos-int -23))))))

(t/deftest seq-validation-test
  (let [failure (v/make-validation-failure
                 [(v/make-validation-error "candidate" "message" nil)])
        failure-2 (v/make-validation-failure
                   [(v/make-validation-error "candidate-2" "message-2" nil)])
        flat-success (v/make-validation-success "candidate")]
    (t/testing "failures are concatenated"
      (t/is (= (v/make-validation-failure
                [(v/make-validation-error "candidate" "message" nil)
                 (v/make-validation-error "candidate-2" "message-2" nil)])
               (v/seq-validation failure failure-2))))
    (t/testing "one failure leads to failure"
      (t/is (= failure
               (v/seq-validation (v/pure-validation identity) failure))))
    (t/testing "two successes lead to success"
{'fraction_non_alphanumeric': 0.16268311488049345, 'fraction_numerical': 0.00719609354921614, 'mean_word_length': 2.651031894934334, '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': '1355703', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1253, 'n_words': 263}