erlang-etf 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +20 -0
  3. data/.gitignore +10 -18
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +15 -4
  7. data/CHANGELOG.md +7 -0
  8. data/Gemfile +10 -6
  9. data/LICENSE.txt +1 -1
  10. data/README.md +13 -13
  11. data/Rakefile +8 -6
  12. data/erlang-etf.gemspec +10 -10
  13. data/lib/erlang-etf.rb +1 -0
  14. data/lib/erlang/etf.rb +363 -30
  15. data/lib/erlang/etf/atom.rb +28 -48
  16. data/lib/erlang/etf/atom_utf8.rb +28 -48
  17. data/lib/erlang/etf/binary.rb +24 -23
  18. data/lib/erlang/etf/bit_binary.rb +35 -27
  19. data/lib/erlang/etf/compressed.rb +61 -35
  20. data/lib/erlang/etf/export.rb +44 -21
  21. data/lib/erlang/etf/float.rb +33 -29
  22. data/lib/erlang/etf/fun.rb +54 -32
  23. data/lib/erlang/etf/integer.rb +24 -12
  24. data/lib/erlang/etf/large_big.rb +31 -37
  25. data/lib/erlang/etf/large_tuple.rb +41 -30
  26. data/lib/erlang/etf/list.rb +55 -25
  27. data/lib/erlang/etf/map.rb +58 -28
  28. data/lib/erlang/etf/new_float.rb +25 -14
  29. data/lib/erlang/etf/new_fun.rb +70 -47
  30. data/lib/erlang/etf/new_reference.rb +51 -24
  31. data/lib/erlang/etf/nil.rb +21 -6
  32. data/lib/erlang/etf/pid.rb +48 -21
  33. data/lib/erlang/etf/port.rb +49 -13
  34. data/lib/erlang/etf/reference.rb +49 -13
  35. data/lib/erlang/etf/small_atom.rb +31 -27
  36. data/lib/erlang/etf/small_atom_utf8.rb +31 -27
  37. data/lib/erlang/etf/small_big.rb +30 -39
  38. data/lib/erlang/etf/small_integer.rb +27 -12
  39. data/lib/erlang/etf/small_tuple.rb +41 -30
  40. data/lib/erlang/etf/string.rb +23 -23
  41. data/lib/erlang/etf/term.rb +109 -70
  42. data/lib/erlang/etf/version.rb +1 -1
  43. metadata +33 -169
  44. data/.rspec +0 -2
  45. data/lib/erlang/etf/bert.rb +0 -74
  46. data/lib/erlang/etf/extensions.rb +0 -144
  47. data/lib/erlang/etf/extensions/array.rb +0 -27
  48. data/lib/erlang/etf/extensions/big_decimal.rb +0 -20
  49. data/lib/erlang/etf/extensions/erlang-export.rb +0 -24
  50. data/lib/erlang/etf/extensions/erlang-list.rb +0 -29
  51. data/lib/erlang/etf/extensions/erlang-map.rb +0 -26
  52. data/lib/erlang/etf/extensions/erlang-nil.rb +0 -20
  53. data/lib/erlang/etf/extensions/erlang-pid.rb +0 -20
  54. data/lib/erlang/etf/extensions/erlang-string.rb +0 -31
  55. data/lib/erlang/etf/extensions/erlang-tuple.rb +0 -29
  56. data/lib/erlang/etf/extensions/false_class.rb +0 -26
  57. data/lib/erlang/etf/extensions/float.rb +0 -18
  58. data/lib/erlang/etf/extensions/hash.rb +0 -30
  59. data/lib/erlang/etf/extensions/integer.rb +0 -46
  60. data/lib/erlang/etf/extensions/nil_class.rb +0 -27
  61. data/lib/erlang/etf/extensions/object.rb +0 -22
  62. data/lib/erlang/etf/extensions/regexp.rb +0 -32
  63. data/lib/erlang/etf/extensions/string.rb +0 -33
  64. data/lib/erlang/etf/extensions/symbol.rb +0 -43
  65. data/lib/erlang/etf/extensions/time.rb +0 -27
  66. data/lib/erlang/etf/extensions/true_class.rb +0 -26
  67. data/lib/erlang/etf/terms.rb +0 -132
  68. data/spec/erlang/etf/atom_spec.rb +0 -90
  69. data/spec/erlang/etf/atom_utf8_spec.rb +0 -90
  70. data/spec/erlang/etf/binary_spec.rb +0 -90
  71. data/spec/erlang/etf/bit_binary_spec.rb +0 -99
  72. data/spec/erlang/etf/compressed_spec.rb +0 -37
  73. data/spec/erlang/etf/export_spec.rb +0 -58
  74. data/spec/erlang/etf/extensions/array_spec.rb +0 -40
  75. data/spec/erlang/etf/extensions/big_decimal_spec.rb +0 -26
  76. data/spec/erlang/etf/extensions/erlang-export_spec.rb +0 -32
  77. data/spec/erlang/etf/extensions/erlang-list_spec.rb +0 -76
  78. data/spec/erlang/etf/extensions/erlang-map_spec.rb +0 -48
  79. data/spec/erlang/etf/extensions/erlang-nil_spec.rb +0 -24
  80. data/spec/erlang/etf/extensions/erlang-pid_spec.rb +0 -33
  81. data/spec/erlang/etf/extensions/erlang-string_spec.rb +0 -41
  82. data/spec/erlang/etf/extensions/erlang-tuple_spec.rb +0 -57
  83. data/spec/erlang/etf/extensions/false_class_spec.rb +0 -29
  84. data/spec/erlang/etf/extensions/float_spec.rb +0 -24
  85. data/spec/erlang/etf/extensions/hash_spec.rb +0 -90
  86. data/spec/erlang/etf/extensions/integer_spec.rb +0 -259
  87. data/spec/erlang/etf/extensions/nil_class_spec.rb +0 -29
  88. data/spec/erlang/etf/extensions/object_spec.rb +0 -30
  89. data/spec/erlang/etf/extensions/regexp_spec.rb +0 -35
  90. data/spec/erlang/etf/extensions/string_spec.rb +0 -43
  91. data/spec/erlang/etf/extensions/symbol_spec.rb +0 -64
  92. data/spec/erlang/etf/extensions/time_spec.rb +0 -32
  93. data/spec/erlang/etf/extensions/true_class_spec.rb +0 -29
  94. data/spec/erlang/etf/float_spec.rb +0 -92
  95. data/spec/erlang/etf/fun_spec.rb +0 -132
  96. data/spec/erlang/etf/integer_spec.rb +0 -57
  97. data/spec/erlang/etf/large_big_spec.rb +0 -67
  98. data/spec/erlang/etf/large_tuple_spec.rb +0 -119
  99. data/spec/erlang/etf/list_spec.rb +0 -159
  100. data/spec/erlang/etf/map_spec.rb +0 -100
  101. data/spec/erlang/etf/new_float_spec.rb +0 -92
  102. data/spec/erlang/etf/new_fun_spec.rb +0 -146
  103. data/spec/erlang/etf/new_reference_spec.rb +0 -60
  104. data/spec/erlang/etf/nil_spec.rb +0 -50
  105. data/spec/erlang/etf/pid_spec.rb +0 -61
  106. data/spec/erlang/etf/port_spec.rb +0 -58
  107. data/spec/erlang/etf/reference_spec.rb +0 -58
  108. data/spec/erlang/etf/small_atom_spec.rb +0 -90
  109. data/spec/erlang/etf/small_atom_utf8_spec.rb +0 -90
  110. data/spec/erlang/etf/small_big_spec.rb +0 -67
  111. data/spec/erlang/etf/small_integer_spec.rb +0 -57
  112. data/spec/erlang/etf/small_tuple_spec.rb +0 -112
  113. data/spec/erlang/etf/string_spec.rb +0 -92
  114. data/spec/erlang/etf/term_spec.rb +0 -27
  115. data/spec/erlang/etf/terms_spec.rb +0 -23
  116. data/spec/erlang/etf_spec.rb +0 -23
  117. data/spec/erlang_spec.rb +0 -95
  118. data/spec/spec_helper.rb +0 -31
