<commit_before>;; -*- indent-tabs-mode: nil -*-

(ns midje.sweet
  (:use clojure.test
        [clojure.contrib.ns-utils :only [immigrate]]
        [clojure.contrib.pprint :only [pprint]]
        [clojure.contrib.seq :only [separate]])
         
  (:use [midje production-mode metaconstants]
        midje.midje-forms.recognizing
        [midje.midje-forms.translating
         :only [midjcoexpand put-wrappers-into-effect
                forms-to-wrap-around translate-fact-body
                add-line-numbers unfold-prerequisites
                form-with-copied-line-numbers
                add-binding-annotations]]
        [midje.fakes :only [background-fakes]]
        [midje.midje-forms.dissecting :only [separate-background-forms
                                             dissect-fact-table]]
        [midje.util debugging thread-safe-var-nesting unify]
        [midje.util.exceptions :only [user-error-exception-lines]]
        [midje.util.wrapping :only [multiwrap]]
        [midje.util.form-utils :only [reader-line-number]]
        [midje.util.file-position :only [user-file-position set-fallback-line-number-from]])
  (:require [midje.midje-forms.building :as building])
  (:require midje.checkers)
  (:require [midje.util.report :as report])
)
(immigrate 'midje.unprocessed)
(immigrate 'midje.semi-sweet)
(intern *ns* 'before #'building/before)
(intern *ns* 'after #'building/after)
(intern *ns* 'around #'building/around)

(defmacro background [& raw-wrappers]
  (when (user-desires-checking?)
    (put-wrappers-into-effect raw-wrappers)))

(defmacro against-background [wrappers & forms]
  (if (user-desires-checking?)
    (midjcoexpand `(against-background ~wrappers ~@forms))
    `(do ~@forms)))
    
(defmacro fact [& forms]
  (when (user-desires-checking?)
    (try
      (set-fallback-line-number-from &form)
      (let [[background remainder] (separate-background-forms forms)]
        (if (empty? background)
          (let [things-to-run (-> remainder
                                  add-line-numbers
                                  translate-fact-body
                                  unfold-prerequisites)
                fake-enabled `(with-installed-fakes
                                (background-fakes)
                                (every? true?
                                        (list ~@things-to-run)))
                expansion (midjcoexpand fake-enabled)
                wrapped-expansion (multiwrap expansion
                                             (forms-to-wrap-around :facts))]
            (define-metaconstants things-to-run)
            `(do (report/fact-begins)
                 ~wrapped-expansion
                 (report/fact-checks-out?)))
          `(against-background ~background (midje.sweet/fact ~@remainder))))
      (catch Exception ex
        `(do
           (clojure.test/report {:type :exceptional-user-error
                                 :macro-form '~&form
                                 :exception-lines '~(user-error-exception-lines ex)
                                 :position (midje.util.file-position/line-number-known ~(:line (meta &form)))})
           false)))))

(defmacro facts [& forms]
  (with-meta `(fact ~@forms) (meta &form)))

(defn- future-fact-1 [forms]
  (let [lineno (reader-line-number forms)
        description (if (string? (second forms))
                      (str (second forms) " ")
                      "")]
    `(clojure.test/report {:type :future-fact
                           :description ~description
                           :position (midje.util.file-position/line-number-known ~lineno)})))

;; Wanna add more to these? See also midje-forms.recognizing.
;; Such is the penalty for whimsy.
(defmacro future-fact [& forms] (future-fact-1 &form))
(defmacro future-facts [& forms] (future-fact-1 &form))
(defmacro pending-fact [& forms] (future-fact-1 &form))
(defmacro pending-facts [& forms] (future-fact-1 &form))
(defmacro incipient-fact [& forms] (future-fact-1 &form))
(defmacro incipient-facts [& forms] (future-fact-1 &form))
(defmacro antiterminologicaldisintactitudinarian-fact [& forms] (future-fact-1 &form))
(defmacro antiterminologicaldisintactitudinarian-facts [& forms] (future-fact-1 &form))

(defmacro tabular [& forms]
  (let [{:keys [fact-form binding-maps map-order]} (dissect-fact-table forms)
        substitute (fn [bindings]
                     (subst fact-form bindings))
        numbered (fn [form]
                   (form-with-copied-line-numbers form fact-form))
        expect-forms (map (comp macroexpand numbered substitute) binding-maps)
        result (add-binding-annotations expect-forms binding-maps map-order)]
    `(do ~@result)))
<commit_msg>shortened tabular macro and removed unused :use statements<commit_after>;; -*- indent-tabs-mode: nil -*-

(ns midje.sweet
  (:use clojure.test
        [clojure.contrib.ns-utils :only [immigrate]])
         
  (:use [midje production-mode metaconstants]
        midje.midje-forms.recognizing
        [midje.midje-forms.translating
         :only [midjcoexpand put-wrappers-into-effect
                forms-to-wrap-around translate-fact-body
                add-line-numbers unfold-prerequisites
                form-with-copied-line-numbers
                add-binding-annotations]]
        [midje.fakes :only [background-fakes]]
        [midje.midje-forms.dissecting :only [separate-background-forms
                                             dissect-fact-table]]
        [midje.util debugging thread-safe-var-nesting unify]
        [midje.util.exceptions :only [user-error-exception-lines]]
        [midje.util.wrapping :only [multiwrap]]
        [midje.util.form-utils :only [reader-line-number]]
        [midje.util.file-position :only [user-file-position set-fallback-line-number-from]])
  (:require [midje.midje-forms.building :as building])
  (:require midje.checkers)
  (:require [midje.util.report :as report])
)
(immigrate 'midje.unprocessed)
(immigrate 'midje.semi-sweet)
(intern *ns* 'before #'building/before)
(intern *ns* 'after #'building/after)
(intern *ns* 'around #'building/around)

(defmacro background [& raw-wrappers]
  (when (user-desires-checking?)
    (put-wrappers-into-effect raw-wrappers)))

(defmacro against-background [wrappers & forms]
  (if (user-desires-checking?)
    (midjcoexpand `(against-background ~wrappers ~@forms))
    `(do ~@forms)))
    
(defmacro fact [& forms]
  (when (user-desires-checking?)
    (try
      (set-fallback-line-number-from &form)
      (let [[background remainder] (separate-background-forms forms)]
        (if (empty? background)
          (let [things-to-run (-> remainder
                                  add-line-numbers
                                  translate-fact-body
                                  unfold-prerequisites)
                fake-enabled `(with-installed-fakes
                                (background-fakes)
                                (every? true?
                                        (list ~@things-to-run)))
                expansion (midjcoexpand fake-enabled)
                wrapped-expansion (multiwrap expansion
                                             (forms-to-wrap-around :facts))]
            (define-metaconstants things-to-run)
            `(do (report/fact-begins)
                 ~wrapped-expansion
                 (report/fact-checks-out?)))
          `(against-background ~background (midje.sweet/fact ~@remainder))))
      (catch Exception ex
        `(do
           (clojure.test/report {:type :exceptional-user-error
                                 :macro-form '~&form
                                 :exception-lines '~(user-error-exception-lines ex)
                                 :position (midje.util.file-position/line-number-known ~(:line (meta &form)))})
           false)))))

(defmacro facts [& forms]
  (with-meta `(fact ~@forms) (meta &form)))

(defn- future-fact-1 [forms]
  (let [lineno (reader-line-number forms)
        description (if (string? (second forms))
                      (str (second forms) " ")
                      "")]
    `(clojure.test/report {:type :future-fact
                           :description ~description
                           :position (midje.util.file-position/line-number-known ~lineno)})))

;; Wanna add more to these? See also midje-forms.recognizing.
;; Such is the penalty for whimsy.
(defmacro future-fact [& forms] (future-fact-1 &form))
(defmacro future-facts [& forms] (future-fact-1 &form))
(defmacro pending-fact [& forms] (future-fact-1 &form))
(defmacro pending-facts [& forms] (future-fact-1 &form))
(defmacro incipient-fact [& forms] (future-fact-1 &form))
(defmacro incipient-facts [& forms] (future-fact-1 &form))
(defmacro antiterminologicaldisintactitudinarian-fact [& forms] (future-fact-1 &form))
(defmacro antiterminologicaldisintactitudinarian-facts [& forms] (future-fact-1 &form))

(defmacro tabular [& forms]
  (let [{:keys [fact-form binding-maps map-order]} (dissect-fact-table forms)
        expect-forms (map (comp macroexpand 
        		        #(form-with-copied-line-numbers % fact-form) 
        		        (partial subst fact-form)) binding-maps)
        result (add-binding-annotations expect-forms binding-maps map-order)]
    `(do ~@result)))



{'fraction_non_alphanumeric': 0.13226258488735582, 'fraction_numerical': 0.0019402824188854155, 'mean_word_length': 2.113422818791946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2442904', 'n_tokens_mistral': 2857, 'n_tokens_neox': 2737, 'n_words': 566}