<commit_before>(ns fudje.core
  (:require [fudje
             [data :as data]
             [util :as ut]]
            [clojure.test :as test])
  (:import [java.util.concurrent.atomic AtomicLong]))

(def ^:dynamic *report-mock-state*  false)

;======================================================================
;;extend what `clojure.test/is` recognises for our own benefit :)

(defmethod test/assert-expr 'compatible
  [msg form]
  `(let [probably-expected# ~(nth form 1)
         probably-supplied# ~(nth form 2)
         [expected# supplied#] (if (fudje.util/poly-checker? probably-expected#)
                                 [probably-expected# probably-supplied#]
                                 [probably-supplied# probably-expected#]) ;; make sure we got the order right

         [only-expected# only-value# both#] (data/diff expected# supplied#)]
     (if only-expected#
       (test/do-report {:type :fail, :message ~msg :expected expected#, :actual (list
                                                                                  '~'found only-value#
                                                                                  '~'instead-of only-expected#)})
       (test/do-report {:type :pass, :message ~msg :expected expected#, :actual both#}))))
;================================================================================================================

(defn- apply-mock [mock args]
  (let [mock-fn (if (ut/throwable? mock)
                  (fn [& _] (throw mock))
                  mock)]
    (cond-> mock-fn
            (fn? mock-fn) (apply args))))

(defn arg-checking-wrapper [f original-mock-fn args-to-check group-no]
  (let [^AtomicLong mcounter (when-not (zero? group-no) (AtomicLong. 0))
        groups? (when (> group-no 1) true)]
    (bound-fn [& args]
      (if fudje.core/*report-mock-state*
        {:actual-calls (if mcounter (.get mcounter) 0)
         :expected-calls group-no}

        (let [vargs (vec args)
              curr-i (when mcounter
                       (.getAndIncrement mcounter))<commit_msg>fix bug in assert-expr extension<commit_after>(ns fudje.core
  (:require [fudje
             [data :as data]
             [util :as ut]]
            [clojure.test :as test])
  (:import [java.util.concurrent.atomic AtomicLong]))

(def ^:dynamic *report-mock-state*  false)

;======================================================================
;;extend what `clojure.test/is` recognises for our own benefit :)

(defmethod test/assert-expr 'compatible
  [msg form]
  `(let [probably-expected# ~(nth form 1)
         probably-supplied# ~(nth form 2)
         [expected# supplied#] (if (fudje.util/poly-checker? probably-expected#)
                                 [probably-expected# probably-supplied#]
                                 [probably-supplied# probably-expected#]) ;; make sure we got the order right

         [only-expected# only-value# both#] (data/diff expected# supplied#)
         failure# (boolean (cond-> only-expected#
                                   (coll? only-expected#) seq))]
     (if only-expected#
       (test/do-report {:type :fail, :message ~msg :expected expected#, :actual (list
                                                                                  '~'found only-value#
                                                                                  '~'instead-of only-expected#)})
       (test/do-report {:type :pass, :message ~msg :expected expected#, :actual both#}))
     (not failure#)))

;================================================================================================================

(defn- apply-mock [mock args]
  (let [mock-fn (if (ut/throwable? mock)
                  (fn [& _] (throw mock))
                  mock)]
    (cond-> mock-fn
            (fn? mock-fn) (apply args))))

(defn arg-checking-wrapper [f original-mock-fn args-to-check group-no]
  (let [^AtomicLong mcounter (when-not (zero? group-no) (AtomicLong. 0))
        groups? (when (> group-no 1) true)]
    (bound-fn [& args]
      (if fudje.core/*report-mock-state*
        {:actual-calls (if mcounter (.get mcounter) 0)
         :expected-calls group-no}

        (let [vargs (vec args)
              curr-i (when mcounter
                       (.getAndIncrement mcounter))
{'fraction_non_alphanumeric': 0.208955223880597, 'fraction_numerical': 0.0023320895522388058, 'mean_word_length': 1.9993006993006992, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5739537', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1138, 'n_words': 306}