<commit_before>(ns protobuf.core-test
  (:use protobuf.core clojure.test)
  (:import (java.io PipedInputStream PipedOutputStream)))

(def Foo      (protodef protobuf.test.Core$Foo))
(def FooUnder (protodef protobuf.test.Core$Foo
                        protobuf.core.PersistentProtocolBufferMap$Def/protobufNames))
(def Bar      (protodef protobuf.test.Core$Bar))
(def Response (protodef protobuf.test.Core$Response))
(def ErrorMsg (protodef protobuf.test.Core$ErrorMsg))

(defn catbytes [& args]
  (let [out-buf (byte-array (reduce + (map count args)))]
    (loop [offset 0, args args]
      (if-let [[^bytes array & more] (seq args)]
        (let [size (count array)]
          (System/arraycopy array 0
                            out-buf offset size)
          (recur (+ size offset) more))
        out-buf))))

(deftest test-conj
  (let [p (protobuf Foo :id 5 :tags ["little" "yellow"] :doubles [1.2 3.4 5.6] :floats [0.01 0.02 0.03])]
    (let [p (conj p {:label "bar"})]
      (is (= 5     (:id p)))
      (is (= "bar" (:label p)))
      (is (= ["little" "yellow"] (:tags p)))
      (is (= [1.2 3.4 5.6] (:doubles p)))
      (is (= [(float 0.01) (float 0.02) (float 0.03)] (:floats  p))))
    (let [p (conj p {:tags ["different"]})]
      (is (= ["different"] (:tags p))))
    (let [p (conj p {:tags ["little" "yellow" "different"] :label "very"})]
      (is (= ["little" "yellow" "different"] (:tags p)))
      (is (= "very" (:label p))))))

(deftest test-append
  (let [p (protobuf Foo :id 5 :tags ["little" "yellow"] :doubles [1.2] :floats [0.01])]
    (let [p (append p {:label "bar"})]
      (is (= 5     (:id p)))
      (is (= "bar" (:label p)))
      (is (= false (:deleted p)))
      (is (= ["little" "yellow"] (:tags p))))
    (let [p (append (assoc p :deleted true) p)]
      (is (= true (:deleted p))))
    (let [p (append p {:tags ["different"]})]
      (is (= ["little" "yellow" "different"] (:tags p))))
    (let [p (append p {:tags ["different"] :label "very"})]
      (is (= ["little" "yellow" "different"] (:tags p)))
      (is (= "very" (:label p))))
    (let [p (append p {:doubles [3.4] :floats [0.02]})]
      (is (= [1.2 3.4] (:doubles p)))
      (is (= [(float 0.01) (float 0.02)] (:floats  p))))))

(deftest test-assoc
  (let [p (protobuf Foo :id 5 :tags ["little" "yellow"] :foo-by-id {1 {:label "one"} 2 {:label "two"}})]
    (let [p (assoc p :label "baz" :tags ["nuprin"])]
      (is (= ["nuprin"] (:tags p)))
      (is (= "baz"      (:label p))))
    (let [p (assoc p :responses [:yes :no :maybe :no "yes"])]
      (is (= [:yes :no :maybe :no :yes] (:responses p))))
    (let [p (assoc p :tags "aspirin")]
      (is (= ["aspirin"] (:tags p))))<commit_msg>Add test for our new use of OrderedMap<commit_after>(ns protobuf.core-test
  (:use protobuf.core clojure.test
        ordered-map.core)
  (:import (java.io PipedInputStream PipedOutputStream)))

(def Foo      (protodef protobuf.test.Core$Foo))
(def FooUnder (protodef protobuf.test.Core$Foo
                        protobuf.core.PersistentProtocolBufferMap$Def/protobufNames))
(def Bar      (protodef protobuf.test.Core$Bar))
(def Response (protodef protobuf.test.Core$Response))
(def ErrorMsg (protodef protobuf.test.Core$ErrorMsg))

(defn catbytes [& args]
  (let [out-buf (byte-array (reduce + (map count args)))]
    (loop [offset 0, args args]
      (if-let [[^bytes array & more] (seq args)]
        (let [size (count array)]
          (System/arraycopy array 0
                            out-buf offset size)
          (recur (+ size offset) more))
        out-buf))))

(deftest test-conj
  (let [p (protobuf Foo :id 5 :tags ["little" "yellow"] :doubles [1.2 3.4 5.6] :floats [0.01 0.02 0.03])]
    (let [p (conj p {:label "bar"})]
      (is (= 5     (:id p)))
      (is (= "bar" (:label p)))
      (is (= ["little" "yellow"] (:tags p)))
      (is (= [1.2 3.4 5.6] (:doubles p)))
      (is (= [(float 0.01) (float 0.02) (float 0.03)] (:floats  p))))
    (let [p (conj p {:tags ["different"]})]
      (is (= ["different"] (:tags p))))
    (let [p (conj p {:tags ["little" "yellow" "different"] :label "very"})]
      (is (= ["little" "yellow" "different"] (:tags p)))
      (is (= "very" (:label p))))))

(deftest test-append
  (let [p (protobuf Foo :id 5 :tags ["little" "yellow"] :doubles [1.2] :floats [0.01])]
    (let [p (append p {:label "bar"})]
      (is (= 5     (:id p)))
      (is (= "bar" (:label p)))
      (is (= false (:deleted p)))
      (is (= ["little" "yellow"] (:tags p))))
    (let [p (append (assoc p :deleted true) p)]
      (is (= true (:deleted p))))
    (let [p (append p {:tags ["different"]})]
      (is (= ["little" "yellow" "different"] (:tags p))))
    (let [p (append p {:tags ["different"] :label "very"})]
      (is (= ["little" "yellow" "different"] (:tags p)))
      (is (= "very" (:label p))))
    (let [p (append p {:doubles [3.4] :floats [0.02]})]
      (is (= [1.2 3.4] (:doubles p)))
      (is (= [(float 0.01) (float 0.02)] (:floats  p))))))

(deftest test-ordered-append
  (let [inputs (apply ordered-map (for [x (range 26)
                                        entry [(str x) (str (char (+ (int \a) x)))]]
                                    entry))]
    (= (seq inputs)
       (seq (reduce (fn [m [k v]]
                      (append m {:attr_map {k v}}))
                    (protobuf Foo)
                    inputs)))))

(deftest test-assoc
  (let [p (protobuf Foo :id 5 :tags ["little" "yellow"] :foo-by-id {1 {:label "one"} 2 {:label "two"}})]
    (let [p (assoc p :label "baz" :tags ["nuprin"])]
      (is (= ["nuprin"] (:tags p)))
      (is (= "baz"      (:label p))))
    (let [p (assoc p :responses [:yes :no :maybe :no "yes"])]
      (is (= [:yes :no :maybe :no :yes] (:responses p))))
    (let [p (assoc p :tags "aspirin")]
      (is (= ["aspirin"] (:tags p))))
{'fraction_non_alphanumeric': 0.21853507565337002, 'fraction_numerical': 0.02063273727647868, 'mean_word_length': 2.604089219330855, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2332846', 'n_tokens_mistral': 2361, 'n_tokens_neox': 2081, 'n_words': 664}