xdr 3.0.1 → 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 +4 -4
- data/CHANGELOG.md +12 -9
- data/README.md +4 -2
- data/lib/xdr/concerns/converts_to_xdr.rb +30 -31
- data/lib/xdr/union.rb +7 -4
- data/lib/xdr/version.rb +1 -1
- metadata +43 -114
- data/.gitignore +0 -15
- data/.travis.yml +0 -9
- 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 -88
- data/spec/lib/xdr/concerns/reads_bytes_spec.rb +0 -57
- 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 -40
- 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 -47
- data/spec/lib/xdr/struct_spec.rb +0 -101
- data/spec/lib/xdr/union_spec.rb +0 -258
- 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 -50
- 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 -28
@@ -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,50 +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
|
-
|
19
|
-
it "raises a ReadError when the padding isn't zeros" do
|
20
|
-
expect{ read "\x00\x00\x00\x01\x01\x00\x00\x01" }.to raise_error(XDR::ReadError)
|
21
|
-
expect{ read "\x00\x00\x00\x01\x01\x00\x01\x00" }.to raise_error(XDR::ReadError)
|
22
|
-
expect{ read "\x00\x00\x00\x01\x01\x01\x00\x00" }.to raise_error(XDR::ReadError)
|
23
|
-
end
|
24
|
-
|
25
|
-
def read(str)
|
26
|
-
io = StringIO.new(str)
|
27
|
-
subject.read(io)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe XDR::VarOpaque, "#write" do
|
32
|
-
subject{ XDR::VarOpaque[2] }
|
33
|
-
|
34
|
-
it "encodes values correctly" do
|
35
|
-
expect(write("")).to eq("\x00\x00\x00\x00")
|
36
|
-
expect(write("\x00")).to eq("\x00\x00\x00\x01\x00\x00\x00\x00")
|
37
|
-
expect(write("\x01")).to eq("\x00\x00\x00\x01\x01\x00\x00\x00")
|
38
|
-
expect(write("\x00\x01")).to eq("\x00\x00\x00\x02\x00\x01\x00\x00")
|
39
|
-
end
|
40
|
-
|
41
|
-
it "raises a WriteError when the provided string is too long" do
|
42
|
-
expect{ write "123" }.to raise_error(XDR::WriteError)
|
43
|
-
end
|
44
|
-
|
45
|
-
def write(val)
|
46
|
-
io = StringIO.new()
|
47
|
-
subject.write(val, io)
|
48
|
-
io.string
|
49
|
-
end
|
50
|
-
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
|
data/spec/spec_helper.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
Bundler.setup
|
3
|
-
require 'simplecov'
|
4
|
-
SimpleCov.start
|
5
|
-
|
6
|
-
require 'pry'
|
7
|
-
require 'xdr'
|
8
|
-
|
9
|
-
__dir__ = File.dirname(__FILE__)
|
10
|
-
|
11
|
-
Dir["#{__dir__}/support/**/*.rb"].each { |f| require f }
|
12
|
-
|
13
|
-
RSpec.configure do |config|
|
14
|
-
|
15
|
-
end
|
data/xdr.gemspec
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'xdr/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "xdr"
|
8
|
-
spec.version = XDR::VERSION
|
9
|
-
spec.authors = ["Scott Fleckenstein"]
|
10
|
-
spec.email = ["scott@stellar.org"]
|
11
|
-
spec.summary = %q{XDR Helper Library}
|
12
|
-
spec.homepage = "https://github.com/stellar/ruby-xdr"
|
13
|
-
spec.license = "Apache 2.0"
|
14
|
-
spec.required_ruby_version = '>= 2.2.0'
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
spec.add_dependency "activesupport", ">= 5.2.0"
|
21
|
-
spec.add_dependency "activemodel", ">= 5.2.0"
|
22
|
-
|
23
|
-
spec.add_development_dependency "bundler", "~> 2.1.4"
|
24
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
-
spec.add_development_dependency "rspec", "~> 3.1"
|
26
|
-
spec.add_development_dependency "guard-rspec"
|
27
|
-
spec.add_development_dependency "simplecov"
|
28
|
-
end
|