gitlab-cbor 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.gitlab-ci.yml +44 -0
- data/.travis.yml +24 -0
- data/CHANGELOG.md +30 -0
- data/ChangeLog +106 -0
- data/Gemfile +11 -0
- data/README.rdoc +191 -0
- data/Rakefile +97 -0
- data/ci/test.rb +31 -0
- data/doclib/cbor/buffer.rb +193 -0
- data/doclib/cbor/core_ext.rb +133 -0
- data/doclib/cbor/error.rb +14 -0
- data/doclib/cbor/packer.rb +133 -0
- data/doclib/cbor/simple.rb +15 -0
- data/doclib/cbor/tagged.rb +16 -0
- data/doclib/cbor/unpacker.rb +138 -0
- data/doclib/cbor.rb +80 -0
- data/ext/cbor/buffer.c +693 -0
- data/ext/cbor/buffer.h +484 -0
- data/ext/cbor/buffer_class.c +561 -0
- data/ext/cbor/buffer_class.h +41 -0
- data/ext/cbor/cbor.h +69 -0
- data/ext/cbor/compat.h +147 -0
- data/ext/cbor/core_ext.c +199 -0
- data/ext/cbor/core_ext.h +35 -0
- data/ext/cbor/extconf.rb +29 -0
- data/ext/cbor/packer.c +169 -0
- data/ext/cbor/packer.h +370 -0
- data/ext/cbor/packer_class.c +345 -0
- data/ext/cbor/packer_class.h +40 -0
- data/ext/cbor/rbinit.c +57 -0
- data/ext/cbor/renamer.h +56 -0
- data/ext/cbor/rmem.c +103 -0
- data/ext/cbor/rmem.h +118 -0
- data/ext/cbor/sysdep.h +139 -0
- data/ext/cbor/sysdep_endian.h +59 -0
- data/ext/cbor/sysdep_types.h +55 -0
- data/ext/cbor/unpacker.c +787 -0
- data/ext/cbor/unpacker.h +135 -0
- data/ext/cbor/unpacker_class.c +483 -0
- data/ext/cbor/unpacker_class.h +39 -0
- data/gitlab-cbor.gemspec +27 -0
- data/lib/cbor/version.rb +3 -0
- data/lib/cbor.rb +6 -0
- data/spec/buffer_io_spec.rb +260 -0
- data/spec/buffer_spec.rb +576 -0
- data/spec/cases.cbor +0 -0
- data/spec/cases.cbor_stream +0 -0
- data/spec/cases.json +1 -0
- data/spec/cases.msg +0 -0
- data/spec/cases_compact.msg +0 -0
- data/spec/cases_spec.rb +39 -0
- data/spec/format_spec.rb +603 -0
- data/spec/packer_spec.rb +127 -0
- data/spec/random_compat.rb +24 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/unpacker_spec.rb +260 -0
- metadata +189 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'random_compat'
|
|
3
|
+
|
|
4
|
+
require 'stringio'
|
|
5
|
+
if defined?(Encoding)
|
|
6
|
+
Encoding.default_external = 'ASCII-8BIT'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe Buffer do
|
|
10
|
+
r = Random.new
|
|
11
|
+
random_seed = r.seed
|
|
12
|
+
puts "buffer_io random seed: 0x#{random_seed.to_s(16)}"
|
|
13
|
+
|
|
14
|
+
let :source do
|
|
15
|
+
''
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def set_source(s)
|
|
19
|
+
source.replace(s)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
let :io do
|
|
23
|
+
StringIO.new(source.dup)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let :buffer do
|
|
27
|
+
Buffer.new(io)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
let :repetition do
|
|
31
|
+
ENV['SLOW'] ? 3 : 50
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'io returns internal io' do
|
|
35
|
+
buffer.io.should == io
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'close closes internal io' do
|
|
39
|
+
io.should_receive(:close)
|
|
40
|
+
buffer.close
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'short feed and read all' do
|
|
44
|
+
set_source 'aa'
|
|
45
|
+
buffer.read.should == 'aa'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'short feed and read short' do
|
|
49
|
+
set_source 'aa'
|
|
50
|
+
buffer.read(1).should == 'a'
|
|
51
|
+
buffer.read(1).should == 'a'
|
|
52
|
+
buffer.read(1).should == nil
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'long feed and read all' do
|
|
56
|
+
set_source ' '*(1024*1024)
|
|
57
|
+
s = buffer.read
|
|
58
|
+
s.size.should == source.size
|
|
59
|
+
s.should == source
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'long feed and read mixed' do
|
|
63
|
+
set_source ' '*(1024*1024)
|
|
64
|
+
buffer.read(10).should == source.slice!(0, 10)
|
|
65
|
+
buffer.read(10).should == source.slice!(0, 10)
|
|
66
|
+
buffer.read(10).should == source.slice!(0, 10)
|
|
67
|
+
s = buffer.read
|
|
68
|
+
s.size.should == source.size
|
|
69
|
+
s.should == source
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'eof' do
|
|
73
|
+
set_source ''
|
|
74
|
+
buffer.read.should == ''
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'eof 2' do
|
|
78
|
+
set_source 'a'
|
|
79
|
+
buffer.read.should == 'a'
|
|
80
|
+
buffer.read.should == ''
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'write short once and flush' do
|
|
84
|
+
buffer.write('aa')
|
|
85
|
+
buffer.flush
|
|
86
|
+
io.string.should == 'aa'
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it 'write short twice and flush' do
|
|
90
|
+
buffer.write('a')
|
|
91
|
+
buffer.write('a')
|
|
92
|
+
buffer.flush
|
|
93
|
+
io.string.should == 'aa'
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'write long once and flush' do
|
|
97
|
+
s = ' '*(1024*1024)
|
|
98
|
+
buffer.write s
|
|
99
|
+
buffer.flush
|
|
100
|
+
io.string.size.should == s.size
|
|
101
|
+
io.string.should == s
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'write short multi and flush' do
|
|
105
|
+
s = ' '*(1024*1024)
|
|
106
|
+
1024.times {
|
|
107
|
+
buffer.write ' '*1024
|
|
108
|
+
}
|
|
109
|
+
buffer.flush
|
|
110
|
+
io.string.size.should == s.size
|
|
111
|
+
io.string.should == s
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it 'random read' do
|
|
115
|
+
r = Random.new(random_seed)
|
|
116
|
+
|
|
117
|
+
repetition.times {
|
|
118
|
+
fragments = []
|
|
119
|
+
|
|
120
|
+
r.rand(4).times do
|
|
121
|
+
n = r.rand(1024*1400)
|
|
122
|
+
s = r.bytes(n)
|
|
123
|
+
fragments << s
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
io = StringIO.new(fragments.join)
|
|
127
|
+
b = Buffer.new(io)
|
|
128
|
+
|
|
129
|
+
fragments.each {|s|
|
|
130
|
+
x = b.read(s.size)
|
|
131
|
+
x.size.should == s.size
|
|
132
|
+
x.should == s
|
|
133
|
+
}
|
|
134
|
+
b.empty?.should == true
|
|
135
|
+
b.read.should == ''
|
|
136
|
+
}
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it 'random read_all' do
|
|
140
|
+
r = Random.new(random_seed)
|
|
141
|
+
|
|
142
|
+
repetition.times {
|
|
143
|
+
fragments = []
|
|
144
|
+
sx = r.bytes(0)
|
|
145
|
+
|
|
146
|
+
r.rand(4).times do
|
|
147
|
+
n = r.rand(1024*1400)
|
|
148
|
+
s = r.bytes(n)
|
|
149
|
+
fragments << s
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
io = StringIO.new(fragments.join)
|
|
153
|
+
b = Buffer.new(io)
|
|
154
|
+
|
|
155
|
+
fragments.each {|s|
|
|
156
|
+
x = b.read_all(s.size)
|
|
157
|
+
x.size.should == s.size
|
|
158
|
+
x.should == s
|
|
159
|
+
}
|
|
160
|
+
b.empty?.should == true
|
|
161
|
+
lambda {
|
|
162
|
+
b.read_all(1)
|
|
163
|
+
}.should raise_error(EOFError)
|
|
164
|
+
}
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it 'random skip' do
|
|
168
|
+
r = Random.new(random_seed)
|
|
169
|
+
|
|
170
|
+
repetition.times {
|
|
171
|
+
fragments = []
|
|
172
|
+
|
|
173
|
+
r.rand(4).times do
|
|
174
|
+
n = r.rand(1024*1400)
|
|
175
|
+
s = r.bytes(n)
|
|
176
|
+
fragments << s
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
io = StringIO.new(fragments.join)
|
|
180
|
+
b = Buffer.new(io)
|
|
181
|
+
|
|
182
|
+
fragments.each {|s|
|
|
183
|
+
b.skip(s.size).should == s.size
|
|
184
|
+
}
|
|
185
|
+
b.empty?.should == true
|
|
186
|
+
b.skip(1).should == 0
|
|
187
|
+
}
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it 'random skip_all' do
|
|
191
|
+
r = Random.new(random_seed)
|
|
192
|
+
|
|
193
|
+
repetition.times {
|
|
194
|
+
fragments = []
|
|
195
|
+
|
|
196
|
+
r.rand(4).times do
|
|
197
|
+
n = r.rand(1024*1400)
|
|
198
|
+
s = r.bytes(n)
|
|
199
|
+
fragments << s
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
io = StringIO.new(fragments.join)
|
|
203
|
+
b = Buffer.new(io)
|
|
204
|
+
|
|
205
|
+
fragments.each {|s|
|
|
206
|
+
lambda {
|
|
207
|
+
b.skip_all(s.size)
|
|
208
|
+
}.should_not raise_error()
|
|
209
|
+
}
|
|
210
|
+
b.empty?.should == true
|
|
211
|
+
lambda {
|
|
212
|
+
b.skip_all(1)
|
|
213
|
+
}.should raise_error(EOFError)
|
|
214
|
+
}
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it 'random write and flush' do
|
|
218
|
+
r = Random.new(random_seed)
|
|
219
|
+
|
|
220
|
+
repetition.times {
|
|
221
|
+
s = r.bytes(0)
|
|
222
|
+
io = StringIO.new
|
|
223
|
+
b = Buffer.new(io)
|
|
224
|
+
|
|
225
|
+
r.rand(4).times do
|
|
226
|
+
n = r.rand(1024*1400)
|
|
227
|
+
x = r.bytes(n)
|
|
228
|
+
s << x
|
|
229
|
+
b.write(x)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
(io.string.size + b.size).should == s.size
|
|
233
|
+
|
|
234
|
+
b.flush
|
|
235
|
+
|
|
236
|
+
io.string.size.should == s.size
|
|
237
|
+
io.string.should == s
|
|
238
|
+
}
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
it 'random write and clear' do
|
|
242
|
+
r = Random.new(random_seed)
|
|
243
|
+
b = Buffer.new
|
|
244
|
+
|
|
245
|
+
repetition.times {
|
|
246
|
+
s = r.bytes(0)
|
|
247
|
+
|
|
248
|
+
r.rand(4).times do
|
|
249
|
+
n = r.rand(1024*1400)
|
|
250
|
+
x = r.bytes(n)
|
|
251
|
+
s << x
|
|
252
|
+
b.write(x)
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
b.size.should == s.size
|
|
256
|
+
b.clear
|
|
257
|
+
}
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
|