Skip to content

Commit

Permalink
Add tests for ITF8/LTF8 decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
athos committed Dec 21, 2023
1 parent 5df326e commit a5d6eba
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/cljam/io/cram/itf8_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(ns cljam.io.cram.itf8-test
(:require [cljam.io.cram.itf8 :as itf8]
[cljam.io.util.byte-buffer :as bb]
[clojure.test :refer [deftest are]]))

(deftest decode-itf8-test
(are [bs expected] (= expected
(-> (byte-array bs)
bb/make-lsb-byte-buffer
itf8/decode-itf8))
[0x00] 0x00
[0x7f] 0x7f
[0x80 0xff] 0xff
[0xbc 0xab] 0x3cab
[0xc0 0x12 0x34] 0x1234
[0xda 0xbc 0x23] 0x1abc23
[0xe0 0x12 0x34 0x56] 0x123456
[0xea 0xbc 0xde 0xf0] 0xabcdef0
[0xfc 0xaf 0xeb 0xab 0x0e] (unchecked-int 0xcafebabe)
[0xff 0xff 0xff 0xff 0xff] -1))

(deftest decode-ltf8-test
(are [bs expected] (= expected
(-> (byte-array bs)
bb/make-lsb-byte-buffer
itf8/decode-ltf8))
[0x00] 0x00
[0x7f] 0x7f
[0x80 0xff] 0xff
[0xbc 0xab] 0x3cab
[0xc0 0x12 0x34] 0x1234
[0xda 0xbc 0x23] 0x1abc23
[0xe0 0x12 0x34 0x56] 0x123456
[0xea 0xbc 0xde 0xf0] 0xabcdef0
[0xf0 0xde 0xad 0xbe 0xef] 0xdeadbeef
[0xf7 0xff 0xff 0xff 0xff] 0x7ffffffff
[0xf8 0x12 0x34 0x56 0x78 0x9a] 0x123456789a
[0xfb 0xff 0xff 0xff 0xff 0xff] 0x3ffffffffff
[0xfc 0xba 0xdb 0xad 0xba 0xdb 0xad] 0xbadbadbadbad
[0xfd 0x23 0x45 0x67 0x89 0xab 0xcd] 0x123456789abcd
[0xff 0x12 0x34 0x56 0x78 0x9a 0xbc 0xde 0xf0] 0x123456789abcdef0
[0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff] -1))

0 comments on commit a5d6eba

Please sign in to comment.