erlang-terms 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3601d91c1507e3949f9c60b571091b9a959419d0
4
- data.tar.gz: 39d79df7d50eb719fe6dabb77640a14041135811
3
+ metadata.gz: 5eac7619f9acc493a2e29c2034bfbca752e3e3a2
4
+ data.tar.gz: d0453d251e15a1c97e0fbedd3430c83611ffdc31
5
5
  SHA512:
6
- metadata.gz: 3c3a3073708fc654cd4fe651e56baf379ff2a2f49726e5f648b891dfd16c8f18c0ae61500384212bcb8cd8a8ff76ad4c0fbf36eafc3753583340d0dedbe9254f
7
- data.tar.gz: 4eaf82c1a4ec55cf0b73f37d2ac9dc15e2371235276630f41f1590bf3e2e7cf9bb31078180e84bb08e7efa617abddfbf29a07608a4c4206ebc7dcd046fd85579
6
+ metadata.gz: 9df6cd4f3ff07549e79ed11840ad7707486bcfc5bd925bbf73fa1dce4b1c70495f64d0a6cfbeaa0735b1f1326c927a329e206785fd3c0c0d918e31692c8d9dd1
7
+ data.tar.gz: f1f1540c3bc703057833fecbedf0915c8991d674239438b20e35a20b7327a86d6d8e275d5d3ec58a8bd984fe22782a486c5079dd2be02f98eb893437d1717af4
data/README.md CHANGED
@@ -72,6 +72,17 @@ list.improper?
72
72
  # => false
73
73
  ```
74
74
 
75
+ ### Erlang::Nil
76
+
77
+ ```erlang
78
+ Nil = [].
79
+ ```
80
+
81
+ ```ruby
82
+ erlang_nil = Erlang::Nil.new
83
+ # => #<Erlang::Nil []>
84
+ ```
85
+
75
86
  ### Erlang::Pid
76
87
 
77
88
  ```erlang
@@ -12,5 +12,12 @@ module Erlang
12
12
  def inspect
13
13
  "#<#{self.class.name} fun #{mod}:#{function}/#{arity}>"
14
14
  end
15
+
16
+ def ==(other)
17
+ self.class === other &&
18
+ mod.to_s == other.mod.to_s &&
19
+ function.to_s == other.function.to_s &&
20
+ arity == other.arity
21
+ end
15
22
  end
16
23
  end
@@ -20,7 +20,25 @@ module Erlang
20
20
  end
21
21
 
22
22
  def pretty_inspect
23
- "#<#{self.class.name} #{super[0..-3]} | #{tail.inspect}]>\n"
23
+ "#<#{self.class.name} #{super[0..-2]}>\n"
24
+ end
25
+
26
+ def pretty_print(q)
27
+ q.group(1, '[', " | #{tail.inspect}]") {
28
+ q.seplist(self) { |v|
29
+ q.pp v
30
+ }
31
+ }
32
+ end
33
+
34
+ def ==(other)
35
+ if improper? and not other.respond_to?(:tail)
36
+ false
37
+ elsif other.respond_to?(:tail)
38
+ super && tail == other.tail
39
+ else
40
+ super
41
+ end
24
42
  end
25
43
  end
26
44
  end
@@ -0,0 +1,15 @@
1
+ module Erlang
2
+ class Nil
3
+ def inspect
4
+ "#<#{self.class.name} []>"
5
+ end
6
+
7
+ def ==(other)
8
+ if other == []
9
+ true
10
+ else
11
+ other === self.class
12
+ end
13
+ end
14
+ end
15
+ end
@@ -19,5 +19,13 @@ module Erlang
19
19
  " @node=#{node.inspect}\n" <<
20
20
  " @creation=#{creation.inspect}>"
21
21
  end
22
+
23
+ def ==(other)
24
+ self.class === other &&
25
+ node.to_s == other.node.to_s &&
26
+ id.to_s == other.id.to_s &&
27
+ serial == other.serial &&
28
+ creation == other.creation
29
+ end
22
30
  end
23
31
  end
@@ -7,6 +7,7 @@ end
7
7
 
8
8
  require "erlang/export"
9
9
  require "erlang/list"
10
+ require "erlang/nil"
10
11
  require "erlang/pid"
11
12
  require "erlang/string"
12
13
  require "erlang/tuple"
@@ -1,5 +1,5 @@
1
1
  module Erlang
2
2
  module Terms
3
- VERSION = "0.0.2"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -1,11 +1,23 @@
1
1
  module Erlang
2
2
  class Tuple < ::Array
3
+ def arity
4
+ length
5
+ end
6
+
3
7
  def inspect
4
8
  "#<#{self.class.name} {#{super[1..-2]}}>"
5
9
  end
6
10
 
7
11
  def pretty_inspect
8
- "#<#{self.class.name} {#{super[1..-3]}}>\n"
12
+ "#<#{self.class.name} #{super[0..-2]}>\n"
13
+ end
14
+
15
+ def pretty_print(q)
16
+ q.group(1, '{', '}') {
17
+ q.seplist(self) { |v|
18
+ q.pp v
19
+ }
20
+ }
9
21
  end
