erlang-etf 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +6 -0
- data/erlang-etf.gemspec +30 -0
- data/lib/erlang/etf.rb +40 -0
- data/lib/erlang/etf/atom.rb +46 -0
- data/lib/erlang/etf/atom_utf8.rb +44 -0
- data/lib/erlang/etf/bert.rb +74 -0
- data/lib/erlang/etf/binary.rb +44 -0
- data/lib/erlang/etf/bit_binary.rb +47 -0
- data/lib/erlang/etf/export.rb +44 -0
- data/lib/erlang/etf/extensions.rb +157 -0
- data/lib/erlang/etf/extensions/array.rb +29 -0
- data/lib/erlang/etf/extensions/big_decimal.rb +22 -0
- data/lib/erlang/etf/extensions/erlang-export.rb +26 -0
- data/lib/erlang/etf/extensions/erlang-list.rb +31 -0
- data/lib/erlang/etf/extensions/erlang-nil.rb +22 -0
- data/lib/erlang/etf/extensions/erlang-pid.rb +22 -0
- data/lib/erlang/etf/extensions/erlang-string.rb +22 -0
- data/lib/erlang/etf/extensions/erlang-tuple.rb +31 -0
- data/lib/erlang/etf/extensions/false_class.rb +28 -0
- data/lib/erlang/etf/extensions/float.rb +20 -0
- data/lib/erlang/etf/extensions/hash.rb +32 -0
- data/lib/erlang/etf/extensions/integer.rb +48 -0
- data/lib/erlang/etf/extensions/nil_class.rb +29 -0
- data/lib/erlang/etf/extensions/object.rb +24 -0
- data/lib/erlang/etf/extensions/regexp.rb +34 -0
- data/lib/erlang/etf/extensions/string.rb +35 -0
- data/lib/erlang/etf/extensions/symbol.rb +45 -0
- data/lib/erlang/etf/extensions/time.rb +29 -0
- data/lib/erlang/etf/extensions/true_class.rb +28 -0
- data/lib/erlang/etf/float.rb +57 -0
- data/lib/erlang/etf/fun.rb +67 -0
- data/lib/erlang/etf/integer.rb +29 -0
- data/lib/erlang/etf/large_big.rb +53 -0
- data/lib/erlang/etf/large_tuple.rb +55 -0
- data/lib/erlang/etf/list.rb +50 -0
- data/lib/erlang/etf/new_float.rb +33 -0
- data/lib/erlang/etf/new_fun.rb +98 -0
- data/lib/erlang/etf/new_reference.rb +59 -0
- data/lib/erlang/etf/nil.rb +23 -0
- data/lib/erlang/etf/pid.rb +45 -0
- data/lib/erlang/etf/port.rb +34 -0
- data/lib/erlang/etf/reference.rb +41 -0
- data/lib/erlang/etf/small_atom.rb +48 -0
- data/lib/erlang/etf/small_atom_utf8.rb +44 -0
- data/lib/erlang/etf/small_big.rb +59 -0
- data/lib/erlang/etf/small_integer.rb +29 -0
- data/lib/erlang/etf/small_tuple.rb +56 -0
- data/lib/erlang/etf/string.rb +46 -0
- data/lib/erlang/etf/term.rb +101 -0
- data/lib/erlang/etf/terms.rb +105 -0
- data/lib/erlang/etf/version.rb +5 -0
- data/spec/erlang/etf/atom_spec.rb +90 -0
- data/spec/erlang/etf/atom_utf8_spec.rb +90 -0
- data/spec/erlang/etf/binary_spec.rb +90 -0
- data/spec/erlang/etf/bit_binary_spec.rb +99 -0
- data/spec/erlang/etf/export_spec.rb +58 -0
- data/spec/erlang/etf/extensions/array_spec.rb +40 -0
- data/spec/erlang/etf/extensions/big_decimal_spec.rb +26 -0
- data/spec/erlang/etf/extensions/erlang-export_spec.rb +32 -0
- data/spec/erlang/etf/extensions/erlang-list_spec.rb +76 -0
- data/spec/erlang/etf/extensions/erlang-nil_spec.rb +24 -0
- data/spec/erlang/etf/extensions/erlang-pid_spec.rb +33 -0
- data/spec/erlang/etf/extensions/erlang-string_spec.rb +26 -0
- data/spec/erlang/etf/extensions/erlang-tuple_spec.rb +56 -0
- data/spec/erlang/etf/extensions/false_class_spec.rb +29 -0
- data/spec/erlang/etf/extensions/float_spec.rb +24 -0
- data/spec/erlang/etf/extensions/hash_spec.rb +90 -0
- data/spec/erlang/etf/extensions/integer_spec.rb +259 -0
- data/spec/erlang/etf/extensions/nil_class_spec.rb +29 -0
- data/spec/erlang/etf/extensions/object_spec.rb +30 -0
- data/spec/erlang/etf/extensions/regexp_spec.rb +35 -0
- data/spec/erlang/etf/extensions/string_spec.rb +43 -0
- data/spec/erlang/etf/extensions/symbol_spec.rb +64 -0
- data/spec/erlang/etf/extensions/time_spec.rb +32 -0
- data/spec/erlang/etf/extensions/true_class_spec.rb +29 -0
- data/spec/erlang/etf/float_spec.rb +92 -0
- data/spec/erlang/etf/fun_spec.rb +132 -0
- data/spec/erlang/etf/integer_spec.rb +57 -0
- data/spec/erlang/etf/large_big_spec.rb +67 -0
- data/spec/erlang/etf/large_tuple_spec.rb +119 -0
- data/spec/erlang/etf/list_spec.rb +159 -0
- data/spec/erlang/etf/new_float_spec.rb +92 -0
- data/spec/erlang/etf/new_fun_spec.rb +146 -0
- data/spec/erlang/etf/new_reference_spec.rb +60 -0
- data/spec/erlang/etf/nil_spec.rb +50 -0
- data/spec/erlang/etf/pid_spec.rb +61 -0
- data/spec/erlang/etf/port_spec.rb +58 -0
- data/spec/erlang/etf/reference_spec.rb +58 -0
- data/spec/erlang/etf/small_atom_spec.rb +90 -0
- data/spec/erlang/etf/small_atom_utf8_spec.rb +90 -0
- data/spec/erlang/etf/small_big_spec.rb +67 -0
- data/spec/erlang/etf/small_integer_spec.rb +57 -0
- data/spec/erlang/etf/small_tuple_spec.rb +112 -0
- data/spec/erlang/etf/string_spec.rb +92 -0
- data/spec/erlang/etf/term_spec.rb +27 -0
- data/spec/erlang/etf/terms_spec.rb +23 -0
- data/spec/erlang/etf_spec.rb +23 -0
- data/spec/erlang_spec.rb +77 -0
- data/spec/spec_helper.rb +7 -0
- metadata +310 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Erlang::ETF::Nil do
|
6
|
+
let(:term_class) { Erlang::ETF::Nil }
|
7
|
+
|
8
|
+
describe '[class]' do
|
9
|
+
describe 'deserialize' do
|
10
|
+
let(:buffer) { StringIO.new(bytes.pack('C*')) }
|
11
|
+
subject { term_class.deserialize(buffer) }
|
12
|
+
|
13
|
+
let(:bytes) { [] }
|
14
|
+
|
15
|
+
it { should eq(term_class.new) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'new' do
|
19
|
+
subject { term_class.new }
|
20
|
+
|
21
|
+
it { should eq(term_class.new) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '[instance]' do
|
26
|
+
let(:term) { term_class.new }
|
27
|
+
|
28
|
+
describe 'serialize' do
|
29
|
+
subject { term.serialize }
|
30
|
+
|
31
|
+
let(:bytes) { [106].pack('C*') }
|
32
|
+
|
33
|
+
it { should eq(bytes) }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '__erlang_type__' do
|
37
|
+
subject { term.__erlang_type__ }
|
38
|
+
|
39
|
+
it { should eq(:nil) }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '__ruby_evolve__' do
|
43
|
+
let(:ruby_obj) { [] }
|
44
|
+
subject { term.__ruby_evolve__ }
|
45
|
+
|
46
|
+
it { should eq(ruby_obj) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Erlang::ETF::Pid do
|
6
|
+
let(:term_class) { Erlang::ETF::Pid }
|
7
|
+
|
8
|
+
let(:node) { Erlang::ETF::Atom.new("node@host").tap(&:serialize) }
|
9
|
+
let(:id) { 1234 }
|
10
|
+
let(:serial) { 13 }
|
11
|
+
let(:creation) { 1 }
|
12
|
+
|
13
|
+
describe '[class]' do
|
14
|
+
describe 'deserialize' do
|
15
|
+
let(:buffer) { StringIO.new(bytes.pack('C*')) }
|
16
|
+
subject { term_class.deserialize(buffer) }
|
17
|
+
|
18
|
+
let(:bytes) { [100, 0, 9, 110, 111, 100, 101, 64, 104, 111, 115, 116, 0, 0, 4, 210, 0, 0, 0, 13, 1] }
|
19
|
+
|
20
|
+
its(:node) { should eq(node) }
|
21
|
+
its(:id) { should eq(id) }
|
22
|
+
its(:serial) { should eq(serial) }
|
23
|
+
its(:creation) { should eq(creation) }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'new' do
|
27
|
+
subject { term_class.new(node, id, serial, creation) }
|
28
|
+
|
29
|
+
its(:node) { should eq(node) }
|
30
|
+
its(:id) { should eq(id) }
|
31
|
+
its(:serial) { should eq(serial) }
|
32
|
+
its(:creation) { should eq(creation) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '[instance]' do
|
37
|
+
let(:term) { term_class.new(node, id, serial, creation) }
|
38
|
+
|
39
|
+
describe 'serialize' do
|
40
|
+
subject { term.serialize }
|
41
|
+
|
42
|
+
let(:bytes) { [103, 100, 0, 9, 110, 111, 100, 101, 64, 104, 111, 115, 116, 0, 0, 4, 210, 0, 0, 0, 13, 1].pack('C*') }
|
43
|
+
|
44
|
+
it { should eq(bytes) }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '__erlang_type__' do
|
48
|
+
subject { term.__erlang_type__ }
|
49
|
+
|
50
|
+
it { should eq(:pid) }
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '__ruby_evolve__' do
|
54
|
+
let(:ruby_obj) { ::Erlang::Pid.new(:'node@host', 1234, 13, 1) }
|
55
|
+
subject { term.__ruby_evolve__ }
|
56
|
+
|
57
|
+
it { should eq(ruby_obj) }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Erlang::ETF::Port do
|
6
|
+
let(:term_class) { Erlang::ETF::Port }
|
7
|
+
|
8
|
+
let(:node) { Erlang::ETF::Atom.new("node@host").tap(&:serialize) }
|
9
|
+
let(:id) { 1234 }
|
10
|
+
let(:creation) { 1 }
|
11
|
+
|
12
|
+
describe '[class]' do
|
13
|
+
describe 'deserialize' do
|
14
|
+
let(:buffer) { StringIO.new(bytes.pack('C*')) }
|
15
|
+
subject { term_class.deserialize(buffer) }
|
16
|
+
|
17
|
+
let(:bytes) { [100, 0, 9, 110, 111, 100, 101, 64, 104, 111, 115, 116, 0, 0, 4, 210, 1] }
|
18
|
+
|
19
|
+
its(:node) { should eq(node) }
|
20
|
+
its(:id) { should eq(id) }
|
21
|
+
its(:creation) { should eq(creation) }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'new' do
|
25
|
+
subject { term_class.new(node, id, creation) }
|
26
|
+
|
27
|
+
its(:node) { should eq(node) }
|
28
|
+
its(:id) { should eq(id) }
|
29
|
+
its(:creation) { should eq(creation) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '[instance]' do
|
34
|
+
let(:term) { term_class.new(node, id, creation) }
|
35
|
+
|
36
|
+
describe 'serialize' do
|
37
|
+
subject { term.serialize }
|
38
|
+
|
39
|
+
let(:bytes) { [102, 100, 0, 9, 110, 111, 100, 101, 64, 104, 111, 115, 116, 0, 0, 4, 210, 1].pack('C*') }
|
40
|
+
|
41
|
+
it { should eq(bytes) }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '__erlang_type__' do
|
45
|
+
subject { term.__erlang_type__ }
|
46
|
+
|
47
|
+
it { should eq(:port) }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '__ruby_evolve__' do
|
51
|
+
let(:ruby_obj) { term }
|
52
|
+
subject { term.__ruby_evolve__ }
|
53
|
+
|
54
|
+
it { should eq(ruby_obj) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Erlang::ETF::Reference do
|
6
|
+
let(:term_class) { Erlang::ETF::Reference }
|
7
|
+
|
8
|
+
let(:node) { Erlang::ETF::Atom.new("node@host").tap(&:serialize) }
|
9
|
+
let(:id) { 1234 }
|
10
|
+
let(:creation) { 1 }
|
11
|
+
|
12
|
+
describe '[class]' do
|
13
|
+
describe 'deserialize' do
|
14
|
+
let(:buffer) { StringIO.new(bytes.pack('C*')) }
|
15
|
+
subject { term_class.deserialize(buffer) }
|
16
|
+
|
17
|
+
let(:bytes) { [100, 0, 9, 110, 111, 100, 101, 64, 104, 111, 115, 116, 0, 0, 4, 210, 1] }
|
18
|
+
|
19
|
+
its(:node) { should eq(node) }
|
20
|
+
its(:id) { should eq(id) }
|
21
|
+
its(:creation) { should eq(creation) }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'new' do
|
25
|
+
subject { term_class.new(node, id, creation) }
|
26
|
+
|
27
|
+
its(:node) { should eq(node) }
|
28
|
+
its(:id) { should eq(id) }
|
29
|
+
its(:creation) { should eq(creation) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '[instance]' do
|
34
|
+
let(:term) { term_class.new(node, id, creation) }
|
35
|
+
|
36
|
+
describe 'serialize' do
|
37
|
+
subject { term.serialize }
|
38
|
+
|
39
|
+
let(:bytes) { [101, 100, 0, 9, 110, 111, 100, 101, 64, 104, 111, 115, 116, 0, 0, 4, 210, 1].pack('C*') }
|
40
|
+
|
41
|
+
it { should eq(bytes) }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '__erlang_type__' do
|
45
|
+
subject { term.__erlang_type__ }
|
46
|
+
|
47
|
+
it { should eq(:reference) }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '__ruby_evolve__' do
|
51
|
+
let(:ruby_obj) { term }
|
52
|
+
subject { term.__ruby_evolve__ }
|
53
|
+
|
54
|
+
it { should eq(ruby_obj) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Erlang::ETF::SmallAtom do
|
6
|
+
let(:term_class) { Erlang::ETF::SmallAtom }
|
7
|
+
|
8
|
+
describe '[class]' do
|
9
|
+
describe 'deserialize' do
|
10
|
+
let(:buffer) { StringIO.new(bytes.pack('C*')) }
|
11
|
+
subject { term_class.deserialize(buffer) }
|
12
|
+
|
13
|
+
context "ASCII bytes" do
|
14
|
+
let(:bytes) { [4, 116, 101, 115, 116] }
|
15
|
+
|
16
|
+
its(:len) { should eq(4) }
|
17
|
+
its(:atom_name) { should eq("test") }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "UTF-8 bytes" do
|
21
|
+
let(:bytes) { [2, 206, 169] }
|
22
|
+
|
23
|
+
its(:len) { should eq(2) }
|
24
|
+
its(:atom_name) { should eq("Ω") }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'new' do
|
29
|
+
subject { term_class.new(atom_name) }
|
30
|
+
|
31
|
+
context "ASCII" do
|
32
|
+
let(:atom_name) { "test" }
|
33
|
+
|
34
|
+
its(:atom_name) { should eq(atom_name) }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "UTF-8" do
|
38
|
+
let(:atom_name) { "Ω" }
|
39
|
+
|
40
|
+
its(:atom_name) { should eq(atom_name) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '[instance]' do
|
46
|
+
let(:term) { term_class.new(atom_name) }
|
47
|
+
|
48
|
+
describe 'serialize' do
|
49
|
+
subject { term.serialize }
|
50
|
+
|
51
|
+
context "ASCII" do
|
52
|
+
let(:atom_name) { "test" }
|
53
|
+
let(:bytes) { [115, 4, 116, 101, 115, 116].pack('C*') }
|
54
|
+
|
55
|
+
it { should eq(bytes) }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "UTF-8" do
|
59
|
+
let(:atom_name) { "Ω" }
|
60
|
+
let(:bytes) { [115, 2, 206, 169].pack('C*') }
|
61
|
+
|
62
|
+
it { should eq(bytes) }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '__erlang_type__' do
|
67
|
+
subject { term.__erlang_type__ }
|
68
|
+
|
69
|
+
let(:atom_name) { "test" }
|
70
|
+
it { should eq(:small_atom) }
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '__ruby_evolve__' do
|
74
|
+
subject { term.__ruby_evolve__ }
|
75
|
+
|
76
|
+
context "ASCII" do
|
77
|
+
let(:atom_name) { "test" }
|
78
|
+
|
79
|
+
it { should eq(:test) }
|
80
|
+
end
|
81
|
+
|
82
|
+
context "UTF-8" do
|
83
|
+
let(:atom_name) { "Ω" }
|
84
|
+
|
85
|
+
it { should eq(:'Ω') }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Erlang::ETF::SmallAtomUTF8 do
|
6
|
+
let(:term_class) { Erlang::ETF::SmallAtomUTF8 }
|
7
|
+
|
8
|
+
describe '[class]' do
|
9
|
+
describe 'deserialize' do
|
10
|
+
let(:buffer) { StringIO.new(bytes.pack('C*')) }
|
11
|
+
subject { term_class.deserialize(buffer) }
|
12
|
+
|
13
|
+
context "ASCII bytes" do
|
14
|
+
let(:bytes) { [4, 116, 101, 115, 116] }
|
15
|
+
|
16
|
+
its(:len) { should eq(4) }
|
17
|
+
its(:atom_name) { should eq("test") }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "UTF-8 bytes" do
|
21
|
+
let(:bytes) { [2, 206, 169] }
|
22
|
+
|
23
|
+
its(:len) { should eq(2) }
|
24
|
+
its(:atom_name) { should eq("Ω") }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'new' do
|
29
|
+
subject { term_class.new(atom_name) }
|
30
|
+
|
31
|
+
context "ASCII" do
|
32
|
+
let(:atom_name) { "test" }
|
33
|
+
|
34
|
+
its(:atom_name) { should eq(atom_name) }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "UTF-8" do
|
38
|
+
let(:atom_name) { "Ω" }
|
39
|
+
|
40
|
+
its(:atom_name) { should eq(atom_name) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '[instance]' do
|
46
|
+
let(:term) { term_class.new(atom_name) }
|
47
|
+
|
48
|
+
describe 'serialize' do
|
49
|
+
subject { term.serialize }
|
50
|
+
|
51
|
+
context "ASCII" do
|
52
|
+
let(:atom_name) { "test" }
|
53
|
+
let(:bytes) { [119, 4, 116, 101, 115, 116].pack('C*') }
|
54
|
+
|
55
|
+
it { should eq(bytes) }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "UTF-8" do
|
59
|
+
let(:atom_name) { "Ω" }
|
60
|
+
let(:bytes) { [119, 2, 206, 169].pack('C*') }
|
61
|
+
|
62
|
+
it { should eq(bytes) }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '__erlang_type__' do
|
67
|
+
subject { term.__erlang_type__ }
|
68
|
+
|
69
|
+
let(:atom_name) { "Ω" }
|
70
|
+
it { should eq(:small_atom_utf8) }
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '__ruby_evolve__' do
|
74
|
+
subject { term.__ruby_evolve__ }
|
75
|
+
|
76
|
+
context "ASCII" do
|
77
|
+
let(:atom_name) { "test" }
|
78
|
+
|
79
|
+
it { should eq(:test) }
|
80
|
+
end
|
81
|
+
|
82
|
+
context "UTF-8" do
|
83
|
+
let(:atom_name) { "Ω" }
|
84
|
+
|
85
|
+
it { should eq(:'Ω') }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Erlang::ETF::SmallBig do
|
6
|
+
let(:term_class) { Erlang::ETF::SmallBig }
|
7
|
+
|
8
|
+
describe '[class]' do
|
9
|
+
describe 'deserialize' do
|
10
|
+
let(:buffer) { StringIO.new(bytes.pack('C*')) }
|
11
|
+
subject { term_class.deserialize(buffer) }
|
12
|
+
|
13
|
+
let(:n) { 128 }
|
14
|
+
let(:sign) { 0 }
|
15
|
+
let(:integer) { (+1 << (128 * 8)) - 1 }
|
16
|
+
let(:bytes) { [128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] }
|
17
|
+
|
18
|
+
its(:n) { should eq(n) }
|
19
|
+
its(:sign) { should eq(sign) }
|
20
|
+
its(:integer) { should eq(integer) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'new' do
|
24
|
+
subject { term_class.new(integer).tap(&:serialize) }
|
25
|
+
|
26
|
+
let(:n) { 128 }
|
27
|
+
let(:sign) { 1 }
|
28
|
+
let(:integer) { (-1 << (128 * 8)) + 1 }
|
29
|
+
|
30
|
+
its(:n) { should eq(n) }
|
31
|
+
its(:sign) { should eq(sign) }
|
32
|
+
its(:integer) { should eq(integer) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '[instance]' do
|
37
|
+
let(:term) { term_class.new(integer) }
|
38
|
+
|
39
|
+
describe 'serialize' do
|
40
|
+
subject { term.serialize }
|
41
|
+
|
42
|
+
let(:n) { 128 }
|
43
|
+
let(:sign) { 1 }
|
44
|
+
let(:integer) { (-1 << (128 * 8)) + 1 }
|
45
|
+
let(:bytes) { [110, 128, 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255].pack('C*') }
|
46
|
+
|
47
|
+
it { should eq(bytes) }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '__erlang_type__' do
|
51
|
+
subject { term.__erlang_type__ }
|
52
|
+
|
53
|
+
let(:integer) { (+1 << (128 * 8)) - 1 }
|
54
|
+
it { should eq(:small_big) }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '__ruby_evolve__' do
|
58
|
+
subject { term.__ruby_evolve__ }
|
59
|
+
|
60
|
+
let(:ruby_obj) { (+1 << (128 * 8)) - 1 }
|
61
|
+
let(:integer) { (+1 << (128 * 8)) - 1 }
|
62
|
+
|
63
|
+
it { should eq(ruby_obj) }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|