erlang-etf 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +49 -0
  8. data/Rakefile +6 -0
  9. data/erlang-etf.gemspec +30 -0
  10. data/lib/erlang/etf.rb +40 -0
  11. data/lib/erlang/etf/atom.rb +46 -0
  12. data/lib/erlang/etf/atom_utf8.rb +44 -0
  13. data/lib/erlang/etf/bert.rb +74 -0
  14. data/lib/erlang/etf/binary.rb +44 -0
  15. data/lib/erlang/etf/bit_binary.rb +47 -0
  16. data/lib/erlang/etf/export.rb +44 -0
  17. data/lib/erlang/etf/extensions.rb +157 -0
  18. data/lib/erlang/etf/extensions/array.rb +29 -0
  19. data/lib/erlang/etf/extensions/big_decimal.rb +22 -0
  20. data/lib/erlang/etf/extensions/erlang-export.rb +26 -0
  21. data/lib/erlang/etf/extensions/erlang-list.rb +31 -0
  22. data/lib/erlang/etf/extensions/erlang-nil.rb +22 -0
  23. data/lib/erlang/etf/extensions/erlang-pid.rb +22 -0
  24. data/lib/erlang/etf/extensions/erlang-string.rb +22 -0
  25. data/lib/erlang/etf/extensions/erlang-tuple.rb +31 -0
  26. data/lib/erlang/etf/extensions/false_class.rb +28 -0
  27. data/lib/erlang/etf/extensions/float.rb +20 -0
  28. data/lib/erlang/etf/extensions/hash.rb +32 -0
  29. data/lib/erlang/etf/extensions/integer.rb +48 -0
  30. data/lib/erlang/etf/extensions/nil_class.rb +29 -0
  31. data/lib/erlang/etf/extensions/object.rb +24 -0
  32. data/lib/erlang/etf/extensions/regexp.rb +34 -0
  33. data/lib/erlang/etf/extensions/string.rb +35 -0
  34. data/lib/erlang/etf/extensions/symbol.rb +45 -0
  35. data/lib/erlang/etf/extensions/time.rb +29 -0
  36. data/lib/erlang/etf/extensions/true_class.rb +28 -0
  37. data/lib/erlang/etf/float.rb +57 -0
  38. data/lib/erlang/etf/fun.rb +67 -0
  39. data/lib/erlang/etf/integer.rb +29 -0
  40. data/lib/erlang/etf/large_big.rb +53 -0
  41. data/lib/erlang/etf/large_tuple.rb +55 -0
  42. data/lib/erlang/etf/list.rb +50 -0
  43. data/lib/erlang/etf/new_float.rb +33 -0
  44. data/lib/erlang/etf/new_fun.rb +98 -0
  45. data/lib/erlang/etf/new_reference.rb +59 -0
  46. data/lib/erlang/etf/nil.rb +23 -0
  47. data/lib/erlang/etf/pid.rb +45 -0
  48. data/lib/erlang/etf/port.rb +34 -0
  49. data/lib/erlang/etf/reference.rb +41 -0
  50. data/lib/erlang/etf/small_atom.rb +48 -0
  51. data/lib/erlang/etf/small_atom_utf8.rb +44 -0
  52. data/lib/erlang/etf/small_big.rb +59 -0
  53. data/lib/erlang/etf/small_integer.rb +29 -0
  54. data/lib/erlang/etf/small_tuple.rb +56 -0
  55. data/lib/erlang/etf/string.rb +46 -0
  56. data/lib/erlang/etf/term.rb +101 -0
  57. data/lib/erlang/etf/terms.rb +105 -0
  58. data/lib/erlang/etf/version.rb +5 -0
  59. data/spec/erlang/etf/atom_spec.rb +90 -0
  60. data/spec/erlang/etf/atom_utf8_spec.rb +90 -0
  61. data/spec/erlang/etf/binary_spec.rb +90 -0
  62. data/spec/erlang/etf/bit_binary_spec.rb +99 -0
  63. data/spec/erlang/etf/export_spec.rb +58 -0
  64. data/spec/erlang/etf/extensions/array_spec.rb +40 -0
  65. data/spec/erlang/etf/extensions/big_decimal_spec.rb +26 -0
  66. data/spec/erlang/etf/extensions/erlang-export_spec.rb +32 -0
  67. data/spec/erlang/etf/extensions/erlang-list_spec.rb +76 -0
  68. data/spec/erlang/etf/extensions/erlang-nil_spec.rb +24 -0
  69. data/spec/erlang/etf/extensions/erlang-pid_spec.rb +33 -0
  70. data/spec/erlang/etf/extensions/erlang-string_spec.rb +26 -0
  71. data/spec/erlang/etf/extensions/erlang-tuple_spec.rb +56 -0
  72. data/spec/erlang/etf/extensions/false_class_spec.rb +29 -0
  73. data/spec/erlang/etf/extensions/float_spec.rb +24 -0
  74. data/spec/erlang/etf/extensions/hash_spec.rb +90 -0
  75. data/spec/erlang/etf/extensions/integer_spec.rb +259 -0
  76. data/spec/erlang/etf/extensions/nil_class_spec.rb +29 -0
  77. data/spec/erlang/etf/extensions/object_spec.rb +30 -0
  78. data/spec/erlang/etf/extensions/regexp_spec.rb +35 -0
  79. data/spec/erlang/etf/extensions/string_spec.rb +43 -0
  80. data/spec/erlang/etf/extensions/symbol_spec.rb +64 -0
  81. data/spec/erlang/etf/extensions/time_spec.rb +32 -0
  82. data/spec/erlang/etf/extensions/true_class_spec.rb +29 -0
  83. data/spec/erlang/etf/float_spec.rb +92 -0
  84. data/spec/erlang/etf/fun_spec.rb +132 -0
  85. data/spec/erlang/etf/integer_spec.rb +57 -0
  86. data/spec/erlang/etf/large_big_spec.rb +67 -0
  87. data/spec/erlang/etf/large_tuple_spec.rb +119 -0
  88. data/spec/erlang/etf/list_spec.rb +159 -0
  89. data/spec/erlang/etf/new_float_spec.rb +92 -0
  90. data/spec/erlang/etf/new_fun_spec.rb +146 -0
  91. data/spec/erlang/etf/new_reference_spec.rb +60 -0
  92. data/spec/erlang/etf/nil_spec.rb +50 -0
  93. data/spec/erlang/etf/pid_spec.rb +61 -0
  94. data/spec/erlang/etf/port_spec.rb +58 -0
  95. data/spec/erlang/etf/reference_spec.rb +58 -0
  96. data/spec/erlang/etf/small_atom_spec.rb +90 -0
  97. data/spec/erlang/etf/small_atom_utf8_spec.rb +90 -0
  98. data/spec/erlang/etf/small_big_spec.rb +67 -0
  99. data/spec/erlang/etf/small_integer_spec.rb +57 -0
  100. data/spec/erlang/etf/small_tuple_spec.rb +112 -0
  101. data/spec/erlang/etf/string_spec.rb +92 -0
  102. data/spec/erlang/etf/term_spec.rb +27 -0
  103. data/spec/erlang/etf/terms_spec.rb +23 -0
  104. data/spec/erlang/etf_spec.rb +23 -0
  105. data/spec/erlang_spec.rb +77 -0
  106. data/spec/spec_helper.rb +7 -0
  107. metadata +310 -0
