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,159 +0,0 @@
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
@@ -1,100 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
- require 'pry'
5
-
6
- describe Erlang::ETF::Map do
7
- let(:term_class) { Erlang::ETF::Map }
8
-
9
- let(:atom) { Erlang::ETF::SmallAtom.new("test").tap(&:serialize) }
10
- let(:binary) { Erlang::ETF::Binary.new("test").tap(&:serialize) }
11
- let(:new_float) { Erlang::ETF::NewFloat.new(1.1) }
12
- let(:small_integer) { Erlang::ETF::SmallInteger.new(13) }
13
- let(:small_list) { Erlang::ETF::List.new([atom, binary, new_float, small_integer]) }
14
- let(:erlang_nil) { Erlang::ETF::Nil.new }
15
- let(:small_tuple) { Erlang::ETF::SmallTuple.new([atom, binary, new_float, small_integer, small_list]) }
16
- let(:small_map) { Erlang::ETF::Map.new([atom, binary, new_float], [small_integer, erlang_nil, small_list]) }
17
-
18
- describe '[class]' do
19
- describe 'deserialize' do
20
- let(:buffer) { StringIO.new(bytes.pack('C*')) }
21
- subject { term_class.deserialize(buffer) }
22
-
23
- context 'single item map' do
24
- let(:bytes) { [0, 0, 0, 1, 100, 0, 1, 97, 106] }
25
- let(:atom_a) { Erlang::ETF::Atom.new("a").tap(&:serialize) }
26
-
27
- its(:size) { should eq(1) }
28
- its(:keys) { should eq([atom_a]) }
29
- its(:values) { should eq([erlang_nil]) }
30
- end
31
-
32
- context 'multiple item map' do
33
- let(:bytes) { [0, 0, 0, 3, 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] }
34
-
35
- its(:size) { should eq(3) }
36
- its(:keys) { should eq([atom, binary, new_float]) }
37
- its(:values) { should eq([small_integer, erlang_nil, small_list]) }
38
- end
39
- end
40
- end
41
-
42
- describe '[instance]' do
43
- let(:term) { term_class.new(keys, values) }
44
-
45
- let(:atom_a) { Erlang::ETF::Atom.new("a").tap(&:serialize) }
46
-
47
- describe 'serialize' do
48
- subject { term.serialize }
49
-
50
- context 'single item map' do
51
- let(:bytes) { [116, 0, 0, 0, 1, 100, 0, 1, 97, 106].pack('C*') }
52
-
53
- let(:keys) { [atom_a] }
54
- let(:values) { [erlang_nil] }
55
-
56
- it { should eq(bytes) }
57
- end
58
-
59
- context 'multiple item map' do
60
- let(:bytes) { [116, 0, 0, 0, 3, 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, 116, 0, 0, 0, 3, 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*') }
61
-
62
- let(:keys) { [atom, binary, new_float] }
63
- let(:values) { [small_integer, small_map, small_list] }
64
-
65
- it { should eq(bytes) }
66
- end
67
- end
68
-
69
- describe '__erlang_type__' do
70
- subject { term.__erlang_type__ }
71
-
72
- let(:keys) { [atom_a] }
73
- let(:values) { [erlang_nil] }
74
- it { should eq(:map) }
75
- end
76
-
77
- describe '__ruby_evolve__' do
78
- context 'single item map' do
79
- let(:ruby_obj) { ::Erlang::Map[:a, :a] }
80
- subject { term.__ruby_evolve__ }
81
-
82
- let(:keys) { [atom_a] }
83
- let(:values) { [atom_a] }
84
-
85
- it { should eq(ruby_obj) }
86
- end
87
-
88
- context 'multiple item map' do
89
- let(:ruby_obj) { ::Erlang::Map[: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]] }
90
- subject { term.__ruby_evolve__ }
91
-
92
- let(:keys) { [atom, new_float, small_tuple] }
93
- let(:values) { [binary, small_integer, small_list] }
94
-
95
- it { should eq(ruby_obj) }
96
- end
97
- end
98
- end
99
-
100
- end
@@ -1,92 +0,0 @@
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
@@ -1,146 +0,0 @@
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