<commit_before>(ns smooth-test.parser.parse)

(defn build-advance-clock [tm]
  (let [sym (gensym "advance-clock")]
    `(fn ~sym [level#]
       (smooth-test.core/print-title level# (str "Advancing clock " ~tm "ms")))
    ))

(defn parse-clock-tick [acc [assertion arrow time_ms]]
  (if (= assertion 'clock-ticks)
    (update-in acc [:steps] #(conj % `{:type   :clock-tick
                                       :time   ~time_ms
                                       :action (fn [level#] (smooth-test.core/print-title level# "ADVANCE CLOCK"))
                                       }))
    acc
    )
  )

(defn parse-assertion [acc [assertion arrow result]]
  (if (= assertion 'clock-ticks)
    acc
    (update-in acc [:steps] #(conj % `{:type     :assertion
                                       :action   (fn [] ~assertion)
                                       :expected (fn [] ~result)
                                       }))
    )
  )

(defn stackmocks [mocks testname levelname]
  (if (empty? mocks)
    `(~testname ~levelname)
    `(with-redefs ~(first mocks) ~(stackmocks (rest mocks) testname levelname))
    )
  )

(defn parse-mocking-clause [acc [the-call arrow value-to-return]]
  (let [function-to-mock (first the-call)
        args-to-expect (rest the-call)]
    (update acc :setup #(conj % {:function function-to-mock :return value-to-return}))))


(defn is-mocking-clause? [triple] (not (and (sequential? (first triple)) (= "behavior" (name (first (first triple)))))))

(defn build-assertion [assertion]
  (let [sym (gensym "assertion")]
    `(fn ~sym [level#]
       (let [actual# ((:action ~assertion))
             expected# ((:expected ~assertion))]
         (if (= actual# expected#)
           (smooth-test.core/print-title level# "TEST OK.")
           (smooth-test.core/print-title level# (str "TEST FAILED. Expected " expected# " but got " actual#))
           )
         )
       )
    )
  )
(defn build-behavior-step-function [step]
  (cond
    (= :assertion (:type step)) (build-assertion step)
    (= :clock-tick (:type step)) (build-advance-clock (:time step))
    )
  )


(defn specification-fn [args]
  (let [keywords (set (filter #(keyword? %) args))
        title (first (filter #(string? %) args))
        tests (filter #(list? %) args)
        expanded-tests #spy/d (map #(macroexpand-1 %) tests)
        sym (gensym "specification")]
    `(defn ~(vary-meta sym assoc :test-context keywords) []
       (smooth-test.core/print-title 0 ~title)
       (smooth-test.core/run-sub-tests 0 ~expanded-tests)
       )
    )
  )

(defmacro specification
  "(specification optional-keyword(s) \"title\" test-forms)"
  [& args]
  (specification-fn args))

(defmacro info [description]
  (let [sym (gensym "info")]
    `(fn ~sym [level#] (smooth-test.core/print-title level# ~description))
    )
  )
<commit_msg>Story ID: RPC-171 Summary: Removed spyscope<commit_after>(ns smooth-test.parser.parse)

(defn build-advance-clock [tm]
  (let [sym (gensym "advance-clock")]
    `(fn ~sym [level#]
       (smooth-test.core/print-title level# (str "Advancing clock " ~tm "ms")))
    ))

(defn parse-clock-tick [acc [assertion arrow time_ms]]
  (if (= assertion 'clock-ticks)
    (update-in acc [:steps] #(conj % `{:type   :clock-tick
                                       :time   ~time_ms
                                       :action (fn [level#] (smooth-test.core/print-title level# "ADVANCE CLOCK"))
                                       }))
    acc
    )
  )

(defn parse-assertion [acc [assertion arrow result]]
  (if (= assertion 'clock-ticks)
    acc
    (update-in acc [:steps] #(conj % `{:type     :assertion
                                       :action   (fn [] ~assertion)
                                       :expected (fn [] ~result)
                                       }))
    )
  )

(defn stackmocks [mocks testname levelname]
  (if (empty? mocks)
    `(~testname ~levelname)
    `(with-redefs ~(first mocks) ~(stackmocks (rest mocks) testname levelname))
    )
  )

(defn parse-mocking-clause [acc [the-call arrow value-to-return]]
  (let [function-to-mock (first the-call)
        args-to-expect (rest the-call)]
    (update acc :setup #(conj % {:function function-to-mock :return value-to-return}))))


(defn is-mocking-clause? [triple] (not (and (sequential? (first triple)) (= "behavior" (name (first (first triple)))))))

(defn build-assertion [assertion]
  (let [sym (gensym "assertion")]
    `(fn ~sym [level#]
       (let [actual# ((:action ~assertion))
             expected# ((:expected ~assertion))]
         (if (= actual# expected#)
           (smooth-test.core/print-title level# "TEST OK.")
           (smooth-test.core/print-title level# (str "TEST FAILED. Expected " expected# " but got " actual#))
           )
         )
       )
    )
  )
(defn build-behavior-step-function [step]
  (cond
    (= :assertion (:type step)) (build-assertion step)
    (= :clock-tick (:type step)) (build-advance-clock (:time step))
    )
  )


(defn specification-fn [args]
  (let [keywords (set (filter #(keyword? %) args))
        title (first (filter #(string? %) args))
        tests (filter #(list? %) args)
        expanded-tests (map #(macroexpand-1 %) tests)
        sym (gensym "specification")]
    `(defn ~(vary-meta sym assoc :test-context keywords) []
       (smooth-test.core/print-title 0 ~title)
       (smooth-test.core/run-sub-tests 0 ~expanded-tests)
       )
    )
  )

(defmacro specification
  "(specification optional-keyword(s) \"title\" test-forms)"
  [& args]
  (specification-fn args))

(defmacro info [description]
  (let [sym (gensym "info")]
    `(fn ~sym [level#] (smooth-test.core/print-title level# ~description))
    )
  )

{'fraction_non_alphanumeric': 0.15898334794040314, 'fraction_numerical': 0.0015775635407537247, 'mean_word_length': 2.2475811041548095, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7536099', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1875, 'n_words': 458}