bindata 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bindata might be problematic. Click here for more details.
- data/ChangeLog.rdoc +7 -0
- data/NEWS.rdoc +11 -0
- data/Rakefile +6 -1
- data/bindata.gemspec +2 -1
- data/doc/manual.md +17 -9
- data/examples/gzip.rb +2 -2
- data/examples/list.rb +2 -2
- data/lib/bindata/alignment.rb +4 -9
- data/lib/bindata/array.rb +57 -51
- data/lib/bindata/base.rb +13 -110
- data/lib/bindata/base_primitive.rb +130 -75
- data/lib/bindata/bits.rb +5 -7
- data/lib/bindata/choice.rb +24 -32
- data/lib/bindata/dsl.rb +1 -6
- data/lib/bindata/framework.rb +81 -0
- data/lib/bindata/int.rb +5 -7
- data/lib/bindata/name.rb +28 -0
- data/lib/bindata/offset.rb +42 -53
- data/lib/bindata/params.rb +33 -38
- data/lib/bindata/struct.rb +2 -6
- data/lib/bindata/trace.rb +16 -16
- data/lib/bindata/version.rb +1 -1
- data/lib/bindata/virtual.rb +3 -3
- data/{spec/alignment_spec.rb → test/alignment_test.rb} +17 -16
- data/test/array_test.rb +371 -0
- data/test/base_primitive_test.rb +312 -0
- data/test/base_test.rb +183 -0
- data/{spec/bits_spec.rb → test/bits_test.rb} +59 -59
- data/test/choice_test.rb +260 -0
- data/{spec/spec_common.rb → test/common.rb} +33 -18
- data/test/count_bytes_remaining_test.rb +41 -0
- data/{spec/deprecated_spec.rb → test/deprecated_test.rb} +5 -7
- data/test/float_test.rb +72 -0
- data/{spec/int_spec.rb → test/int_test.rb} +34 -43
- data/{spec/io_spec.rb → test/io_test.rb} +70 -71
- data/{spec/lazy_spec.rb → test/lazy_test.rb} +38 -39
- data/test/offset_test.rb +93 -0
- data/test/params_test.rb +144 -0
- data/{spec/primitive_spec.rb → test/primitive_test.rb} +42 -54
- data/{spec/record_spec.rb → test/record_test.rb} +133 -154
- data/test/registry_test.rb +104 -0
- data/test/rest_test.rb +29 -0
- data/test/skip_test.rb +28 -0
- data/{spec/string_spec.rb → test/string_test.rb} +96 -97
- data/test/stringz_test.rb +127 -0
- data/{spec/struct_spec.rb → test/struct_test.rb} +119 -120
- data/{spec/system_spec.rb → test/system_test.rb} +66 -106
- metadata +39 -38
- data/lib/a.rb +0 -24
- data/spec/array_spec.rb +0 -331
- data/spec/base_primitive_spec.rb +0 -238
- data/spec/base_spec.rb +0 -376
- data/spec/choice_spec.rb +0 -263
- data/spec/count_bytes_remaining_spec.rb +0 -38
- data/spec/example.rb +0 -21
- data/spec/float_spec.rb +0 -37
- data/spec/registry_spec.rb +0 -108
- data/spec/rest_spec.rb +0 -26
- data/spec/skip_spec.rb +0 -27
- data/spec/stringz_spec.rb +0 -118
- data/tasks/rspec.rake +0 -17
@@ -0,0 +1,104 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "common"))
|
4
|
+
|
5
|
+
describe BinData::Registry do
|
6
|
+
A = Class.new
|
7
|
+
B = Class.new
|
8
|
+
C = Class.new
|
9
|
+
D = Class.new
|
10
|
+
|
11
|
+
let(:r) { BinData::Registry.new }
|
12
|
+
|
13
|
+
it "lookups registered names" do
|
14
|
+
r.register('ASubClass', A)
|
15
|
+
r.register('AnotherSubClass', B)
|
16
|
+
|
17
|
+
r.lookup('ASubClass').must_equal A
|
18
|
+
r.lookup('a_sub_class').must_equal A
|
19
|
+
r.lookup('AnotherSubClass').must_equal B
|
20
|
+
r.lookup('another_sub_class').must_equal B
|
21
|
+
end
|
22
|
+
|
23
|
+
it "does not lookup unregistered names" do
|
24
|
+
lambda {
|
25
|
+
r.lookup('a_non_existent_sub_class')
|
26
|
+
}.must_raise BinData::UnRegisteredTypeError
|
27
|
+
end
|
28
|
+
|
29
|
+
it "unregisters names" do
|
30
|
+
r.register('ASubClass', A)
|
31
|
+
r.unregister('ASubClass')
|
32
|
+
|
33
|
+
lambda {
|
34
|
+
r.lookup('ASubClass')
|
35
|
+
}.must_raise BinData::UnRegisteredTypeError
|
36
|
+
end
|
37
|
+
|
38
|
+
it "allows overriding of registered classes" do
|
39
|
+
r.register('A', A)
|
40
|
+
r.register('A', B)
|
41
|
+
|
42
|
+
r.lookup('a').must_equal B
|
43
|
+
end
|
44
|
+
|
45
|
+
it "converts CamelCase to underscores" do
|
46
|
+
r.underscore_name('CamelCase').must_equal 'camel_case'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "converts adjacent caps camelCase to underscores" do
|
50
|
+
r.underscore_name('XYZCamelCase').must_equal 'xyz_camel_case'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "ignores the outer nestings of classes" do
|
54
|
+
r.underscore_name('A::B::C').must_equal 'c'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe BinData::Registry, "with numerics" do
|
59
|
+
let(:r) { BinData::RegisteredClasses }
|
60
|
+
|
61
|
+
it "lookup integers with endian" do
|
62
|
+
r.lookup("int24", :big).to_s.must_equal "BinData::Int24be"
|
63
|
+
r.lookup("int24", :little).to_s.must_equal "BinData::Int24le"
|
64
|
+
r.lookup("uint24", :big).to_s.must_equal "BinData::Uint24be"
|
65
|
+
r.lookup("uint24", :little).to_s.must_equal "BinData::Uint24le"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "does not lookup integers without endian" do
|
69
|
+
lambda {
|
70
|
+
r.lookup("int24")
|
71
|
+
}.must_raise BinData::UnRegisteredTypeError
|
72
|
+
end
|
73
|
+
|
74
|
+
it "does not lookup non byte based integers" do
|
75
|
+
lambda {
|
76
|
+
r.lookup("int3")
|
77
|
+
}.must_raise BinData::UnRegisteredTypeError
|
78
|
+
lambda {
|
79
|
+
r.lookup("int3", :big)
|
80
|
+
}.must_raise BinData::UnRegisteredTypeError
|
81
|
+
lambda {
|
82
|
+
r.lookup("int3", :little)
|
83
|
+
}.must_raise BinData::UnRegisteredTypeError
|
84
|
+
end
|
85
|
+
|
86
|
+
it "lookup floats with endian" do
|
87
|
+
r.lookup("float", :big).to_s.must_equal "BinData::FloatBe"
|
88
|
+
r.lookup("float", :little).to_s.must_equal "BinData::FloatLe"
|
89
|
+
r.lookup("double", :big).to_s.must_equal "BinData::DoubleBe"
|
90
|
+
r.lookup("double", :little).to_s.must_equal "BinData::DoubleLe"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "lookup bits" do
|
94
|
+
r.lookup("bit5").to_s.must_equal "BinData::Bit5"
|
95
|
+
r.lookup("bit6le").to_s.must_equal "BinData::Bit6le"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "lookup bits by ignoring endian" do
|
99
|
+
r.lookup("bit2", :big).to_s.must_equal "BinData::Bit2"
|
100
|
+
r.lookup("bit3le", :big).to_s.must_equal "BinData::Bit3le"
|
101
|
+
r.lookup("bit2", :little).to_s.must_equal "BinData::Bit2"
|
102
|
+
r.lookup("bit3le", :little).to_s.must_equal "BinData::Bit3le"
|
103
|
+
end
|
104
|
+
end
|
data/test/rest_test.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "common"))
|
4
|
+
|
5
|
+
describe BinData::Rest do
|
6
|
+
let(:obj) { BinData::Rest.new }
|
7
|
+
|
8
|
+
it "initial state" do
|
9
|
+
obj.must_equal ""
|
10
|
+
end
|
11
|
+
|
12
|
+
it "reads till end of stream" do
|
13
|
+
data = "abcdefghij"
|
14
|
+
obj.read(data).must_equal data
|
15
|
+
end
|
16
|
+
|
17
|
+
it "allows setting value for completeness" do
|
18
|
+
obj.assign("123")
|
19
|
+
obj.must_equal "123"
|
20
|
+
obj.to_binary_s.must_equal "123"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "accepts BinData::BasePrimitive parameters" do
|
24
|
+
rest = BinData::Rest.new(:assert => "abc")
|
25
|
+
lambda {
|
26
|
+
rest.read("xyz")
|
27
|
+
}.must_raise BinData::ValidityError
|
28
|
+
end
|
29
|
+
end
|
data/test/skip_test.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "common"))
|
4
|
+
|
5
|
+
describe BinData::Skip do
|
6
|
+
let(:obj) { BinData::Skip.new(:length => 5) }
|
7
|
+
let(:io) { StringIO.new("abcdefghij") }
|
8
|
+
|
9
|
+
it "initial state" do
|
10
|
+
obj.must_equal ""
|
11
|
+
obj.to_binary_s.must_equal "\000" * 5
|
12
|
+
end
|
13
|
+
|
14
|
+
it "skips bytes" do
|
15
|
+
obj.read(io)
|
16
|
+
io.pos.must_equal 5
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has expected binary representation after setting value" do
|
20
|
+
obj.assign("123")
|
21
|
+
obj.to_binary_s.must_equal "\000" * 5
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has expected binary representation after reading" do
|
25
|
+
obj.read(io)
|
26
|
+
obj.to_binary_s.must_equal "\000" * 5
|
27
|
+
end
|
28
|
+
end
|
@@ -1,23 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "
|
4
|
-
require 'bindata/io'
|
5
|
-
require 'bindata/string'
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "common"))
|
6
4
|
|
7
5
|
describe BinData::String, "with mutually exclusive parameters" do
|
8
6
|
it ":value and :initial_value" do
|
9
7
|
params = {:value => "", :initial_value => ""}
|
10
|
-
|
8
|
+
lambda { BinData::String.new(params) }.must_raise ArgumentError
|
11
9
|
end
|
12
10
|
|
13
11
|
it ":length and :read_length" do
|
14
12
|
params = {:length => 5, :read_length => 5}
|
15
|
-
|
13
|
+
lambda { BinData::String.new(params) }.must_raise ArgumentError
|
16
14
|
end
|
17
15
|
|
18
16
|
it ":value and :length" do
|
19
17
|
params = {:value => "", :length => 5}
|
20
|
-
|
18
|
+
lambda { BinData::String.new(params) }.must_raise ArgumentError
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
@@ -27,140 +25,141 @@ describe BinData::String, "when assigning" do
|
|
27
25
|
|
28
26
|
it "copies data from small to large" do
|
29
27
|
large.assign(small)
|
30
|
-
large.
|
28
|
+
large.must_equal "AAABB"
|
31
29
|
end
|
32
30
|
|
33
31
|
it "copies data from large to small" do
|
34
32
|
small.assign(large)
|
35
|
-
small.
|
33
|
+
small.must_equal "BBB"
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
37
|
describe BinData::String do
|
40
|
-
|
38
|
+
let(:obj) { BinData::String.new("testing") }
|
41
39
|
|
42
40
|
it "compares with regexp" do
|
43
|
-
(/es/ =~
|
41
|
+
(/es/ =~ obj).must_equal 1
|
44
42
|
end
|
45
43
|
|
46
44
|
it "compares with regexp" do
|
47
|
-
(
|
45
|
+
(obj =~ /es/).must_equal 1
|
48
46
|
end
|
49
47
|
end
|
50
48
|
|
51
49
|
describe BinData::String, "with :read_length" do
|
52
|
-
|
50
|
+
let(:obj) { BinData::String.new(:read_length => 5) }
|
53
51
|
|
54
|
-
|
55
|
-
|
52
|
+
specify { obj.num_bytes.must_equal 0 }
|
53
|
+
specify { obj.value.must_equal "" }
|
56
54
|
|
57
55
|
it "reads :read_length bytes" do
|
58
|
-
|
59
|
-
|
56
|
+
obj.read("abcdefghij")
|
57
|
+
obj.must_equal "abcde"
|
60
58
|
end
|
61
59
|
|
62
60
|
it "remembers :read_length after value is cleared" do
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
obj.assign("abc")
|
62
|
+
obj.num_bytes.must_equal 3
|
63
|
+
obj.clear
|
66
64
|
|
67
|
-
|
68
|
-
|
65
|
+
obj.read("abcdefghij")
|
66
|
+
obj.must_equal "abcde"
|
69
67
|
end
|
70
68
|
end
|
71
69
|
|
72
70
|
describe BinData::String, "with :length" do
|
73
|
-
|
71
|
+
let(:obj) { BinData::String.new(:length => 5) }
|
74
72
|
|
75
|
-
|
76
|
-
|
73
|
+
specify { obj.num_bytes.must_equal 5 }
|
74
|
+
specify { obj.value.must_equal "\0\0\0\0\0" }
|
77
75
|
|
78
76
|
it "retains :length after value is set" do
|
79
|
-
|
80
|
-
|
77
|
+
obj.assign("abcdefghij")
|
78
|
+
obj.num_bytes.must_equal 5
|
81
79
|
end
|
82
80
|
|
83
81
|
it "reads :length bytes" do
|
84
|
-
|
85
|
-
|
82
|
+
obj.read("abcdefghij")
|
83
|
+
obj.must_equal "abcde"
|
86
84
|
end
|
87
85
|
|
88
86
|
it "pads values less than :length" do
|
89
|
-
|
90
|
-
|
87
|
+
obj.assign("abc")
|
88
|
+
obj.must_equal "abc\0\0"
|
91
89
|
end
|
92
90
|
|
93
91
|
it "accepts values exactly :length" do
|
94
|
-
|
95
|
-
|
92
|
+
obj.assign("abcde")
|
93
|
+
obj.must_equal "abcde"
|
96
94
|
end
|
97
95
|
|
98
96
|
it "truncates values greater than :length" do
|
99
|
-
|
100
|
-
|
97
|
+
obj.assign("abcdefghij")
|
98
|
+
obj.must_equal "abcde"
|
101
99
|
end
|
102
100
|
end
|
103
101
|
|
104
102
|
describe BinData::String, "with :read_length and :initial_value" do
|
105
|
-
|
103
|
+
let(:obj) { BinData::String.new(:read_length => 5, :initial_value => "abcdefghij") }
|
106
104
|
|
107
|
-
|
108
|
-
|
105
|
+
specify { obj.num_bytes.must_equal 10 }
|
106
|
+
specify { obj.value.must_equal "abcdefghij" }
|
109
107
|
|
110
108
|
it "uses :read_length for reading" do
|
111
109
|
io = StringIO.new("ABCDEFGHIJKLMNOPQRST")
|
112
|
-
|
113
|
-
io.pos.
|
110
|
+
obj.read(io)
|
111
|
+
io.pos.must_equal 5
|
114
112
|
end
|
115
113
|
|
116
114
|
it "forgets :initial_value after reading" do
|
117
|
-
|
118
|
-
|
119
|
-
|
115
|
+
obj.read("ABCDEFGHIJKLMNOPQRST")
|
116
|
+
obj.num_bytes.must_equal 5
|
117
|
+
obj.must_equal "ABCDE"
|
120
118
|
end
|
121
119
|
end
|
122
120
|
|
123
121
|
describe BinData::String, "with :read_length and :value" do
|
124
|
-
|
122
|
+
let(:obj) { BinData::String.new(:read_length => 5, :value => "abcdefghij") }
|
125
123
|
|
126
|
-
|
127
|
-
|
124
|
+
specify { obj.num_bytes.must_equal 10 }
|
125
|
+
specify { obj.value.must_equal "abcdefghij" }
|
128
126
|
|
129
127
|
it "uses :read_length for reading" do
|
130
128
|
io = StringIO.new("ABCDEFGHIJKLMNOPQRST")
|
131
|
-
|
132
|
-
io.pos.
|
129
|
+
obj.read(io)
|
130
|
+
io.pos.must_equal 5
|
133
131
|
end
|
134
132
|
|
135
|
-
|
133
|
+
describe "after reading" do
|
136
134
|
before(:each) do
|
137
|
-
|
135
|
+
obj.read("ABCDEFGHIJKLMNOPQRST")
|
138
136
|
end
|
139
137
|
|
140
138
|
it "is not affected by :read_length after reading" do
|
141
|
-
|
142
|
-
|
139
|
+
obj.num_bytes.must_equal 10
|
140
|
+
obj.must_equal "abcdefghij"
|
143
141
|
end
|
144
142
|
|
145
143
|
it "returns read value while reading" do
|
146
|
-
|
147
|
-
|
144
|
+
obj.stub :reading?, true do
|
145
|
+
obj.must_equal "ABCDE"
|
146
|
+
end
|
148
147
|
end
|
149
148
|
end
|
150
149
|
end
|
151
150
|
|
152
151
|
describe BinData::String, "with :length and :initial_value" do
|
153
|
-
|
152
|
+
let(:obj) { BinData::String.new(:length => 5, :initial_value => "abcdefghij") }
|
154
153
|
|
155
|
-
|
156
|
-
|
154
|
+
specify { obj.num_bytes.must_equal 5 }
|
155
|
+
specify { obj.value.must_equal "abcde" }
|
157
156
|
|
158
157
|
it "forgets :initial_value after reading" do
|
159
158
|
io = StringIO.new("ABCDEFGHIJKLMNOPQRST")
|
160
|
-
|
161
|
-
io.pos.
|
162
|
-
|
163
|
-
|
159
|
+
obj.read(io)
|
160
|
+
io.pos.must_equal 5
|
161
|
+
obj.num_bytes.must_equal 5
|
162
|
+
obj.must_equal "ABCDE"
|
164
163
|
end
|
165
164
|
end
|
166
165
|
|
@@ -168,18 +167,18 @@ describe BinData::String, "with :pad_byte" do
|
|
168
167
|
it "accepts a numeric value for :pad_byte" do
|
169
168
|
str = BinData::String.new(:length => 5, :pad_byte => 6)
|
170
169
|
str.assign("abc")
|
171
|
-
str.
|
170
|
+
str.must_equal "abc\x06\x06"
|
172
171
|
end
|
173
172
|
|
174
173
|
it "accepts a character for :pad_byte" do
|
175
174
|
str = BinData::String.new(:length => 5, :pad_byte => "R")
|
176
175
|
str.assign("abc")
|
177
|
-
str.
|
176
|
+
str.must_equal "abcRR"
|
178
177
|
end
|
179
178
|
|
180
179
|
it "does not accept a string for :pad_byte" do
|
181
180
|
params = {:length => 5, :pad_byte => "RR"}
|
182
|
-
lambda { BinData::String.new(params) }.
|
181
|
+
lambda { BinData::String.new(params) }.must_raise ArgumentError
|
183
182
|
end
|
184
183
|
end
|
185
184
|
|
@@ -189,31 +188,31 @@ describe BinData::String, "with :trim_padding" do
|
|
189
188
|
str2 = BinData::String.new(:length => 5, :trim_padding => false)
|
190
189
|
str1.assign("abc")
|
191
190
|
str2.assign("abc")
|
192
|
-
str1.
|
193
|
-
str2.
|
191
|
+
str1.must_equal "abc\0\0"
|
192
|
+
str2.must_equal "abc\0\0"
|
194
193
|
end
|
195
194
|
|
196
|
-
|
197
|
-
|
195
|
+
describe "trim padding set" do
|
196
|
+
let(:obj) { BinData::String.new(:pad_byte => 'R', :trim_padding => true) }
|
198
197
|
|
199
198
|
it "trims the value" do
|
200
|
-
|
201
|
-
|
199
|
+
obj.assign("abcRR")
|
200
|
+
obj.must_equal "abc"
|
202
201
|
end
|
203
202
|
|
204
203
|
it "does not affect num_bytes" do
|
205
|
-
|
206
|
-
|
204
|
+
obj.assign("abcRR")
|
205
|
+
obj.num_bytes.must_equal 5
|
207
206
|
end
|
208
207
|
|
209
208
|
it "trims if last char is :pad_byte" do
|
210
|
-
|
211
|
-
|
209
|
+
obj.assign("abcRR")
|
210
|
+
obj.must_equal "abc"
|
212
211
|
end
|
213
212
|
|
214
213
|
it "does not trim if value contains :pad_byte not at the end" do
|
215
|
-
|
216
|
-
|
214
|
+
obj.assign("abcRRde")
|
215
|
+
obj.must_equal "abcRRde"
|
217
216
|
end
|
218
217
|
end
|
219
218
|
end
|
@@ -224,38 +223,38 @@ describe BinData::String, "with :pad_front" do
|
|
224
223
|
str2 = BinData::String.new(:length => 5, :pad_front => false)
|
225
224
|
str1.assign("abc")
|
226
225
|
str2.assign("abc")
|
227
|
-
str1.
|
228
|
-
str2.
|
226
|
+
str1.must_equal "abc\0\0"
|
227
|
+
str2.must_equal "abc\0\0"
|
229
228
|
end
|
230
229
|
|
231
230
|
it "pads to the front" do
|
232
231
|
str = BinData::String.new(:length => 5, :pad_byte => 'R', :pad_front => true)
|
233
232
|
str.assign("abc")
|
234
|
-
str.
|
233
|
+
str.must_equal "RRabc"
|
235
234
|
end
|
236
235
|
|
237
236
|
it "can alternatively be accesses by :pad_left" do
|
238
237
|
str = BinData::String.new(:length => 5, :pad_byte => 'R', :pad_left => true)
|
239
238
|
str.assign("abc")
|
240
|
-
str.
|
239
|
+
str.must_equal "RRabc"
|
241
240
|
end
|
242
241
|
|
243
|
-
|
244
|
-
|
242
|
+
describe "and :trim_padding" do
|
243
|
+
let(:obj) { BinData::String.new(:length => 5, :pad_byte => 'R', :pad_front => true, :trim_padding => true) }
|
245
244
|
|
246
245
|
it "assigns" do
|
247
|
-
|
248
|
-
|
246
|
+
obj.assign("abc")
|
247
|
+
obj.must_equal "abc"
|
249
248
|
end
|
250
249
|
|
251
250
|
it "has to_binary_s" do
|
252
|
-
|
253
|
-
|
251
|
+
obj.assign("abc")
|
252
|
+
obj.to_binary_s.must_equal "RRabc"
|
254
253
|
end
|
255
254
|
|
256
255
|
it "reads" do
|
257
|
-
|
258
|
-
|
256
|
+
obj.read "RRabc"
|
257
|
+
obj.must_equal "abc"
|
259
258
|
end
|
260
259
|
end
|
261
260
|
end
|
@@ -268,32 +267,32 @@ describe BinData::String, "with Ruby 1.9 encodings" do
|
|
268
267
|
end
|
269
268
|
end
|
270
269
|
|
271
|
-
|
270
|
+
let(:obj) { UTF8String.new }
|
272
271
|
let(:binary_str) { binary("\xC3\x85\xC3\x84\xC3\x96") }
|
273
272
|
let(:utf8_str) { binary_str.dup.force_encoding('UTF-8') }
|
274
273
|
|
275
274
|
it "stores assigned values as binary" do
|
276
|
-
|
277
|
-
|
275
|
+
obj.assign(utf8_str)
|
276
|
+
obj.to_binary_s.must_equal binary_str
|
278
277
|
end
|
279
278
|
|
280
279
|
it "stores read values as binary" do
|
281
|
-
|
282
|
-
|
280
|
+
obj = UTF8String.new(:read_length => binary_str.length)
|
281
|
+
obj.read(binary_str)
|
283
282
|
|
284
|
-
|
283
|
+
obj.to_binary_s.must_equal binary_str
|
285
284
|
end
|
286
285
|
|
287
286
|
it "returns values in correct encoding" do
|
288
|
-
|
287
|
+
obj.assign(utf8_str)
|
289
288
|
|
290
|
-
|
289
|
+
obj.snapshot.must_equal utf8_str
|
291
290
|
end
|
292
291
|
|
293
292
|
it "has correct num_bytes" do
|
294
|
-
|
293
|
+
obj.assign(utf8_str)
|
295
294
|
|
296
|
-
|
295
|
+
obj.num_bytes.must_equal binary_str.length
|
297
296
|
end
|
298
297
|
end
|
299
298
|
end
|