<commit_before>(ns literals.core-test
  (:use clojure.test)
  (:require clojure.tools.reader
            literals.core
            [clj-time.core :as t]
            [immutant.messaging :as msg]))

(def publish (partial msg/publish "queue.literals"))
(def receive (partial msg/receive "queue.literals" :timeout 30000))
(def listen (partial msg/listen "queue.literals"))

(defmacro with-tools-readers [& body]
  `(binding [clojure.tools.reader/*data-readers*
             {'acme/datetime #'literals.core/from-edn-datetime}]
     (do ~@body)))

(defn test-message-encoding [enc]
  (let [t (t/now)
        r (rand)]
    ;; first for raw receive
    (publish [r t] :encoding enc)
    (is (= [r t] (receive)))
    ;; then for a listener
    (let [r (inc r)
          p (promise)
          l (listen #(deliver p %))]
      (try
        (publish [r t] :encoding enc)
        (is (= [r t] (deref p 1000 :fail)))
        (finally (msg/unlisten l))))))

;;; These will only work when data_readers.clj is auto-loaded
(when (resolve 'clojure.core/*data-readers*)
  (deftest publish-receive-edn
    (test-message-encoding :edn))
  (deftest publish-receive-clojure
    (test-message-encoding :clojure)))


;;; The rest should work with all versions

(deftest publish-receive-edn-with-tools
  (with-tools-readers (test-message-encoding :edn)))

(deftest publish-receive-clojure-with-tools
  (with-tools-readers (test-message-encoding :clojure)))
<commit_msg>Add some debugging output, and wait a frickin' month for it to timeout.<commit_after>(ns literals.core-test
  (:use clojure.test)
  (:require clojure.tools.reader
            literals.core
            [clj-time.core :as t]
            [immutant.messaging :as msg]))

(def publish (partial msg/publish "queue.literals"))
(def receive (partial msg/receive "queue.literals" :timeout 60000))
(def listen (partial msg/listen "queue.literals"))

(defmacro with-tools-readers [& body]
  `(binding [clojure.tools.reader/*data-readers*
             {'acme/datetime #'literals.core/from-edn-datetime}]
     (do ~@body)))

(defn test-message-encoding [enc]
  (let [t (t/now)
        r (rand)]
    ;; first for raw receive
    (println "Publishing, encoding:" enc)
    (time 
     (publish [r t] :encoding enc))
    (time
     (is (= [r t] (receive))))
    ;; then for a listener
    (let [r (inc r)
          p (promise)
          l (listen #(deliver p %))]
      (try
        (publish [r t] :encoding enc)
        (is (= [r t] (deref p 1000 :fail)))
        (finally (msg/unlisten l))))))

;;; These will only work when data_readers.clj is auto-loaded
(when (resolve 'clojure.core/*data-readers*)
  (deftest publish-receive-edn
    (test-message-encoding :edn))
  (deftest publish-receive-clojure
    (test-message-encoding :clojure)))


;;; The rest should work with all versions

(deftest publish-receive-edn-with-tools
  (with-tools-readers (test-message-encoding :edn)))

(deftest publish-receive-clojure-with-tools
  (with-tools-readers (test-message-encoding :clojure)))

{'fraction_non_alphanumeric': 0.14921900963775342, 'fraction_numerical': 0.005982053838484547, 'mean_word_length': 3.0186915887850465, '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': '6273128', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1030, 'n_words': 270}