@@ -0,0 +1,159 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Erlang::ETF::List do
6
+ let(:term_class) { Erlang::ETF::List }
7
+
8
+ let(:atom) { Erlang::ETF::SmallAtom.new("test").tap(&:serialize) }
9
+ let(:binary) { Erlang::ETF::Binary.new("test").tap(&:serialize) }
10
+ let(:new_float) { Erlang::ETF::NewFloat.new(1.1) }
11
+ let(:small_integer) { Erlang::ETF::SmallInteger.new(13) }
12
+ let(:small_list) { Erlang::ETF::List.new([atom, binary, new_float, small_integer]) }
13
+ let(:small_tuple) { Erlang::ETF::SmallTuple.new([atom, binary, new_float, small_integer, small_list]) }
14
+
15
+ let(:erlang_nil) { Erlang::ETF::Nil.new }
16
+
17
+ describe '[class]' do
18
+ describe 'deserialize' do
19
+ let(:buffer) { StringIO.new(bytes.pack('C*')) }
20
+ subject { term_class.deserialize(buffer) }
21
+
22
+ context 'single improper list' do
23
+ let(:bytes) { [0, 0, 0, 1, 100, 0, 1, 97, 100, 0, 1, 98] }
24
+ let(:atom_a) { Erlang::ETF::Atom.new("a").tap(&:serialize) }
25
+ let(:atom_b) { Erlang::ETF::Atom.new("b").tap(&:serialize) }
26
+
27
+ it { should be_improper }
28
+ its(:len) { should eq(1) }
29
+ its(:elements) { should eq([atom_a]) }
30
+ its(:tail) { should eq(atom_b) }
31
+ end
32
+
33
+ context 'single proper list' do
34
+ let(:bytes) { [0, 0, 0, 1, 97, 13, 106] }
35
+
36
+ it { should_not be_improper }
37
+ its(:len) { should eq(1) }
38
+ its(:elements) { should eq([small_integer]) }
39
+ its(:tail) { should eq(erlang_nil) }
40
+ end
41
+
42
+ context 'complex improper list' do
43
+ let(:bytes) { [0, 0, 0, 6, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 104, 5, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106] }
44
+
45
+ it { should be_improper }
46
+ its(:len) { should eq(6) }
47
+ its(:elements) { should eq([atom, binary, new_float, small_integer, small_tuple, small_list]) }
48
+ its(:tail) { should eq(small_list) }
49
+ end
50
+
51
+ context 'complex proper list' do
52
+ let(:bytes) { [0, 0, 0, 6, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 104, 5, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106, 106] }
53
+
54
+ it { should_not be_improper }
55
+ its(:len) { should eq(6) }
56
+ its(:elements) { should eq([atom, binary, new_float, small_integer, small_tuple, small_list]) }
57
+ its(:tail) { should eq(erlang_nil) }
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '[instance]' do
63
+ let(:term) { term_class.new(elements, tail) }
64
+
65
+ let(:atom_a) { Erlang::ETF::Atom.new("a").tap(&:serialize) }
66
+ let(:atom_b) { Erlang::ETF::Atom.new("b").tap(&:serialize) }
67
+
68
+ describe 'serialize' do
69
+ subject { term.serialize }
70
+
71
+ context 'single improper list' do
72
+ let(:bytes) { [108, 0, 0, 0, 1, 100, 0, 1, 97, 100, 0, 1, 98].pack('C*') }
73
+
74
+ let(:elements) { [atom_a] }
75
+ let(:tail) { atom_b }
76
+
77
+ it { should eq(bytes) }
78
+ end
79
+
80
+ context 'single proper list' do
81
+ let(:bytes) { [108, 0, 0, 0, 1, 100, 0, 1, 97, 106].pack('C*') }
82
+
83
+ let(:elements) { [atom_a] }
84
+ let(:tail) { erlang_nil }
85
+
86
+ it { should eq(bytes) }
87
+ end
88
+
89
+ context 'complex improper list' do
90
+ let(:bytes) { [108, 0, 0, 0, 6, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 104, 5, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106].pack('C*') }
91
+
92
+ let(:elements) { [atom, binary, new_float, small_integer, small_tuple, small_list] }
93
+ let(:tail) { small_list }
94
+
95
+ it { should eq(bytes) }
96
+ end
97
+
98
+ context 'complex proper list' do
99
+ let(:bytes) { [108, 0, 0, 0, 6, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 104, 5, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106, 106].pack('C*') }
100
+
101
+ let(:elements) { [atom, binary, new_float, small_integer, small_tuple, small_list] }
102
+ let(:tail) { erlang_nil }
103
+
104
+ it { should eq(bytes) }
105
+ end
106
+ end
107
+
108
+ describe '__erlang_type__' do
109
+ subject { term.__erlang_type__ }
110
+
111
+ let(:elements) { [atom_a] }
112
+ let(:tail) { erlang_nil }
113
+ it { should eq(:list) }
114
+ end
115
+
116
+ describe '__ruby_evolve__' do
117
+ context 'single improper list' do
118
+ let(:ruby_obj) { ::Erlang::List[:a].tail(:b) }
119
+ subject { term.__ruby_evolve__ }
120
+
121
+ let(:elements) { [atom_a] }
122
+ let(:tail) { atom_b }
123
+
124
+ it { should eq(ruby_obj) }
125
+ end
126
+
127
+ context 'single proper list' do
128
+ let(:ruby_obj) { [:a] }
129
+ subject { term.__ruby_evolve__ }
130
+
131
+ let(:elements) { [atom_a] }
132
+ let(:tail) { erlang_nil }
133
+
134
+ it { should eq(ruby_obj) }
135
+ end
136
+
137
+ context 'complex improper list' do
138
+ let(:ruby_obj) { ::Erlang::List[:test, "test", 1.1, 13, ::Erlang::Tuple[:test, "test", 1.1, 13, ::Erlang::List[:test, "test", 1.1, 13]], ::Erlang::List[:test, "test", 1.1, 13]].tail(::Erlang::List[:test, "test", 1.1, 13]) }
139
+ subject { term.__ruby_evolve__ }
140
+
141
+ let(:elements) { [atom, binary, new_float, small_integer, small_tuple, small_list] }
142
+ let(:tail) { small_list }
143
+
144
+ it { should eq(ruby_obj) }
145
+ end
146
+
147
+ context 'complex proper list' do
148
+ let(:ruby_obj) { ::Erlang::List[:test, "test", 1.1, 13, ::Erlang::Tuple[:test, "test", 1.1, 13, ::Erlang::List[:test, "test", 1.1, 13]], ::Erlang::List[:test, "test", 1.1, 13]] }
149
+ subject { term.__ruby_evolve__ }
150
+
151
+ let(:elements) { [atom, binary, new_float, small_integer, small_tuple, small_list] }
152
+ let(:tail) { erlang_nil }
153
+
154
+ it { should eq(ruby_obj) }
155
+ end
156
+ end
157
+ end
158
+
159
+ end
@@ -0,0 +1,92 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Erlang::ETF::NewFloat do
6
+ let(:term_class) { Erlang::ETF::NewFloat }
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 'with 2 significant digits' do
14
+ let(:float) { 1.1 }
15
+ let(:bytes) { [63, 241, 153, 153, 153, 153, 153, 154] }
16
+
17
+ its(:float) { should eq(float) }
18
+ end
19
+
20
+ context 'with 16 significant digits' do
21
+ let(:float) { 0.001122334455667789 }
22
+ let(:bytes) { [63, 82, 99, 105, 114, 16, 170, 24] }
23
+
24
+ its(:float) { should eq(float) }
25
+ end
26
+ end
27
+
28
+ describe 'new' do
29
+ subject { term_class.new(float) }
30
+
31
+ context 'with 2 significant digits' do
32
+ let(:float) { -1.1 }
33
+
34
+ its(:float) { should eq(float) }
35
+ end
36
+
37
+ context 'with 16 significant digits' do
38
+ let(:float) { 0.001122334455667789 }
39
+
40
+ its(:float) { should eq(float) }
41
+ end
42
+ end
43
+ end
44
+
45
+ describe '[instance]' do
46
+ let(:term) { term_class.new(float) }
47
+
48
+ describe 'serialize' do
49
+ subject { term.serialize }
50
+
51
+ context 'with 2 significant digits' do
52
+ let(:float) { -1.1 }
53
+ let(:bytes) { [70, 191, 241, 153, 153, 153, 153, 153, 154].pack('C*') }
54
+
55
+ it { should eq(bytes) }
56
+ end
57
+
58
+ context 'with 16 significant digits' do
59
+ let(:float) { 0.001122334455667789 }
60
+ let(:bytes) { [70, 63, 82, 99, 105, 114, 16, 170, 24].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(:float) { 1.1 }
70
+ it { should eq(:new_float) }
71
+ end
72
+
73
+ describe '__ruby_evolve__' do
74
+ subject { term.__ruby_evolve__ }
75
+
76
+ context 'with 2 significant digits' do
77
+ let(:ruby_obj) { -1.1 }
78
+ let(:float) { -1.1 }
79
+
80
+ it { should eq(ruby_obj) }
81
+ end
82
+
83
+ context 'with 16 significant digits' do
84
+ let(:ruby_obj) { 0.001122334455667789 }
85
+ let(:float) { 0.001122334455667789 }
86
+
87
+ it { should eq(ruby_obj) }
88
+ end
89
+ end
90
+ end
91
+
92
+ end
@@ -0,0 +1,146 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Erlang::ETF::NewFun do
6
+ let(:term_class) { Erlang::ETF::NewFun }
7
+
8
+ let(:arity) { 1 }
9
+ let(:uniq) { [32, 134, 155, 11, 165, 194, 128, 94, 159, 150, 25, 37, 107, 162, 125, 47] }
10
+ let(:index) { 6 }
11
+ let(:mod) { Erlang::ETF::Atom.new("erl_eval") }
12
+ let(:old_index) { Erlang::ETF::SmallInteger.new(6) }
13
+ let(:old_uniq) { Erlang::ETF::Integer.new(17052888) }
14
+ let(:pid) { Erlang::ETF::Pid.new(Erlang::ETF::Atom.new("nonode@nohost"), 2, 0, 0) }
15
+ let(:free_vars) {
16
+ [
17
+ Erlang::ETF::Nil.new,
18
+ Erlang::ETF::Atom.new("none"),
19
+ Erlang::ETF::Atom.new("none"),
20
+ Erlang::ETF::List.new([
21
+ Erlang::ETF::SmallTuple.new([
22
+ Erlang::ETF::Atom.new("clause"),
23
+ Erlang::ETF::SmallInteger.new(1),
24
+ Erlang::ETF::List.new([
25
+ Erlang::ETF::SmallTuple.new([
26
+ Erlang::ETF::Atom.new("atom"),
27
+ Erlang::ETF::SmallInteger.new(1),
28
+ Erlang::ETF::Atom.new("a")
29
+ ])
30
+ ]),
31
+ Erlang::ETF::Nil.new,
32
+ Erlang::ETF::List.new([
33
+ Erlang::ETF::SmallTuple.new([
34
+ Erlang::ETF::Atom.new("atom"),
35
+ Erlang::ETF::SmallInteger.new(1),
36
+ Erlang::ETF::Atom.new("true")
37
+ ])
38
+ ])
39
+ ]),
40
+ Erlang::ETF::SmallTuple.new([
41
+ Erlang::ETF::Atom.new("clause"),
42
+ Erlang::ETF::SmallInteger.new(1),
43
+ Erlang::ETF::List.new([
44
+ Erlang::ETF::SmallTuple.new([
45
+ Erlang::ETF::Atom.new("var"),
46
+ Erlang::ETF::SmallInteger.new(1),
47
+ Erlang::ETF::Atom.new("_")
48
+ ])
49
+ ]),
50
+ Erlang::ETF::Nil.new,
51
+ Erlang::ETF::List.new([
52
+ Erlang::ETF::SmallTuple.new([
53
+ Erlang::ETF::Atom.new("atom"),
54
+ Erlang::ETF::SmallInteger.new(1),
55
+ Erlang::ETF::Atom.new("false")
56
+ ])
57
+ ])
58
+ ])
59
+ ])
60
+ ]
61
+ }
62
+
63
+ describe '[class]' do
64
+ describe 'deserialize' do
65
+ let(:buffer) { StringIO.new(bytes.pack('C*')) }
66
+ subject { term_class.deserialize(buffer) }
67
+
68
+ # generated using:
69
+ # erl -noshell -eval 'io:format("~w~n", [term_to_binary(fun(a) -> true; (_) -> false end)]), init:stop().'
70
+ #
71
+ let(:bytes) { [
72
+ 0,0,0,212,1,32,134,155,11,165,194,128,94,159,150,25,37,107,162,125,
73
+ 47,0,0,0,6,0,0,0,4,100,0,8,101,114,108,95,101,118,97,108,97,6,98,1,4,52,216,
74
+ 103,100,0,13,110,111,110,111,100,101,64,110,111,104,111,115,116,0,0,0,2,0,0,
75
+ 0,0,0,106,100,0,4,110,111,110,101,100,0,4,110,111,110,101,108,0,0,0,2,104,5,
76
+ 100,0,6,99,108,97,117,115,101,97,1,108,0,0,0,1,104,3,100,0,4,97,116,111,109,
77
+ 97,1,100,0,1,97,106,106,108,0,0,0,1,104,3,100,0,4,97,116,111,109,97,1,100,0,
78
+ 4,116,114,117,101,106,104,5,100,0,6,99,108,97,117,115,101,97,1,108,0,0,0,1,
79
+ 104,3,100,0,3,118,97,114,97,1,100,0,1,95,106,106,108,0,0,0,1,104,3,100,0,4,
80
+ 97,116,111,109,97,1,100,0,5,102,97,108,115,101,106,106
81
+ ] }
82
+
83
+ its(:size) { should eq(212) }
84
+ its(:arity) { should eq(arity) }
85
+ its(:uniq) { should eq(uniq) }
86
+ its(:index) { should eq(index) }
87
+ its(:num_free) { should eq(4) }
88
+ its(:mod) { should eq(mod) }
89
+ its(:old_index) { should eq(old_index) }
90
+ its(:old_uniq) { should eq(old_uniq) }
91
+ its(:pid) { should eq(pid) }
92
+ its(:free_vars) { should eq(free_vars) }
93
+ end
94
+
95
+ describe 'new' do
96
+ subject { term_class.new(arity, uniq, index, mod, old_index, old_uniq, pid, free_vars).tap(&:serialize) }
97
+
98
+ its(:size) { should eq(212) }
99
+ its(:arity) { should eq(arity) }
100
+ its(:uniq) { should eq(uniq) }
101
+ its(:index) { should eq(index) }
102
+ its(:num_free) { should eq(4) }
103
+ its(:mod) { should eq(mod) }
104
+ its(:old_index) { should eq(old_index) }
105
+ its(:old_uniq) { should eq(old_uniq) }
106
+ its(:pid) { should eq(pid) }
107
+ its(:free_vars) { should eq(free_vars) }
108
+ end
109
+ end
110
+
111
+ describe '[instance]' do
112
+ let(:term) { term_class.new(arity, uniq, index, mod, old_index, old_uniq, pid, free_vars) }
113
+
114
+ describe 'serialize' do
115
+ subject { term.serialize }
116
+
117
+ let(:bytes) { [
118
+ 112,0,0,0,212,1,32,134,155,11,165,194,128,94,159,150,25,37,107,162,125,
119
+ 47,0,0,0,6,0,0,0,4,100,0,8,101,114,108,95,101,118,97,108,97,6,98,1,4,52,216,
120
+ 103,100,0,13,110,111,110,111,100,101,64,110,111,104,111,115,116,0,0,0,2,0,0,
121
+ 0,0,0,106,100,0,4,110,111,110,101,100,0,4,110,111,110,101,108,0,0,0,2,104,5,
122
+ 100,0,6,99,108,97,117,115,101,97,1,108,0,0,0,1,104,3,100,0,4,97,116,111,109,
123
+ 97,1,100,0,1,97,106,106,108,0,0,0,1,104,3,100,0,4,97,116,111,109,97,1,100,0,
124
+ 4,116,114,117,101,106,104,5,100,0,6,99,108,97,117,115,101,97,1,108,0,0,0,1,
125
+ 104,3,100,0,3,118,97,114,97,1,100,0,1,95,106,106,108,0,0,0,1,104,3,100,0,4,
126
+ 97,116,111,109,97,1,100,0,5,102,97,108,115,101,106,106
127
+ ].pack('C*') }
128
+
129
+ it { should eq(bytes) }
130
+ end
131
+
132
+ describe '__erlang_type__' do
133
+ subject { term.__erlang_type__ }
134
+
135
+ it { should eq(:new_fun) }
136
+ end
137
+
138
+ describe '__ruby_evolve__' do
139
+ let(:ruby_obj) { term }
140
+ subject { term.__ruby_evolve__ }
141
+
142
+ it { should eq(ruby_obj) }
143
+ end
144
+ end
145
+
146
+ end
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Erlang::ETF::NewReference do
6
+ let(:term_class) { Erlang::ETF::NewReference }
7
+
8
+ let(:node) { Erlang::ETF::Atom.new("node@host").tap(&:serialize) }
9
+ let(:ids) { [1234, 5678] }
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) { [0, 2, 100, 0, 9, 110, 111, 100, 101, 64, 104, 111, 115, 116, 1, 0, 0, 4, 210, 0, 0, 22, 46] }
18
+
19
+ its(:node) { should eq(node) }
20
+ its(:len) { should eq(2) }
21
+ its(:creation) { should eq(creation) }
22
+ its(:ids) { should eq(ids) }
23
+ end
24
+
25
+ describe 'new' do
26
+ subject { term_class.new(node, creation, ids) }
27
+
28
+ its(:node) { should eq(node) }
29
+ its(:len) { should eq(2) }
30
+ its(:creation) { should eq(creation) }
31
+ its(:ids) { should eq(ids) }
32
+ end
33
+ end
34
+
35
+ describe '[instance]' do
36
+ let(:term) { term_class.new(node, creation, ids) }
37
+
38
+ describe 'serialize' do
39
+ subject { term.serialize }
40
+
41
+ let(:bytes) { [114, 0, 2, 100, 0, 9, 110, 111, 100, 101, 64, 104, 111, 115, 116, 1, 0, 0, 4, 210, 0, 0, 22, 46].pack('C*') }
42
+
43
+ it { should eq(bytes) }
44
+ end
45
+
46
+ describe '__erlang_type__' do
47
+ subject { term.__erlang_type__ }
48
+
49
+ it { should eq(:new_reference) }
50
+ end
51
+
52
+ describe '__ruby_evolve__' do
53
+ let(:ruby_obj) { term }
54
+ subject { term.__ruby_evolve__ }
55
+
56
+ it { should eq(ruby_obj) }
57
+ end
58
+ end
59
+
60
+ end