erlang-etf 1.1.1 → 2.0.0

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.
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,90 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Erlang::ETF::Atom do
6
- let(:term_class) { Erlang::ETF::Atom }
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) { [0, 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) { [0, 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) { [100, 0, 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) { [100, 0, 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(: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
@@ -1,90 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Erlang::ETF::AtomUTF8 do
6
- let(:term_class) { Erlang::ETF::AtomUTF8 }
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) { [0, 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) { [0, 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) { [118, 0, 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) { [118, 0, 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(: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
@@ -1,90 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Erlang::ETF::Binary do
6
- let(:term_class) { Erlang::ETF::Binary }
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) { [0, 0, 0, 4, 116, 101, 115, 116] }
15
-
16
- its(:len) { should eq(4) }
17
- its(:data) { should eq("test") }
18
- end
19
-
20
- context "UTF-8 bytes" do
21
- let(:bytes) { [0, 0, 0, 2, 206, 169] }
22
-
23
- its(:len) { should eq(2) }
24
- its(:data) { should eq("Ω") }
25
- end
26
- end
27
-
28
- describe 'new' do
29
- subject { term_class.new(data) }
30
-
31
- context "ASCII" do
32
- let(:data) { "test" }
33
-
34
- its(:data) { should eq(data) }
35
- end
36
-
37
- context "UTF-8" do
38
- let(:data) { "Ω" }
39
-
40
- its(:data) { should eq(data) }
41
- end
42
- end
43
- end
44
-
45
- describe '[instance]' do
46
- let(:term) { term_class.new(data) }
47
-
48
- describe 'serialize' do
49
- subject { term.serialize }
50
-
51
- context "ASCII" do
52
- let(:data) { "test" }
53
- let(:bytes) { [109, 0, 0, 0, 4, 116, 101, 115, 116].pack('C*') }
54
-
55
- it { should eq(bytes) }
56
- end
57
-
58
- context "UTF-8" do
59
- let(:data) { "Ω" }
60
- let(:bytes) { [109, 0, 0, 0, 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(:data) { "test" }
70
- it { should eq(:binary) }
71
- end
72
-
73
- describe '__ruby_evolve__' do
74
- subject { term.__ruby_evolve__ }
75
-
76
- context "ASCII" do
77
- let(:data) { "test" }
78
-
79
- it { should eq("test") }
80
- end
81
-
82
- context "UTF-8" do
83
- let(:data) { "Ω" }
84
-
85
- it { should eq("Ω") }
86
- end
87
- end
88
- end
89
-
90
- end
@@ -1,99 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Erlang::ETF::BitBinary do
6
- let(:term_class) { Erlang::ETF::BitBinary }
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) { [0, 0, 0, 5, 1, 116, 101, 115, 116, 128] }
15
-
16
- its(:len) { should eq(5) }
17
- its(:bits) { should eq(1) }
18
- its(:data) { should eq("test\x80") }
19
- end
20
-
21
- context "UTF-8 bytes" do
22
- let(:bytes) { [0, 0, 0, 3, 1, 206, 169, 128] }
23
-
24
- its(:len) { should eq(3) }
25
- its(:bits) { should eq(1) }
26
- its(:data) { should eq("Ω\x80") }
27
- end
28
- end
29
-
30
- describe 'new' do
31
- subject { term_class.new(bits, data) }
32
-
33
- context "ASCII" do
34
- let(:bits) { 1 }
35
- let(:data) { "test\x80" }
36
-
37
- its(:data) { should eq(data) }
38
- end
39
-
40
- context "UTF-8" do
41
- let(:bits) { 1 }
42
- let(:data) { "Ω\x80" }
43
-
44
- its(:data) { should eq(data) }
45
- end
46
- end
47
- end
48
-
49
- describe '[instance]' do
50
- let(:term) { term_class.new(bits, data) }
51
-
52
- describe 'serialize' do
53
- subject { term.serialize }
54
-
55
- context "ASCII" do
56
- let(:bits) { 1 }
57
- let(:data) { "test\x80" }
58
- let(:bytes) { [77, 0, 0, 0, 5, 1, 116, 101, 115, 116, 128].pack('C*') }
59
-
60
- it { should eq(bytes) }
61
- end
62
-
63
- context "UTF-8" do
64
- let(:bits) { 1 }
65
- let(:data) { "Ω\x80" }
66
- let(:bytes) { [77, 0, 0, 0, 3, 1, 206, 169, 128].pack('C*') }
67
-
68
- it { should eq(bytes) }
69
- end
70
- end
71
-
72
- describe '__erlang_type__' do
73
- subject { term.__erlang_type__ }
74
-
75
- let(:bits) { 1 }
76
- let(:data) { "test\x80" }
77
- it { should eq(:bit_binary) }
78
- end
79
-
80
- describe '__ruby_evolve__' do
81
- subject { term.__ruby_evolve__ }
82
-
83
- context "ASCII" do
84
- let(:bits) { 1 }
85
- let(:data) { "test\x80" }
86
-
87
- it { should eq(term) }
88
- end
89
-
90
- context "UTF-8" do
91
- let(:bits) { 1 }
92
- let(:data) { "Ω\x80" }
93
-
94
- it { should eq(term) }
95
- end
96
- end
97
- end
98
-
99
- end
@@ -1,37 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Erlang::ETF::Compressed do
6
- let(:term_class) { Erlang::ETF::Compressed }
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 "valid zlib bytes" do
14
- let(:bytes) { [0, 0, 0, 18, 120, 218, 203, 102, 224, 103, 68, 5, 0, 9, 0, 0, 138] }
15
-
16
- its(:uncompressed_size) { should eq(18) }
17
- its(:data) { should eq(::Erlang::ETF::String.new(([1] * 15).pack('C*').from_utf8_binary).tap { |s| s.len = 15 }) }
18
- its(:__ruby_evolve__) { should eq(::Erlang::String.new(([1] * 15).pack('C*').from_utf8_binary)) }
19
- end
20
-
21
- context "invalid zlib bytes" do
22
- subject { -> { term_class.deserialize(buffer) } }
23
- let(:bytes) { [0, 0, 0, 18, 120, 218, 203, 102, 224, 103, 68, 5, 0, 9, 0, 0] }
24
-
25
- it { should raise_error(::Zlib::BufError) }
26
- end
27
-
28
- context "valid zlib bytes, invalid uncompressed size" do
29
- subject { -> { term_class.deserialize(buffer) } }
30
- let(:bytes) { [0, 0, 0, 17, 120, 218, 203, 102, 224, 103, 68, 5, 0, 9, 0, 0, 138] }
31
-
32
- it { should raise_error(::Zlib::DataError) }
33
- end
34
- end
35
- end
36
-
37
- end
@@ -1,58 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Erlang::ETF::Export do
6
- let(:term_class) { Erlang::ETF::Export }
7
-
8
- let(:mod) { Erlang::ETF::Atom.new("erlang").tap(&:serialize) }
9
- let(:function) { Erlang::ETF::Atom.new("now").tap(&:serialize) }
10
- let(:arity) { Erlang::ETF::SmallInteger.new(0).tap(&:serialize) }
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, 6, 101, 114, 108, 97, 110, 103, 100, 0, 3, 110, 111, 119, 97, 0] }
18
-
19
- its(:mod) { should eq(mod) }
20
- its(:function) { should eq(function) }
21
- its(:arity) { should eq(arity) }
22
- end
23
-
24
- describe 'new' do
25
- subject { term_class.new(mod, function, arity) }
26
-
27
- its(:mod) { should eq(mod) }
28
- its(:function) { should eq(function) }
29
- its(:arity) { should eq(arity) }
30
- end
31
- end
32
-
33
- describe '[instance]' do
34
- let(:term) { term_class.new(mod, function, arity) }
35
-
36
- describe 'serialize' do
37
- subject { term.serialize }
38
-
39
- let(:bytes) { [113, 100, 0, 6, 101, 114, 108, 97, 110, 103, 100, 0, 3, 110, 111, 119, 97, 0].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(:export) }
48
- end
49
-
50
- describe '__ruby_evolve__' do
51
- let(:ruby_obj) { ::Erlang::Export.new(:erlang, :now, 0) }
52
- subject { term.__ruby_evolve__ }
53
-
54
- it { should eq(ruby_obj) }
55
- end
56
- end
57
-
58
- end