aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-08-05 22:25:43 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-08-05 22:25:48 +0900
commit0474e6ba3a171ac1ba46e8499b12e6b36a56d326 (patch)
tree057687da4f8dfba688d101dd229f0dc81a6869ed /test
parentc122dd3334be25fdf54e9c2b964a5f0774a7f3ac (diff)
downloadplum-0474e6ba3a171ac1ba46e8499b12e6b36a56d326.tar.gz
test: add test cases for BinaryString
Diffstat (limited to 'test')
-rw-r--r--test/plum/test_binary_string.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/plum/test_binary_string.rb b/test/plum/test_binary_string.rb
new file mode 100644
index 0000000..69c9c3a
--- /dev/null
+++ b/test/plum/test_binary_string.rb
@@ -0,0 +1,51 @@
+require "test_helper"
+
+using BinaryString
+
+class BinaryStringTest < Minitest::Test
+ def test_uint8
+ assert_equal(0x67, "\x67".uint8)
+ assert_equal(0x75, "\x67\x75".uint8(1))
+ end
+
+ def test_uint16
+ assert_equal(0x78ff, "\x78\xff".uint16)
+ assert_equal(0xee55, "\x78\xee\x55".uint16(1))
+ end
+
+ def test_uint24
+ assert_equal(0x005554, "\x00\x55\x54".uint24)
+ assert_equal(0x005554, "\x2f\xaa\x00\x55\x54".uint24(2))
+ end
+
+ def test_uint32
+ assert_equal(0x00555400, "\x00\x55\x54\x00".uint32)
+ assert_equal(0x00555400, "\x2f\xaa\x00\x55\x54\x00".uint32(2))
+ end
+
+ def test_push_uint8
+ assert_equal("\x24", "".push_uint8(0x24))
+ end
+
+ def test_push_uint16
+ assert_equal("\x24\x11", "".push_uint16(0x2411))
+ end
+
+ def test_push_uint24
+ assert_equal("\x11\x11\x24", "".push_uint24(0x111124))
+ end
+
+ def test_push_uint32
+ assert_equal("\x10\x00\x00\x24", "".push_uint32(0x10000024))
+ end
+
+ def test_push
+ assert_equal("adh", "ad".push("h"))
+ end
+
+ def test_byteshift
+ sushi = "\u{1f363}".encode(Encoding::UTF_8)
+ assert_equal("\xf0".b, sushi.byteshift(1).b)
+ assert_equal("\x9f\x8d\xa3".b, sushi.b)
+ end
+end