test/int_test.rb in bindata-2.1.0 vs test/int_test.rb in bindata-2.2.0
- old
+ new
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby
-require File.expand_path(File.join(File.dirname(__FILE__), "common"))
+require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
module AllIntegers
def test_have_correct_num_bytes
all_classes do |int_class|
@@ -80,11 +80,11 @@
val = gen_test_int
subject = int_class.new
subject.assign(val)
- subject.to_binary_s.must_equal int_to_binary_str(val)
+ subject.to_binary_s.must_equal_binary int_to_binary_str(val)
end
end
def test_convert_a_negative_number_to_string
all_classes do |int_class|
@@ -92,11 +92,11 @@
val = -gen_test_int
subject = int_class.new
subject.assign(val)
- subject.to_binary_s.must_equal int_to_binary_str(val)
+ subject.to_binary_s.must_equal_binary int_to_binary_str(val)
end
end
end
def all_classes(&block)
@@ -126,10 +126,10 @@
# resulting int is guaranteed to be +ve for signed or unsigned integers
(0 ... @nbytes).inject(0) { |val, i| (val << 8) | ((val + 0x11) % 0x100) }
end
def int_to_binary_str(val)
- str = binary("")
+ str = "".force_encoding(Encoding::BINARY)
v = val & ((1 << (@nbytes * 8)) - 1)
@nbytes.times do
str.concat(v & 0xff)
v >>= 8
end