10
22
  end
11
23
  end
@@ -7,5 +7,11 @@ describe Erlang::Export do
7
7
  it 'formats as #<Erlang::Export fun module:function/arity>' do
8
8
  expect(subject.inspect).to eq("#<Erlang::Export fun module:function/1>")
9
9
  end
10
+
11
+ it 'compares with other exports' do
12
+ expect(subject).to eq(subject)
13
+ expect(subject).to eq(Erlang::Export.new('module', 'function', 1))
14
+ expect(subject).to_not eq(Erlang::Export.new('module', 'function', 0))
15
+ end
10
16
  end
11
17
  end
@@ -20,4 +20,20 @@ describe Erlang::List do
20
20
  end
21
21
  end
22
22
  end
23
+
24
+ it 'has | [] in pretty_inspect' do
25
+ expect(Erlang::List[:a].pretty_inspect).to include("| []")
26
+ end
27
+
28
+ context '#==' do
29
+ subject { Erlang::List[:a, :b] }
30
+
31
+ it 'compares with other lists' do
32
+ expect(subject).to eq(subject)
33
+ expect(subject).to eq(Erlang::List[:a, :b])
34
+ expect(subject).to_not eq(Erlang::List[:a, :b].tail(:c))
35
+ expect(subject).to eq([:a, :b])
36
+ expect(Erlang::List[:a].tail(:c)).to_not eq([:a])
37
+ end
38
+ end
23
39
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Erlang::Nil do
4
+ describe '#inspect' do
5
+ subject { Erlang::Nil.new }
6
+
7
+ it 'formats as #<Erlang::Nil []>' do
8
+ expect(subject.inspect).to eq("#<Erlang::Nil []>")
9
+ end
10
+
11
+ it 'compares with other nil (and [])' do
12
+ expect(subject).to eq(subject)
13
+ expect(subject).to eq(Erlang::Nil.new)
14
+ expect(subject).to eq([])
15
+ expect(subject).to_not eq([:a])
16
+ end
17
+ end
18
+ end
@@ -7,5 +7,15 @@ describe Erlang::Pid do
7
7
  it 'formats as #<Erlang::Pid <0.100.5> @node="nonode@nohost" @creation=1>' do
8
8
  expect(subject.inspect).to eq('#<Erlang::Pid <0.100.5> @node="nonode@nohost" @creation=1>')
9
9
  end
10
+
11
+ it 'has <0.100.5> in the pretty_inspect' do
12
+ expect(subject.pretty_inspect).to include("<0.100.5>")
13
+ end
14
+
15
+ it 'compares with other pids' do
16
+ expect(subject).to eq(subject)
17
+ expect(subject).to eq(Erlang::Pid.new(:'nonode@nohost', 100, 5, 1))
18
+ expect(subject).to_not eq(Erlang::Pid.new('nonode@nohost', 100, 5, 0))
19
+ end
10
20
  end
11
21
  end
@@ -7,5 +7,14 @@ describe Erlang::Tuple do
7
7
  it 'formats as #<Erlang::Tuple {:a, 1, "one"}>' do
8
8
  expect(subject.inspect).to eq('#<Erlang::Tuple {:a, 1, "one"}>')
9
9
  end
10
+
11
+ it 'has {} in pretty_inspect' do
12
+ expect(Erlang::Tuple[].pretty_inspect).to include("{}")
13
+ expect(Erlang::Tuple[Erlang::Tuple[]].pretty_inspect).to include("{{}}")
14
+ end
15
+
16
+ it 'arity equals length' do
17
+ expect(subject.arity).to eq(subject.length)
18
+ end
10
19
  end
11
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erlang-terms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Bennett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-18 00:00:00.000000000 Z
11
+ date: 2013-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,6 +98,7 @@ files:
98
98
  - erlang-terms.gemspec
99
99
  - lib/erlang/export.rb
100
100
  - lib/erlang/list.rb
101
+ - lib/erlang/nil.rb
101
102
  - lib/erlang/pid.rb
102
103
  - lib/erlang/string.rb
103
104
  - lib/erlang/terms.rb
@@ -105,6 +106,7 @@ files:
105
106
  - lib/erlang/tuple.rb
106
107
  - spec/erlang/export_spec.rb
107
108
  - spec/erlang/list_spec.rb
109
+ - spec/erlang/nil_spec.rb
108
110
  - spec/erlang/pid_spec.rb
109
111
  - spec/erlang/string_spec.rb
110
112
  - spec/erlang/terms_spec.rb
@@ -137,6 +139,7 @@ summary: Erlang terms represented in Ruby
137
139
  test_files:
138
140
  - spec/erlang/export_spec.rb
139
141
  - spec/erlang/list_spec.rb
142
+ - spec/erlang/nil_spec.rb
140
143
  - spec/erlang/pid_spec.rb
141
144
  - spec/erlang/string_spec.rb
142
145
  - spec/erlang/terms_spec.rb