             (t/is (= written (buf/size spec)))
             (let [[readed data'] (buf/read* buffer spec)]
               (t/is (= readed (buf/size spec)))
-              (t/is (= data data')))))))))
-
-;; #+clj
-;; (t/deftest spec-data-with-dynamic-types-single
-;;   (let [spec (buf/spec (buf/string*))
-;;         buffer (buf/allocate 20)]
-;;     (buf/write! buffer ["1234567890"] spec)
-;;     (let [[readed data] (buf/read* buffer spec)]
-;;       (t/is (= readed 14))
-;;       (t/is (= data ["1234567890"])))))
-
-;; #+clj
-;; (t/deftest spec-data-with-dynamic-types-combined
-;;   (let [spec (buf/spec (buf/string*) (buf/int64))
-;;         buffer (buf/allocate 40)]
-;;     (buf/write! buffer ["1234567890" 1000] spec)
-;;     (let [[readed data] (buf/read* buffer spec)]
-;;       (t/is (= readed 22))
-;;       (t/is (= data ["1234567890" 1000])))))
-
-;; #+clj
-;; (t/deftest spec-composition
-;;   (let [spec (buf/spec (buf/compose-type (buf/int32) (buf/int32))
-;;                        (buf/compose-type (buf/string 10) (buf/string 5)))
-;;         buffer (buf/allocate (buf/size spec))
-;;         data [[100 200] ["foo" "bar"]]]
-;;     (buf/write! buffer data spec)
-;;     (let [[readed data'] (buf/read* buffer spec)]
-;;       (t/is (= readed (buf/size spec)))
-;;       (t/is (= data' data)))))
+              (cond
+                (instance? js/Int8Array data')
+                (t/is (equals? data data'))
+
+                :else
+                (t/is (= data data'))))))))))
+
+(t/deftest spec-data-with-dynamic-types-single
+  (let [spec (buf/spec (buf/string*))
+        buffer (buf/allocate 20)]
+    (buf/write! buffer ["1234567890"] spec)
+    (let [[readed data] (buf/read* buffer spec)]
+      (t/is (= readed 14))
+      (t/is (= data ["1234567890"])))))
+
+(t/deftest spec-data-with-dynamic-types-combined
+  (let [spec (buf/spec (buf/string*) (buf/int32))
+        buffer (buf/allocate 40)]
+    (buf/write! buffer ["1234567890" 1000] spec)
+    (let [[readed data] (buf/read* buffer spec)]
+      (t/is (= readed 18))
+      (t/is (= data ["1234567890" 1000])))))
+
+(t/deftest spec-composition
+  (let [spec (buf/spec (buf/compose-type (buf/int32) (buf/int32))
+                       (buf/compose-type (buf/string 10) (buf/string 5)))
+        buffer (buf/allocate (buf/size spec))
+        data [[100 200] ["foo" "bar"]]]
+    (buf/write! buffer data spec)
+    (let [[readed data'] (buf/read* buffer spec)]
+      (t/is (= readed (buf/size spec)))
+      (t/is (= data' data)))))


#+cljs
(t/deftest spec-data-types
  (let [data [;; (buf/string 5) "12345"
              (buf/short)    100
              (buf/integer)  1001
              (buf/bool)     false
              (buf/double)   (double 4.3)
              (buf/float)    (float 3.5)
              (buf/byte)     (byte 32)]]
              ;; (buf/bytes 5)  (bytes/random-bytes 5)]]
    (doseq [[spec data] (partition 2 data)]
      (let [buffers [(buf/allocate (buf/size spec) {:impl :es6})]]
        (doseq [buffer buffers]

  (:require #+clj [clojure.test :as t]
            #+cljs [cljs.test :as t]
            [bytebuf.core :as buf]
            [bytebuf.buffer :as impl])
  #+clj
  (:import java.nio.ByteBuffer
           io.netty.buffer.ByteBuf))


#+clj
(defn random-bytes
  [^long numbytes]
  (let [sr (java.util.Random.)
        buffer (byte-array numbytes)]
    (.nextBytes sr buffer)
    buffer))

#+cljs
(defn random-bytes
  [^long numbytes]
  (let [buffer (js/Int8Array. numbytes)]
    (doseq [i (range numbytes)]
      (aset buffer i (rand-int 10)))
    buffer))

#+clj
(defn equals?
  "Check if two byte arrays are equals."
  [^bytes a ^bytes b]
  (java.util.Arrays/equals a b))

#+cljs
(defn equals?
  [^bytes a ^bytes b]
  (if (not= (.-length a) (.-length b))
    false
    (reduce (fn [acc i]
              (if (not= (aget a i) (aget b i))
                (reduced false)
                true))
            true
            (range (.-length a)))))

#+clj
(t/deftest allocate-heap-nio-buffer