@@ -1,259 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Erlang::ETF::Extensions::Integer do
6
- let(:klass) { ::Integer }
7
-
8
- let(:small_integer_min) { Erlang::ETF::Extensions::Integer::UINT8_MIN }
9
- let(:small_integer_max) { Erlang::ETF::Extensions::Integer::UINT8_MAX }
10
- let(:integer_min) { Erlang::ETF::Extensions::Integer::INT32_MIN }
11
- let(:integer_max) { Erlang::ETF::Extensions::Integer::INT32_MAX }
12
- let(:small_big_min) { (-1 << (255 * 8)) + 1 }
13
- let(:small_big_max) { (+1 << (255 * 8)) - 1 }
14
-
15
- describe '[instance]' do
16
- describe '__erlang_type__' do
17
- subject { instance.__erlang_type__ }
18
-
19
- context "when between #{Erlang::ETF::Extensions::Integer::UINT8_MIN} and #{Erlang::ETF::Extensions::Integer::UINT8_MAX}" do
20
- let(:min) { small_integer_min }
21
- let(:max) { small_integer_max }
22
-
23
- let(:current) { :small_integer }
24
- let(:positive) { :integer }
25
- let(:negative) { :integer }
26
-
27
- context 'minimum' do
28
- let(:instance) { min }
29
- it { should eq(current) }
30
- end
31
-
32
- context 'minimum + 1' do
33
- let(:instance) { min + 1 }
34
- it { should eq(current) }
35
- end
36
-
37
- context 'minimum - 1' do
38
- let(:instance) { min - 1 }
39
- it { should eq(negative) }
40
- end
41
-
42
- context 'maximum' do
43
- let(:instance) { max }
44
- it { should eq(current) }
45
- end
46
-
47
- context 'maximum + 1' do
48
- let(:instance) { max + 1 }
49
- it { should eq(positive) }
50
- end
51
-
52
- context 'maximum - 1' do
53
- let(:instance) { max - 1 }
54
- it { should eq(current) }
55
- end
56
- end
57
-
58
- context "when between #{Erlang::ETF::Extensions::Integer::INT32_MIN} and #{Erlang::ETF::Extensions::Integer::INT32_MAX}" do
59
- let(:min) { integer_min }
60
- let(:max) { integer_max }
61
-
62
- let(:current) { :integer }
63
- let(:positive) { :small_big }
64
- let(:negative) { :small_big }
65
-
66
- context 'minimum' do
67
- let(:instance) { min }
68
- it { should eq(current) }
69
- end
70
-
71
- context 'minimum + 1' do
72
- let(:instance) { min + 1 }
73
- it { should eq(current) }
74
- end
75
-
76
- context 'minimum - 1' do
77
- let(:instance) { min - 1 }
78
- it { should eq(negative) }
79
- end
80
-
81
- context 'maximum' do
82
- let(:instance) { max }
83
- it { should eq(current) }
84
- end
85
-
86
- context 'maximum + 1' do
87
- let(:instance) { max + 1 }
88
- it { should eq(positive) }
89
- end
90
-
91
- context 'maximum - 1' do
92
- let(:instance) { max - 1 }
93
- it { should eq(current) }
94
- end
95
- end
96
-
97
- context "when between ((-1 << (255 * 8)) + 1) and ((+1 << (255 * 8)) - 1)" do
98
- let(:min) { small_big_min }
99
- let(:max) { small_big_max }
100
-
101
- let(:current) { :small_big }
102
- let(:positive) { :large_big }
103
- let(:negative) { :large_big }
104
-
105
- context 'minimum' do
106
- let(:instance) { min }
107
- it { should eq(current) }
108
- end
109
-
110
- context 'minimum + 1' do
111
- let(:instance) { min + 1 }
112
- it { should eq(current) }
113
- end
114
-
115
- context 'minimum - 1' do
116
- let(:instance) { min - 1 }
117
- it { should eq(negative) }
118
- end
119
-
120
- context 'maximum' do
121
- let(:instance) { max }
122
- it { should eq(current) }
123
- end
124
-
125
- context 'maximum + 1' do
126
- let(:instance) { max + 1 }
127
- it { should eq(positive) }
128
- end
129
-
130
- context 'maximum - 1' do
131
- let(:instance) { max - 1 }
132
- it { should eq(current) }
133
- end
134
- end
135
- end
136
-
137
- describe '__erlang_evolve__' do
138
- subject { instance.__erlang_evolve__ }
139
-
140
- context "when >= #{Erlang::ETF::Extensions::Integer::UINT8_MIN} and <= #{Erlang::ETF::Extensions::Integer::UINT8_MAX}" do
141
- let(:min) { small_integer_min }
142
- let(:max) { small_integer_max }
143
-
144
- let(:current) { Erlang::ETF::SmallInteger.new(instance) }
145
- let(:positive) { Erlang::ETF::Integer.new(instance) }
146
- let(:negative) { Erlang::ETF::Integer.new(instance) }
147
-
148
- context 'minimum' do
149
- let(:instance) { min }
150
- it { should eq(current) }
151
- end
152
-
153
- context 'minimum + 1' do
154
- let(:instance) { min + 1 }
155
- it { should eq(current) }
156
- end
157
-
158
- context 'minimum - 1' do
159
- let(:instance) { min - 1 }
160
- it { should eq(negative) }
161
- end
162
-
163
- context 'maximum' do
164
- let(:instance) { max }
165
- it { should eq(current) }
166
- end
167
-
168
- context 'maximum + 1' do
169
- let(:instance) { max + 1 }
170
- it { should eq(positive) }
171
- end
172
-
173
- context 'maximum - 1' do
174
- let(:instance) { max - 1 }
175
- it { should eq(current) }
176
- end
177
- end
178
-
179
- context "when between #{Erlang::ETF::Extensions::Integer::INT32_MIN} and #{Erlang::ETF::Extensions::Integer::INT32_MAX}" do
180
- let(:min) { integer_min }
181
- let(:max) { integer_max }
182
-
183
- let(:current) { Erlang::ETF::Integer.new(instance) }
184
- let(:positive) { Erlang::ETF::SmallBig.new(instance) }
185
- let(:negative) { Erlang::ETF::SmallBig.new(instance) }
186
-
187
- context 'minimum' do
188
- let(:instance) { min }
189
- it { should eq(current) }
190
- end
191
-
192
- context 'minimum + 1' do
193
- let(:instance) { min + 1 }
194
- it { should eq(current) }
195
- end
196
-
197
- context 'minimum - 1' do
198
- let(:instance) { min - 1 }
199
- it { should eq(negative) }
200
- end
201
-
202
- context 'maximum' do
203
- let(:instance) { max }
204
- it { should eq(current) }
205
- end
206
-
207
- context 'maximum + 1' do
208
- let(:instance) { max + 1 }
209
- it { should eq(positive) }
210
- end
211
-
212
- context 'maximum - 1' do
213
- let(:instance) { max - 1 }
214
- it { should eq(current) }
215
- end
216
- end
217
-
218
- context "when between ((-1 << (255 * 8)) + 1) and ((+1 << (255 * 8)) - 1)" do
219
- let(:min) { small_big_min }
220
- let(:max) { small_big_max }
221
-
222
- let(:current) { Erlang::ETF::SmallBig.new(instance) }
223
- let(:positive) { Erlang::ETF::LargeBig.new(instance) }
224
- let(:negative) { Erlang::ETF::LargeBig.new(instance) }
225
-
226
- context 'minimum' do
227
- let(:instance) { min }
228
- it { should eq(current) }
229
- end
230
-
231
- context 'minimum + 1' do
232
- let(:instance) { min + 1 }
233
- it { should eq(current) }
234
- end
235
-
236
- context 'minimum - 1' do
237
- let(:instance) { min - 1 }
238
- it { should eq(negative) }
239
- end
240
-
241
- context 'maximum' do
242
- let(:instance) { max }
243
- it { should eq(current) }
244
- end
245
-
246
- context 'maximum + 1' do
247
- let(:instance) { max + 1 }
248
- it { should eq(positive) }
249
- end
250
-
251
- context 'maximum - 1' do
252
- let(:instance) { max - 1 }
253
- it { should eq(current) }
254
- end
255
- end
256
- end
257
- end
258
-
259
- end
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Erlang::ETF::Extensions::NilClass do
6
- let(:klass) { ::NilClass }
7
-
8
- describe '[instance]' do
9
- let(:instance) { nil }
10
-
11
- describe '__erlang_type__' do
12
- subject { instance.__erlang_type__ }
13
-
14
- it { should eq(:bert_nil) }
15
- end
16
-
17
- describe '__erlang_evolve__' do
18
- subject { instance.__erlang_evolve__ }
19
-
20
- it { should eq(
21
- Erlang::ETF::SmallTuple.new([
22
- Erlang::ETF::SmallAtom.new("bert"),
23
- Erlang::ETF::SmallAtom.new("nil")
24
- ])
25
- ) }
26
- end
27
- end
28
-
29
- end
@@ -1,30 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Erlang::ETF::Extensions::Object do
6
- let(:klass) { ::Object }
7
-
8
- describe '[instance]' do
9
- let(:instance) { klass.new }
10
-
11
- describe '__erlang_type__' do
12
- subject { -> { instance.__erlang_type__ } }
13
-
14
- it { should raise_error(NotImplementedError) }
15
- end
16
-
17
- describe '__erlang_evolve__' do
18
- subject { -> { instance.__erlang_evolve__ } }
19
-
20
- it { should raise_error(NotImplementedError) }
21
- end
22
-
23
- describe '__erlang_dump__' do
24
- subject { -> { instance.__erlang_dump__("") } }
25
-
26
- it { should raise_error(NotImplementedError) }
27
- end
28
- end
29
-
30
- end
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Erlang::ETF::Extensions::Regexp do
6
- let(:klass) { ::Regexp }
7
-
8
- describe '[instance]' do
9
- let(:instance) { /./imx }
10
-
11
- describe '__erlang_type__' do
12
- subject { instance.__erlang_type__ }
13
-
14
- it { should eq(:bert_regex) }
15
- end
16
-
17
- describe '__erlang_evolve__' do
18
- subject { instance.__erlang_evolve__ }
19
-
20
- it { should eq(
21
- Erlang::ETF::SmallTuple.new([
22
- Erlang::ETF::SmallAtom.new("bert"),
23
- Erlang::ETF::SmallAtom.new("regex"),
24
- Erlang::ETF::Binary.new("."),
25
- Erlang::ETF::List.new([
26
- Erlang::ETF::SmallAtom.new("caseless"),
27
- Erlang::ETF::SmallAtom.new("extended"),
28
- Erlang::ETF::SmallAtom.new("multiline")
29
- ])
30
- ])
31
- ) }
32
- end
33
- end
34
-
35
- end
@@ -1,43 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Erlang::ETF::Extensions::String do
6
- let(:klass) { ::String }
7
-
8
- describe '[instance]' do
9
- let(:instance) { "test" }
10
-
11
- describe '__erlang_type__' do
12
- subject { instance.__erlang_type__ }
13
-
14
- it { should eq(:binary) }
15
- end
16
-
17
- describe '__erlang_evolve__' do
18
- subject { instance.__erlang_evolve__ }
19
-
20
- it { should eq(Erlang::ETF::Binary.new(instance)) }
21
- end
22
-
23
- describe 'to_utf8_binary' do
24
- it "converts \"Ω\" to \"\\xCE\\xA9\"" do
25
- expect("Ω".to_utf8_binary).to eq("\xCE\xA9".force_encoding('BINARY'))
26
- end
27
-
28
- it "handles EncodingError" do
29
- string = "Ωomega"
30
- string.should_receive(:encode).with(Erlang::ETF::Extensions::UTF8_ENCODING).and_raise(EncodingError)
31
-
32
- expect(string.to_utf8_binary).to eq("\xCE\xA9omega".force_encoding('BINARY'))
33
- end
34
- end
35
-
36
- describe 'from_utf8_binary' do
37
- it "converts \"\\xCE\\xA9\" to \"Ω\"" do
38
- expect("\xCE\xA9".force_encoding('BINARY').from_utf8_binary).to eq("Ω")
39
- end
40
- end
41
- end
42
-
43
- end
@@ -1,64 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Erlang::ETF::Extensions::Symbol do
6
- let(:klass) { ::Symbol }
7
-
8
- describe '[instance]' do
9
- describe '__erlang_type__' do
10
- subject { instance.__erlang_type__ }
11
-
12
- context 'when bytesize is < 256' do
13
- let(:instance) { :a }
14
- it { should eq(:small_atom) }
15
-
16
- context 'when it contains UTF-8 characters' do
17
- let(:instance) { :'Ω' }
18
- it { should eq(:small_atom_utf8) }
19
- end
20
- end
21
-
22
- context 'when bytesize is >= 256' do
23
- let(:instance) { ("a" * 256).intern }
24
- it { should eq(:atom) }
25
-
26
- context 'when it contains UTF-8 characters' do
27
- let(:instance) { ("Ω" * 256).intern }
28
- it { should eq(:atom_utf8) }
29
- end
30
- end
31
- end
32
-
33
- describe '__erlang_evolve__' do
34
- subject { instance.__erlang_evolve__ }
35
-
36
- context 'when bytesize is < 256' do
37
- let(:instance) { :a }
38
- it { should eq(Erlang::ETF::SmallAtom.new(instance.to_s)) }
39
-
40
- context 'when it contains UTF-8 characters' do
41
- let(:instance) { :'Ω' }
42
- it { should eq(Erlang::ETF::SmallAtomUTF8.new(instance.to_s)) }
43
- end
44
- end
45
-
46
- context 'when bytesize is >= 256' do
47
- let(:instance) { ("a" * 256).intern }
48
- it { should eq(Erlang::ETF::Atom.new(instance.to_s)) }
49
-
50
- context 'when it contains UTF-8 characters' do
51
- let(:instance) { ("Ω" * 256).intern }
52
- it { should eq(Erlang::ETF::AtomUTF8.new(instance.to_s)) }
53
- end
54
- end
55
- end
56
-
57
- describe 'to_utf8_binary' do
58
- it "converts :Ω to \"\\xCE\\xA9\"" do
59
- expect(:'Ω'.to_utf8_binary).to eq("\xCE\xA9".force_encoding('BINARY'))
60
- end
61
- end
62
- end
63
-
64
- end