xdr 0.1.0 → 3.0.2
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 +5 -5
- data/CHANGELOG.md +31 -0
- data/README.md +7 -2
- data/lib/xdr.rb +0 -1
- data/lib/xdr/concerns/converts_to_xdr.rb +47 -24
- data/lib/xdr/concerns/reads_bytes.rb +8 -0
- data/lib/xdr/dsl/enum.rb +1 -1
- data/lib/xdr/opaque.rb +1 -1
- data/lib/xdr/string.rb +1 -1
- data/lib/xdr/struct.rb +1 -1
- data/lib/xdr/union.rb +15 -6
- data/lib/xdr/var_opaque.rb +1 -1
- data/lib/xdr/version.rb +1 -1
- metadata +47 -133
- data/.gitignore +0 -15
- data/.travis.yml +0 -14
- data/.yardopts +0 -7
- data/Gemfile +0 -4
- data/Guardfile +0 -5
- data/Rakefile +0 -9
- data/examples/enum.rb +0 -30
- data/examples/struct.rb +0 -24
- data/examples/union.rb +0 -29
- data/spec/lib/xdr/array_spec.rb +0 -73
- data/spec/lib/xdr/bool_spec.rb +0 -43
- data/spec/lib/xdr/concerns/converts_to_xdr_spec.rb +0 -55
- data/spec/lib/xdr/concerns/reads_bytes_spec.rb +0 -31
- data/spec/lib/xdr/double_spec.rb +0 -38
- data/spec/lib/xdr/dsl/enum_spec.rb +0 -44
- data/spec/lib/xdr/dsl/struct_spec.rb +0 -29
- data/spec/lib/xdr/dsl/union_spec.rb +0 -69
- data/spec/lib/xdr/enum_spec.rb +0 -70
- data/spec/lib/xdr/float_spec.rb +0 -37
- data/spec/lib/xdr/hyper_spec.rb +0 -40
- data/spec/lib/xdr/int_spec.rb +0 -40
- data/spec/lib/xdr/opaque_spec.rb +0 -36
- data/spec/lib/xdr/option_spec.rb +0 -36
- data/spec/lib/xdr/quadruple_spec.rb +0 -14
- data/spec/lib/xdr/rpc/record_reader_spec.rb +0 -27
- data/spec/lib/xdr/string_spec.rb +0 -41
- data/spec/lib/xdr/struct_spec.rb +0 -101
- data/spec/lib/xdr/union_spec.rb +0 -248
- data/spec/lib/xdr/unsigned_hyper_spec.rb +0 -36
- data/spec/lib/xdr/unsigned_int_spec.rb +0 -36
- data/spec/lib/xdr/var_array_spec.rb +0 -71
- data/spec/lib/xdr/var_opaque_spec.rb +0 -43
- data/spec/lib/xdr/void_spec.rb +0 -46
- data/spec/spec_helper.rb +0 -15
- data/spec/support/matchers/eq_bytes.rb +0 -6
- data/xdr.gemspec +0 -29
data/spec/lib/xdr/union_spec.rb
DELETED
@@ -1,248 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe XDR::Union, ".read" do
|
4
|
-
|
5
|
-
subject{ UnionSpec::Result }
|
6
|
-
let(:result){ subject.read(bytes) }
|
7
|
-
|
8
|
-
context "with a void arm encoded" do
|
9
|
-
let(:bytes){ StringIO.new "\x00\x00\x00\x00" }
|
10
|
-
|
11
|
-
it "decodes correctly" do
|
12
|
-
expect(result).to be_a(UnionSpec::Result)
|
13
|
-
expect(result.switch).to eq(UnionSpec::ResultType.ok)
|
14
|
-
expect(result.arm).to be_nil
|
15
|
-
expect(result.get).to be_nil
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "with a non-void arm encoded" do
|
20
|
-
let(:bytes){ StringIO.new "\x00\x00\x00\x01\x00\x00\x00\x0812345678" }
|
21
|
-
|
22
|
-
it "decodes correctly" do
|
23
|
-
expect(result).to be_a(UnionSpec::Result)
|
24
|
-
expect(result.switch).to eq(UnionSpec::ResultType.error)
|
25
|
-
expect(result.arm).to eq(:message)
|
26
|
-
expect(result.get).to eq("12345678")
|
27
|
-
expect(result.message!).to eq("12345678")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "with a default arm encoded" do
|
32
|
-
let(:bytes){ StringIO.new "\x00\x00\x00\x02" }
|
33
|
-
|
34
|
-
it "decodes correctly" do
|
35
|
-
expect(result).to be_a(UnionSpec::Result)
|
36
|
-
expect(result.switch).to eq(UnionSpec::ResultType.nonsense)
|
37
|
-
expect(result.arm).to be_nil
|
38
|
-
expect(result.get).to be_nil
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "with a switch that is not a member of the switch_type" do
|
43
|
-
let(:bytes){ StringIO.new "\x00\x00\x00\x10" }
|
44
|
-
|
45
|
-
it "raises EnumValueError" do
|
46
|
-
expect{ result }.to raise_error XDR::EnumValueError
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "with a invalid arm encoded" do
|
51
|
-
let(:bytes){ StringIO.new "\x00\x00\x00\x02" }
|
52
|
-
subject{ UnionSpec::UnforfivingResult }
|
53
|
-
|
54
|
-
it "raises InvalidSwitchError" do
|
55
|
-
expect{ result }.to raise_error XDR::InvalidSwitchError
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
describe XDR::Union, "#attribute!" do
|
62
|
-
subject{ UnionSpec::Result.new(:ok) }
|
63
|
-
|
64
|
-
it "raises an ArmNotSetError when the attribute requested has not been populated" do
|
65
|
-
expect{ subject.message! }.to raise_error XDR::ArmNotSetError
|
66
|
-
end
|
67
|
-
|
68
|
-
it "returns the underyling value when the arm is populated" do
|
69
|
-
subject.set(:error, "it all went bad")
|
70
|
-
expect(subject.message!).to eq("it all went bad")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe XDR::Union, "#set" do
|
75
|
-
subject{ UnionSpec::ManyTypes.new }
|
76
|
-
|
77
|
-
it "sets the underlying member variables correctly" do
|
78
|
-
subject.set(:fixnum, 3)
|
79
|
-
expect(subject.switch).to eq(UnionSpec::Types.fixnum)
|
80
|
-
expect(subject.arm).to eq(:fixnum)
|
81
|
-
expect(subject.value).to eq(3)
|
82
|
-
|
83
|
-
subject.set(:float, 1.0)
|
84
|
-
expect(subject.switch).to eq(UnionSpec::Types.float)
|
85
|
-
expect(subject.arm).to eq(:float)
|
86
|
-
expect(subject.value).to eq(1.0)
|
87
|
-
|
88
|
-
subject.set(:array, [1,2])
|
89
|
-
expect(subject.switch).to eq(UnionSpec::Types.array)
|
90
|
-
expect(subject.arm).to eq(:array)
|
91
|
-
expect(subject.value).to eq([1,2])
|
92
|
-
|
93
|
-
subject.set(:bool, true)
|
94
|
-
expect(subject.switch).to eq(UnionSpec::Types.bool)
|
95
|
-
expect(subject.arm).to eq(:bool)
|
96
|
-
expect(subject.value).to eq(true)
|
97
|
-
|
98
|
-
subject.set(:optional, nil)
|
99
|
-
expect(subject.switch).to eq(UnionSpec::Types.optional)
|
100
|
-
expect(subject.arm).to eq(:optional)
|
101
|
-
expect(subject.value).to eq(nil)
|
102
|
-
|
103
|
-
subject.set(:optional, 3)
|
104
|
-
expect(subject.switch).to eq(UnionSpec::Types.optional)
|
105
|
-
expect(subject.arm).to eq(:optional)
|
106
|
-
expect(subject.value).to eq(3)
|
107
|
-
|
108
|
-
subject.set(:complex, UnionSpec::Result.new(:ok))
|
109
|
-
expect(subject.switch).to eq(UnionSpec::Types.complex)
|
110
|
-
expect(subject.arm).to eq(:complex)
|
111
|
-
expect(subject.value).to be_a(UnionSpec::Result)
|
112
|
-
|
113
|
-
subject.set(:void)
|
114
|
-
expect(subject.switch).to eq(UnionSpec::Types.void)
|
115
|
-
expect(subject.arm).to eq(nil)
|
116
|
-
expect(subject.value).to eq(nil)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "raises InvalidValueError if the value provided is not compatible with the selected arm" do
|
120
|
-
expect{ subject.set(:fixnum, 3.0) }.to raise_error(XDR::InvalidValueError)
|
121
|
-
expect{ subject.set(:fixnum, "hi") }.to raise_error(XDR::InvalidValueError)
|
122
|
-
expect{ subject.set(:fixnum, []) }.to raise_error(XDR::InvalidValueError)
|
123
|
-
expect{ subject.set(:fixnum, true) }.to raise_error(XDR::InvalidValueError)
|
124
|
-
|
125
|
-
expect{ subject.set(:float, 3) }.to raise_error(XDR::InvalidValueError)
|
126
|
-
expect{ subject.set(:float, "hi") }.to raise_error(XDR::InvalidValueError)
|
127
|
-
expect{ subject.set(:float, []) }.to raise_error(XDR::InvalidValueError)
|
128
|
-
expect{ subject.set(:float, true) }.to raise_error(XDR::InvalidValueError)
|
129
|
-
|
130
|
-
expect{ subject.set(:array, 3) }.to raise_error(XDR::InvalidValueError)
|
131
|
-
expect{ subject.set(:array, "hi") }.to raise_error(XDR::InvalidValueError)
|
132
|
-
expect{ subject.set(:array, 3.0) }.to raise_error(XDR::InvalidValueError)
|
133
|
-
expect{ subject.set(:array, true) }.to raise_error(XDR::InvalidValueError)
|
134
|
-
|
135
|
-
expect{ subject.set(:bool, 3) }.to raise_error(XDR::InvalidValueError)
|
136
|
-
expect{ subject.set(:bool, "hi") }.to raise_error(XDR::InvalidValueError)
|
137
|
-
expect{ subject.set(:bool, 3.0) }.to raise_error(XDR::InvalidValueError)
|
138
|
-
expect{ subject.set(:bool, []) }.to raise_error(XDR::InvalidValueError)
|
139
|
-
|
140
|
-
expect{ subject.set(:optional, "hi") }.to raise_error(XDR::InvalidValueError)
|
141
|
-
expect{ subject.set(:optional, 3.0) }.to raise_error(XDR::InvalidValueError)
|
142
|
-
expect{ subject.set(:optional, []) }.to raise_error(XDR::InvalidValueError)
|
143
|
-
expect{ subject.set(:optional, true) }.to raise_error(XDR::InvalidValueError)
|
144
|
-
|
145
|
-
expect{ subject.set(:complex, 3) }.to raise_error(XDR::InvalidValueError)
|
146
|
-
expect{ subject.set(:complex, "hi") }.to raise_error(XDR::InvalidValueError)
|
147
|
-
expect{ subject.set(:complex, 3.0) }.to raise_error(XDR::InvalidValueError)
|
148
|
-
expect{ subject.set(:complex, []) }.to raise_error(XDR::InvalidValueError)
|
149
|
-
expect{ subject.set(:complex, true) }.to raise_error(XDR::InvalidValueError)
|
150
|
-
|
151
|
-
expect{ subject.set(:void, 3) }.to raise_error(XDR::InvalidValueError)
|
152
|
-
expect{ subject.set(:void, "hi") }.to raise_error(XDR::InvalidValueError)
|
153
|
-
expect{ subject.set(:void, 3.0) }.to raise_error(XDR::InvalidValueError)
|
154
|
-
expect{ subject.set(:void, []) }.to raise_error(XDR::InvalidValueError)
|
155
|
-
expect{ subject.set(:void, true) }.to raise_error(XDR::InvalidValueError)
|
156
|
-
end
|
157
|
-
|
158
|
-
it "raises InvalidSwitchError if the provided switch is not compatible with the switch_type" do
|
159
|
-
expect{ subject.set 4 }.to raise_error(XDR::InvalidSwitchError)
|
160
|
-
expect{ subject.set "hi" }.to raise_error(XDR::InvalidSwitchError)
|
161
|
-
expect{ subject.set UnionSpec::ResultType.ok }.to raise_error(XDR::InvalidSwitchError)
|
162
|
-
end
|
163
|
-
|
164
|
-
context "when the union does not have a default switch" do
|
165
|
-
subject{ UnionSpec::UnforfivingResult.new }
|
166
|
-
|
167
|
-
#TODO
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
describe XDR::Union, "#switch" do
|
172
|
-
subject{ UnionSpec::Result.new }
|
173
|
-
|
174
|
-
it "reflects the set switch" do
|
175
|
-
subject.set :ok
|
176
|
-
expect( subject.switch ).to eq(UnionSpec::ResultType.ok)
|
177
|
-
subject.set :error, "broke"
|
178
|
-
expect( subject.switch ).to eq(UnionSpec::ResultType.error)
|
179
|
-
subject.set :nonsense
|
180
|
-
expect( subject.switch ).to eq(UnionSpec::ResultType.nonsense)
|
181
|
-
end
|
182
|
-
|
183
|
-
it "is aliased to the union's switch_name" do
|
184
|
-
subject.set :ok
|
185
|
-
expect( subject.type ).to eq(subject.switch)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
module UnionSpec
|
190
|
-
class ResultType < XDR::Enum
|
191
|
-
member :ok, 0
|
192
|
-
member :error, 1
|
193
|
-
member :nonsense, 2
|
194
|
-
|
195
|
-
seal
|
196
|
-
end
|
197
|
-
|
198
|
-
class Types < XDR::Enum
|
199
|
-
member :fixnum, 0
|
200
|
-
member :float, 1
|
201
|
-
member :array, 2
|
202
|
-
member :bool, 3
|
203
|
-
member :optional, 4
|
204
|
-
member :complex, 5
|
205
|
-
member :void, 6
|
206
|
-
|
207
|
-
seal
|
208
|
-
end
|
209
|
-
|
210
|
-
class Result < XDR::Union
|
211
|
-
switch_on ResultType, :type
|
212
|
-
|
213
|
-
switch ResultType.ok
|
214
|
-
switch ResultType.error, :message
|
215
|
-
switch :default
|
216
|
-
|
217
|
-
attribute :message, XDR::String[]
|
218
|
-
end
|
219
|
-
|
220
|
-
class UnforfivingResult < XDR::Union
|
221
|
-
switch_on ResultType, :type
|
222
|
-
|
223
|
-
switch :ok
|
224
|
-
switch :error, :message
|
225
|
-
|
226
|
-
attribute :message, XDR::String[]
|
227
|
-
end
|
228
|
-
|
229
|
-
class ManyTypes < XDR::Union
|
230
|
-
switch_on Types, :type
|
231
|
-
|
232
|
-
switch Types.fixnum, :fixnum
|
233
|
-
switch Types.float, :float
|
234
|
-
switch Types.array, :array
|
235
|
-
switch Types.bool, :bool
|
236
|
-
switch Types.optional, :optional
|
237
|
-
switch Types.complex, :complex
|
238
|
-
switch Types.void
|
239
|
-
|
240
|
-
|
241
|
-
attribute :fixnum, XDR::Hyper
|
242
|
-
attribute :float, XDR::Double
|
243
|
-
attribute :array, XDR::Array[XDR::Int, 2]
|
244
|
-
attribute :bool, XDR::Bool
|
245
|
-
attribute :optional, XDR::Option[XDR::Int]
|
246
|
-
attribute :complex, Result
|
247
|
-
end
|
248
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe XDR::UnsignedHyper, ".read" do
|
5
|
-
|
6
|
-
it "decodes values correctly" do
|
7
|
-
expect(read("\x00\x00\x00\x00\x00\x00\x00\x00")).to eq(0)
|
8
|
-
expect(read("\x00\x00\x00\x00\x00\x00\x00\x01")).to eq(1)
|
9
|
-
expect(read("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF")).to eq(2**64 - 1)
|
10
|
-
end
|
11
|
-
|
12
|
-
def read(str)
|
13
|
-
io = StringIO.new(str)
|
14
|
-
subject.read(io)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe XDR::UnsignedHyper, ".write" do
|
19
|
-
|
20
|
-
it "decodes values correctly" do
|
21
|
-
expect(write 0).to eq_bytes("\x00\x00\x00\x00\x00\x00\x00\x00")
|
22
|
-
expect(write 1).to eq_bytes("\x00\x00\x00\x00\x00\x00\x00\x01")
|
23
|
-
expect(write 2**64 - 1).to eq_bytes("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF")
|
24
|
-
end
|
25
|
-
|
26
|
-
it "raises WriteError when an Integer isn't passed" do
|
27
|
-
expect{ write 1.0 }.to raise_error(XDR::WriteError)
|
28
|
-
expect{ write "hi" }.to raise_error(XDR::WriteError)
|
29
|
-
end
|
30
|
-
|
31
|
-
def write(val)
|
32
|
-
io = StringIO.new()
|
33
|
-
subject.write(val, io)
|
34
|
-
io.string
|
35
|
-
end
|
36
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe XDR::UnsignedInt, ".read" do
|
5
|
-
|
6
|
-
it "decodes values correctly" do
|
7
|
-
expect(read("\x00\x00\x00\x00")).to eq(0)
|
8
|
-
expect(read("\x00\x00\x00\x01")).to eq(1)
|
9
|
-
expect(read("\xFF\xFF\xFF\xFF")).to eq(2**32 - 1)
|
10
|
-
end
|
11
|
-
|
12
|
-
def read(str)
|
13
|
-
io = StringIO.new(str)
|
14
|
-
subject.read(io)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe XDR::UnsignedInt, ".write" do
|
19
|
-
|
20
|
-
it "decodes values correctly" do
|
21
|
-
expect(write 0).to eq_bytes("\x00\x00\x00\x00")
|
22
|
-
expect(write 1).to eq_bytes("\x00\x00\x00\x01")
|
23
|
-
expect(write 2**32 - 1).to eq_bytes("\xFF\xFF\xFF\xFF")
|
24
|
-
end
|
25
|
-
|
26
|
-
it "raises WriteError when an Integer isn't passed" do
|
27
|
-
expect{ write 1.0 }.to raise_error(XDR::WriteError)
|
28
|
-
expect{ write "hi" }.to raise_error(XDR::WriteError)
|
29
|
-
end
|
30
|
-
|
31
|
-
def write(val)
|
32
|
-
io = StringIO.new()
|
33
|
-
subject.write(val, io)
|
34
|
-
io.string
|
35
|
-
end
|
36
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe XDR::VarArray, "#read" do
|
4
|
-
let(:empty_array) { "\x00\x00\x00\x00" }
|
5
|
-
let(:one_array) { "\x00\x00\x00\x01\x00\x00\x00\x00" }
|
6
|
-
let(:many_array) { "\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x00" }
|
7
|
-
let(:too_large_array) { "\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02" }
|
8
|
-
|
9
|
-
subject{ XDR::VarArray[XDR::Int, 2] }
|
10
|
-
|
11
|
-
it "decodes values correctly" do
|
12
|
-
expect(read(empty_array)).to eq([])
|
13
|
-
expect(read(one_array)).to eq([0])
|
14
|
-
expect(read(many_array)).to eq([3,0])
|
15
|
-
end
|
16
|
-
|
17
|
-
it "raises ReadError when the encoded array is too large" do
|
18
|
-
expect{ read(too_large_array) }.to raise_error(XDR::ReadError)
|
19
|
-
end
|
20
|
-
|
21
|
-
def read(str)
|
22
|
-
io = StringIO.new(str)
|
23
|
-
subject.read(io)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
describe XDR::VarArray, "#write" do
|
29
|
-
subject{ XDR::VarArray[XDR::Int, 3] }
|
30
|
-
|
31
|
-
it "encodes values correctly" do
|
32
|
-
expect(write([])).to eq("\x00\x00\x00\x00")
|
33
|
-
expect(write([7])).to eq("\x00\x00\x00\x01\x00\x00\x00\x07")
|
34
|
-
expect(write([1,2,3])).to eq("\x00\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03")
|
35
|
-
end
|
36
|
-
|
37
|
-
it "raises WriteError when the array to encode is too large" do
|
38
|
-
expect{ write([0,1,2,3]) }.to raise_error(XDR::WriteError)
|
39
|
-
end
|
40
|
-
|
41
|
-
def write(val)
|
42
|
-
io = StringIO.new
|
43
|
-
subject.write(val,io)
|
44
|
-
io.string
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe XDR::VarArray, "#valid?" do
|
49
|
-
subject{ XDR::VarArray[XDR::Int, 3] }
|
50
|
-
|
51
|
-
it "accepts an empty array" do
|
52
|
-
expect(subject.valid?([])).to be_truthy
|
53
|
-
end
|
54
|
-
|
55
|
-
it "accepts a filled array provided each element passes the child_type validator" do
|
56
|
-
expect(subject.valid?([1])).to be_truthy
|
57
|
-
expect(subject.valid?([1,2])).to be_truthy
|
58
|
-
end
|
59
|
-
|
60
|
-
it "rejects a filled array if any element is rejected by the child_type validator" do
|
61
|
-
expect(subject.valid?(["hello"])).to be_falsey
|
62
|
-
expect(subject.valid?([1, "hello"])).to be_falsey
|
63
|
-
expect(subject.valid?([1, "hello", 1])).to be_falsey
|
64
|
-
expect(subject.valid?([1, nil])).to be_falsey
|
65
|
-
expect(subject.valid?([nil])).to be_falsey
|
66
|
-
end
|
67
|
-
|
68
|
-
it "rejects arrays that are too large" do
|
69
|
-
expect(subject.valid?([1,2,3,4])).to be_falsey
|
70
|
-
end
|
71
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe XDR::VarOpaque, "#read" do
|
5
|
-
subject{ XDR::VarOpaque[2] }
|
6
|
-
|
7
|
-
it "decodes values correctly" do
|
8
|
-
expect(read("\x00\x00\x00\x00")).to eq("")
|
9
|
-
expect(read("\x00\x00\x00\x01\x00\x00\x00\x00")).to eq("\x00")
|
10
|
-
expect(read("\x00\x00\x00\x01\x01\x00\x00\x00")).to eq("\x01")
|
11
|
-
expect(read("\x00\x00\x00\x02\x00\x01\x00\x00")).to eq("\x00\x01")
|
12
|
-
end
|
13
|
-
|
14
|
-
it "raises a ReadError when the encoded length is greater than the allowed max" do
|
15
|
-
expect{ read "\x00\x00\x00\x03\x00\x00\x00\x00" }.to raise_error(XDR::ReadError)
|
16
|
-
end
|
17
|
-
|
18
|
-
def read(str)
|
19
|
-
io = StringIO.new(str)
|
20
|
-
subject.read(io)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe XDR::VarOpaque, "#write" do
|
25
|
-
subject{ XDR::VarOpaque[2] }
|
26
|
-
|
27
|
-
it "encodes values correctly" do
|
28
|
-
expect(write("")).to eq("\x00\x00\x00\x00")
|
29
|
-
expect(write("\x00")).to eq("\x00\x00\x00\x01\x00\x00\x00\x00")
|
30
|
-
expect(write("\x01")).to eq("\x00\x00\x00\x01\x01\x00\x00\x00")
|
31
|
-
expect(write("\x00\x01")).to eq("\x00\x00\x00\x02\x00\x01\x00\x00")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "raises a WriteError when the provided string is too long" do
|
35
|
-
expect{ write "123" }.to raise_error(XDR::WriteError)
|
36
|
-
end
|
37
|
-
|
38
|
-
def write(val)
|
39
|
-
io = StringIO.new()
|
40
|
-
subject.write(val, io)
|
41
|
-
io.string
|
42
|
-
end
|
43
|
-
end
|
data/spec/lib/xdr/void_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe XDR::Void, ".read" do
|
5
|
-
|
6
|
-
it "decodes values correctly" do
|
7
|
-
expect(read("\x00\x00\x00\x00")).to eq(:void)
|
8
|
-
expect(read("\x00\x00\x00\x01")).to eq(:void)
|
9
|
-
expect(read("\xFF\xFF\xFF\xFF")).to eq(:void)
|
10
|
-
expect(read("\x7F\xFF\xFF\xFF")).to eq(:void)
|
11
|
-
expect(read("\x80\x00\x00\x00")).to eq(:void)
|
12
|
-
end
|
13
|
-
|
14
|
-
def read(str)
|
15
|
-
io = StringIO.new(str)
|
16
|
-
subject.read(io)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe XDR::Void, ".write" do
|
21
|
-
|
22
|
-
it "decodes values correctly" do
|
23
|
-
expect(write :void).to eq("")
|
24
|
-
end
|
25
|
-
|
26
|
-
def write(val)
|
27
|
-
io = StringIO.new()
|
28
|
-
subject.write(val, io)
|
29
|
-
io.string
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe XDR::Void, ".valid?" do
|
34
|
-
|
35
|
-
it "accepts :void" do
|
36
|
-
expect(subject.valid?(:void)).to eq(true)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "rejects anything not :void" do
|
40
|
-
expect(subject.valid?(nil)).to eq(false)
|
41
|
-
expect(subject.valid?(0)).to eq(false)
|
42
|
-
expect(subject.valid?("hello")).to eq(false)
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
end
|