erlectricity 0.2.1 → 1.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 (49) hide show
  1. data/History.txt +14 -1
  2. data/LICENSE +20 -0
  3. data/README.md +130 -0
  4. data/Rakefile +63 -60
  5. data/VERSION.yml +4 -0
  6. data/examples/echo/README.md +12 -0
  7. data/examples/echo/echo.erl +13 -0
  8. data/examples/echo/echo.rb +11 -0
  9. data/examples/gruff/gruff.erl +17 -18
  10. data/examples/gruff/gruff_provider.rb +12 -19
  11. data/examples/gruff/{gruff_run.erl → gruff_run.sh} +5 -3
  12. data/examples/gruff/{stat_run.erl → stat_run.sh} +5 -3
  13. data/examples/gruff/stat_writer.erl +6 -6
  14. data/examples/simple/README.md +5 -0
  15. data/examples/simple/rerl.rb +111 -0
  16. data/examples/simple/rerl.sh +37 -0
  17. data/examples/tinderl/README.md +14 -0
  18. data/examples/tinderl/tinderl.erl +19 -21
  19. data/examples/tinderl/tinderl.rb +11 -10
  20. data/ext/decoder.c +67 -60
  21. data/lib/erlectricity.rb +4 -7
  22. data/lib/erlectricity/condition.rb +35 -20
  23. data/lib/erlectricity/conditions/boolean.rb +11 -0
  24. data/lib/erlectricity/conditions/hash.rb +9 -10
  25. data/lib/erlectricity/conditions/static.rb +31 -10
  26. data/lib/erlectricity/conditions/type.rb +14 -14
  27. data/lib/erlectricity/constants.rb +3 -4
  28. data/lib/erlectricity/decoder.rb +205 -199
  29. data/lib/erlectricity/encoder.rb +49 -35
  30. data/lib/erlectricity/errors/decode_error.rb +1 -1
  31. data/lib/erlectricity/errors/encode_error.rb +1 -1
  32. data/lib/erlectricity/errors/erlectricity_error.rb +1 -1
  33. data/lib/erlectricity/matcher.rb +15 -32
  34. data/lib/erlectricity/port.rb +11 -11
  35. data/lib/erlectricity/receiver.rb +54 -64
  36. data/lib/erlectricity/types/list.rb +3 -1
  37. data/test/condition_spec.rb +8 -9
  38. data/test/decode_spec.rb +27 -28
  39. data/test/encode_spec.rb +31 -24
  40. data/test/matcher_spec.rb +24 -12
  41. data/test/port_spec.rb +3 -4
  42. data/test/receiver_spec.rb +18 -20
  43. data/test/test_helper.rb +9 -5
  44. metadata +36 -29
  45. data/CONTRIBUTORS +0 -2
  46. data/Manifest.txt +0 -45
  47. data/README.txt +0 -43
  48. data/setup.rb +0 -1585
  49. data/test/test_erlectricity.rb +0 -2
data/test/decode_spec.rb CHANGED
@@ -3,127 +3,126 @@ require File.dirname(__FILE__) + '/test_helper.rb'
3
3
  context "When unpacking from a binary stream" do
4
4
  setup do
5
5
  end
6
-
6
+
7
7
  specify "an erlang atom should decode to a ruby symbol" do
8
8
  get("haha").should == :haha
9
9
  end
10
-
10
+
11
11
  specify "an erlang number encoded as a small_int (< 255) should decode to a fixnum" do
12
12
  get("0").should == 0
13
13
  get("255").should == 255
14
14
  end
15
-
15
+
16
16
  specify "an erlang number encoded as a int (signed 27-bit number) should decode to a fixnum" do
17
17
  get("256").should == 256
18
18
  get("#{(1 << 27) -1}").should == (1 << 27) -1
19
19
  get("-1").should == -1
20
20
  get("#{-(1 << 27)}").should == -(1 << 27)
21
21
  end
22
-
23
-
22
+
24
23
  specify "an erlang number encoded as a small bignum (1 byte length) should decode to fixnum if it can" do
25
24
  get("#{(1 << 27)}").should == (1 << 27)
26
25
  get("#{-(1 << 27) - 1}").should == -(1 << 27) - 1
27
26
  get("#{(1 << word_length) - 1}").should == (1 << word_length) - 1
28
27
  get("#{-(1 << word_length)}").should == -(1 << word_length)
29
28
  end
30
-
29
+
31
30
  specify "an erlang number encoded as a small bignum (1 byte length) should decode to bignum if it can't be a fixnum" do
32
31
  get("#{(1 << word_length)}").should == (1 << word_length)
33
32
  get("#{-(1 << word_length) - 1}").should == -(1 << word_length) - 1
34
33
  get("#{(1 << (255 * 8)) - 1}").should == (1 << (255 * 8)) - 1
35
34
  get("#{-((1 << (255 * 8)) - 1)}").should == -((1 << (255 * 8)) - 1)
36
35
  end
37
-
38
-
36
+
39
37
  specify "an erlang number encoded as a big bignum (4 byte length) should decode to bignum" do
40
38
  get("#{(1 << (255 * 8)) }").should == (1 << (255 * 8))
41
39
  get("#{-(1 << (255 * 8))}").should == -(1 << (255 * 8))
42
40
  get("#{(1 << (512 * 8)) }").should == (1 << (512 * 8))
43
41
  get("#{-(1 << (512 * 8))}").should == -(1 << (512 * 8))
44
42
  end
45
-
43
+
46
44
  specify "an erlang float should decode to a Float" do
47
45
  get("#{1.0}").should == 1.0
48
46
  get("#{-1.0}").should == -1.0
49
47
  get("#{123.456}").should == 123.456
50
48
  get("#{123.456789012345}").should == 123.456789012345
51
49
  end
52
-
53
-
50
+
54
51
  specify "an erlang reference should decode to a Reference object" do
55
52
  ref = get("make_ref()")
56
53
  ref.should.be.instance_of Erlectricity::NewReference
57
54
  ref.node.should.be.instance_of Symbol
58
55
  end
59
-
56
+
60
57
  specify "an erlang pid should decode to a Pid object" do
61
58
  pid = get("spawn(fun() -> 3 end)")
62
59
  pid.should.be.instance_of Erlectricity::Pid
63
60
  pid.node.should.be.instance_of Symbol
64
61
  end
65
-
66
-
62
+
67
63
  specify "an erlang tuple encoded as a small tuple (1-byte length) should decode to an array" do
68
64
  ref = get("{3}")
69
65
  ref.length.should == 1
70
66
  ref.first.should == 3
71
-
67
+
72
68
  ref = get("{3, a, make_ref()}")
73
69
  ref.length.should == 3
74
70
  ref[0].should == 3
75
71
  ref[1].should == :a
76
72
  ref[2].class.should == Erlectricity::NewReference
77
-
73
+
78
74
  tuple_meat = (['3'] * 255).join(', ')
79
75
  ref = get("{#{tuple_meat}}")
80
76
  ref.length.should == 255
81
77
  ref.each{|r| r.should == 3}
82
78
  end
83
-
84
-
79
+
85
80
  specify "an erlang tuple encoded as a large tuple (4-byte length) should decode to an array" do
86
81
  tuple_meat = (['3'] * 256).join(', ')
87
82
  ref = get("{#{tuple_meat}}")
88
83
  ref.length.should == 256
89
84
  ref.each{|r| r.should == 3}
90
-
85
+
91
86
  tuple_meat = (['3'] * 512).join(', ')
92
87
  ref = get("{#{tuple_meat}}")
93
88
  ref.length.should == 512
94
89
  ref.each{|r| r.should == 3}
95
90
  end
96
-
97
-
91
+
98
92
  specify "an empty erlang list encoded as a nil should decode to an array" do
99
93
  get("[]").should == []
100
94
  end
101
-
95
+
102
96
  specify "an erlang list encoded as a string should decode to an array of bytes (less than ideal, but consistent)" do
103
97
  get("\"asdasd\"").should == "asdasd".split('').map{|c| c[0]}
104
98
  get("\"#{'a' * 65534}\"").should == ['a'[0]] * 65534
105
99
  end
106
-
100
+
107
101
  specify "an erlang list encoded as a list should decode to a array" do
108
102
  get("[3,4,256]").should == [3,4,256]
109
103
  get("\"#{'a' * 65535 }\"").should == [97] * 65535
110
104
  get("[3,4, foo, {3,4,5,bar}, 256]").should == [3,4, :foo, [3,4,5,:bar], 256]
111
105
  end
112
-
113
-
106
+
114
107
  specify "an erlang binary should decode to a string" do
115
108
  get("<< 3,4,255 >>").should == "\003\004\377"
116
109
  get("<< \"whatup\" >>").should == "whatup"
117
110
  end
118
-
111
+
112
+ specify "erlang atomic booleans should decode to ruby booleans" do
113
+ get("true").should == true
114
+ get("false").should == false
115
+ get("falsereio").should == :falsereio
116
+ end
117
+
119
118
  specify "a good thing should be awesome" do
120
119
  get(%Q-[{options,{struct,[{test,<<"I'm chargin' mah lazer">>}]}},{passage,<<"Why doesn't this work?">>}]-).should ==
121
120
  [[:options, [:struct, [[:test, "I'm chargin' mah lazer"]]]], [:passage, "Why doesn't this work?"]]
122
121
  end
123
-
122
+
124
123
  def get(str)
125
124
  x = "term_to_binary(#{str.gsub(/"/, '\\\"')})"
126
125
  bin = run_erl(x)
127
- Erlectricity::Decoder.read_any_from(bin)
126
+ Erlectricity::Decoder.decode(bin)
128
127
  end
129
128
  end
data/test/encode_spec.rb CHANGED
@@ -5,19 +5,26 @@ context "When packing to a binary stream" do
5
5
  @out = StringIO.new('', 'w')
6
6
  @encoder = Erlectricity::Encoder.new(@out)
7
7
  end
8
+
8
9
  specify "A symbol should be encoded to an erlang atom" do
9
10
  get{@encoder.write_symbol :haha}.should == get_erl("haha")
10
11
  write_any(:haha).should == get_erl_with_magic("haha")
11
12
  end
12
-
13
+
14
+ specify "A boolean should be encoded to an erlang atom" do
15
+ get{@encoder.write_boolean true}.should == get_erl("true")
16
+ get{@encoder.write_boolean false}.should == get_erl("false")
17
+ write_any(true).should == get_erl_with_magic("true")
18
+ write_any(false).should == get_erl_with_magic("false")
19
+ end
20
+
13
21
  specify "A number should be encoded as an erlang number would be" do
14
-
15
22
  #SMALL_INTS
16
23
  get{@encoder.write_fixnum 0}.should == get_erl("0")
17
24
  get{@encoder.write_fixnum 255}.should == get_erl("255")
18
25
  write_any(0).should == get_erl_with_magic("0")
19
26
  write_any(255).should == get_erl_with_magic("255")
20
-
27
+
21
28
  #INTS
22
29
  get{@encoder.write_fixnum 256}.should == get_erl("256")
23
30
  get{@encoder.write_fixnum((1 << 27) - 1)}.should == get_erl("#{(1 << 27) - 1}")
@@ -27,105 +34,105 @@ context "When packing to a binary stream" do
27
34
  write_any((1 << 27) - 1).should == get_erl_with_magic("#{(1 << 27) - 1}")
28
35
  write_any(-1).should == get_erl_with_magic("-1")
29
36
  write_any(-(1 << 27)).should == get_erl_with_magic("#{-(1 << 27)}")
30
-
37
+
31
38
  # #SMALL_BIGNUMS
32
39
  # get{@encoder.write_fixnum((1 << word_length))}.should == get_erl("#{(1 << word_length)}")
33
40
  # get{@encoder.write_fixnum(-(1 << word_length) - 1)}.should == get_erl("#{-(1 << word_length) - 1}")
34
41
  # get{@encoder.write_fixnum((1 << (255 * 8)) - 1)}.should == get_erl("#{(1 << (255 * 8)) - 1}")
35
42
  # get{@encoder.write_fixnum(-((1 << (255 * 8)) - 1))}.should == get_erl("#{-((1 << (255 * 8)) - 1)}")
36
- #
43
+ #
37
44
  # write_any((1 << word_length)).should == get_erl_with_magic("#{(1 << word_length)}")
38
45
  # write_any(-(1 << word_length) - 1).should == get_erl_with_magic("#{-(1 << word_length) - 1}")
39
46
  # write_any((1 << (255 * 8)) - 1).should == get_erl_with_magic("#{(1 << (255 * 8)) - 1}")
40
47
  # write_any(-((1 << (255 * 8)) - 1)).should == get_erl_with_magic("#{-((1 << (255 * 8)) - 1)}")
41
- #
48
+ #
42
49
  # #LARG_BIGNUMS
43
50
  # get{@encoder.write_fixnum((1 << (255 * 8)))}.should == get_erl("#{(1 << (255 * 8))}")
44
51
  # get{@encoder.write_fixnum(-(1 << (255 * 8))}.should == get_erl("#{-(1 << (255 * 8)}")
45
52
  # get{@encoder.write_fixnum((1 << (512 * 8))}.should == get_erl("#{(1 << (512 * 8))}")
46
53
  # get{@encoder.write_fixnum(-((1 << (512 * 8)) - 1))}.should == get_erl("#{-((1 << (512 * 8)) - 1)}")
47
- #
54
+ #
48
55
  # write_any((1 << (255 * 8))).should == get_erl_with_magic("#{(1 << (255 * 8))}")
49
56
  # write_any(-(1 << (255 * 8)).should == get_erl_with_magic("#{-(1 << (255 * 8)}")
50
57
  # write_any((1 << (512 * 8))).should == get_erl_with_magic("#{(1 << (512 * 8))}")
51
58
  # write_any(-((1 << (512 * 8)) - 1)).should == get_erl_with_magic("#{-((1 << (512 * 8)) - 1)}")
52
59
  end
53
-
60
+
54
61
  # specify "A float (that is within the truncated precision of ruby compared to erlang) should encode as erlang does" do
55
62
  # get{@encoder.write_float 1.0}.should == get_erl("1.0")
56
63
  # get{@encoder.write_float -1.0}.should == get_erl("-1.0")
57
64
  # get{@encoder.write_float 123.456}.should == get_erl("123.456")
58
65
  # get{@encoder.write_float 123.456789012345}.should == get_erl("123.456789012345")
59
66
  # end
60
-
67
+
61
68
  specify "An Erlectiricity::NewReference should encode back to its original form" do
62
69
  ref_bin = run_erl("term_to_binary(make_ref())")
63
- ruby_ref = Erlectricity::Decoder.read_any_from(ref_bin)
64
-
70
+ ruby_ref = Erlectricity::Decoder.decode(ref_bin)
71
+
65
72
  get{@encoder.write_new_reference(ruby_ref)}.should == ref_bin[1..-1]
66
73
  write_any(ruby_ref).should == ref_bin
67
74
  end
68
-
75
+
69
76
  specify "An Erlectiricity::Pid should encode back to its original form" do
70
77
  pid_bin = run_erl("term_to_binary(spawn(fun() -> 3 end))")
71
- ruby_pid = Erlectricity::Decoder.read_any_from(pid_bin)
72
-
78
+ ruby_pid = Erlectricity::Decoder.decode(pid_bin)
79
+
73
80
  get{@encoder.write_pid(ruby_pid)}.should == pid_bin[1..-1]
74
81
  write_any(ruby_pid).should == pid_bin
75
82
  end
76
-
83
+
77
84
  specify "An array written with write_tuple should encode as erlang would a tuple" do
78
85
  get{@encoder.write_tuple [1,2,3]}.should == get_erl("{1,2,3}")
79
86
  get{@encoder.write_tuple [3] * 255}.should == get_erl("{#{([3] * 255).join(',')}}")
80
87
  get{@encoder.write_tuple [3] * 256}.should == get_erl("{#{([3] * 256).join(',')}}")
81
88
  get{@encoder.write_tuple [3] * 512}.should == get_erl("{#{([3] * 512).join(',')}}")
82
89
  end
83
-
90
+
84
91
  specify "An array should by default be written as a tuple" do
85
92
  write_any([1,2,3]).should == get_erl_with_magic("{1,2,3}")
86
93
  write_any([3] * 255).should == get_erl_with_magic("{#{([3] * 255).join(',')}}")
87
94
  write_any([3] * 256).should == get_erl_with_magic("{#{([3] * 256).join(',')}}")
88
95
  write_any([3] * 512).should == get_erl_with_magic("{#{([3] * 512).join(',')}}")
89
96
  end
90
-
97
+
91
98
  specify "An Erlectricity::List should by default be written as a list" do
92
99
  write_any(Erl::List.new([1,2,300])).should == get_erl_with_magic("[1,2,300]")
93
100
  write_any(Erl::List.new([300] * 255)).should == get_erl_with_magic("[#{([300] * 255).join(',')}]")
94
101
  write_any(Erl::List.new([300] * 256)).should == get_erl_with_magic("[#{([300] * 256).join(',')}]")
95
102
  write_any(Erl::List.new([300] * 512)).should == get_erl_with_magic("[#{([300] * 512).join(',')}]")
96
103
  end
97
-
104
+
98
105
  specify "An array written with write_list should encode as erlang would a list" do
99
106
  get{@encoder.write_list [1,2,300]}.should == get_erl("[1,2,300]")
100
107
  get{@encoder.write_list [300] * 255}.should == get_erl("[#{([300] * 255).join(',')}]")
101
108
  get{@encoder.write_list [300] * 256}.should == get_erl("[#{([300] * 256).join(',')}]")
102
109
  get{@encoder.write_list [300] * 512}.should == get_erl("[#{([300] * 512).join(',')}]")
103
110
  end
104
-
111
+
105
112
  specify "a string should be encoded as a erlang binary would be" do
106
113
  get{@encoder.write_binary "hey who"}.should == get_erl("<< \"hey who\" >>")
107
114
  get{@encoder.write_binary ""}.should == get_erl("<< \"\" >>")
108
-
115
+
109
116
  write_any("hey who").should == get_erl_with_magic("<< \"hey who\" >>")
110
117
  write_any("").should == get_erl_with_magic("<< \"\" >>")
111
118
  end
112
-
119
+
113
120
  def get
114
121
  @encoder.out = StringIO.new('', 'w')
115
122
  yield
116
123
  @encoder.out.string
117
124
  end
118
-
125
+
119
126
  def write_any(term)
120
127
  @encoder.out = StringIO.new('', 'w')
121
128
  @encoder.write_any term
122
129
  @encoder.out.string
123
130
  end
124
-
131
+
125
132
  def get_erl(str)
126
133
  get_erl_with_magic(str)[1..-1] #[1..-1] to chop off the magic number
127
134
  end
128
-
135
+
129
136
  def get_erl_with_magic(str)
130
137
  run_erl("term_to_binary(#{str.gsub(/"/, '\\\"')})")
131
138
  end
data/test/matcher_spec.rb CHANGED
@@ -4,23 +4,37 @@ def false_match(matcher, arg)
4
4
  matcher.matches?(arg).should == false
5
5
  end
6
6
 
7
+ context "A matcher whose condition is a String (the class object" do
8
+ setup do
9
+ @matcher = Erlectricity::Matcher.new(nil, Erlectricity::TypeCondition.new(String), nil)
10
+ end
11
+
12
+ specify "should match any string" do
13
+ @matcher.matches?("foo").should == true
14
+ end
15
+
16
+ specify "should not match symbols" do
17
+ @matcher.matches?(:foo).should == false
18
+ end
19
+ end
20
+
7
21
  context "A matcher whose condition is Symbol (the class object)" do
8
22
  setup do
9
23
  @matcher = Erlectricity::Matcher.new(nil, Erlectricity::TypeCondition.new(Symbol), nil)
10
24
  end
11
-
25
+
12
26
  specify "should match any symbol" do
13
27
  @matcher.matches?(:foo).should == true
14
28
  @matcher.matches?(:bar).should == true
15
29
  @matcher.matches?(:baz).should == true
16
30
  end
17
-
31
+
18
32
  specify "should not match strings" do
19
33
  @matcher.matches?("foo").should == false
20
34
  @matcher.matches?("bar").should == false
21
35
  @matcher.matches?("baz").should == false
22
36
  end
23
-
37
+
24
38
  specify "should not match a arrays" do
25
39
  @matcher.matches?([:foo]).should == false
26
40
  @matcher.matches?([:foo, :bar]).should == false
@@ -32,11 +46,11 @@ context "a matcher whose condition is a symbol" do
32
46
  setup do
33
47
  @matcher = Erlectricity::Matcher.new(nil, Erlectricity::StaticCondition.new(:foo), nil)
34
48
  end
35
-
49
+
36
50
  specify "should match that symbol" do
37
51
  @matcher.matches?(:foo).should == true
38
52
  end
39
-
53
+
40
54
  specify "should not match any other symbol" do
41
55
  @matcher.matches?(:bar).should == false
42
56
  @matcher.matches?(:baz).should == false
@@ -44,16 +58,14 @@ context "a matcher whose condition is a symbol" do
44
58
  end
45
59
 
46
60
  context "a matcher whose matcher is an array" do
47
- setup do
48
- end
49
-
61
+
50
62
  specify "should match if all of its children match" do
51
63
  Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:speak), Erlectricity::TypeCondition.new(Object)], nil).matches?([:paste, "haha"]).should == false
52
-
64
+
53
65
  matcher = Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:foo), Erlectricity::StaticCondition.new(:bar)], nil)
54
66
  matcher.matches?([:foo, :bar]).should == true
55
67
  end
56
-
68
+
57
69
  specify "should not match any of its children dont match" do
58
70
  matcher = Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:foo), Erlectricity::StaticCondition.new(:bar)], nil)
59
71
  matcher.matches?([:foo]).should == false
@@ -61,9 +73,9 @@ context "a matcher whose matcher is an array" do
61
73
  matcher.matches?([:fooo, :barr]).should == false
62
74
  matcher.matches?([3, :bar]).should == false
63
75
  end
64
-
76
+
65
77
  specify "should not match if arg isn't an array" do
66
78
  matcher = Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:foo), Erlectricity::StaticCondition.new(:bar)], nil)
67
79
  matcher.matches?(:foo).should == false
68
80
  end
69
- end
81
+ end
data/test/port_spec.rb CHANGED
@@ -9,7 +9,7 @@ context "A port" do
9
9
  port.receive.should == :bar
10
10
  port.receive.should == nil
11
11
  end
12
-
12
+
13
13
  specify "should read_from_input if the queue gets empty" do
14
14
  port = FakePort.new(:bar)
15
15
  port.queue.clear
@@ -18,18 +18,17 @@ context "A port" do
18
18
  port.receive.should == :bar
19
19
  port.receive.should == nil
20
20
  end
21
-
21
+
22
22
  specify "should put the terms in skipped at the front of queue when restore_skipped is called" do
23
23
  port = FakePort.new(:baz)
24
24
  port.queue.clear
25
25
  port.queue << :bar
26
26
  port.skipped << :foo
27
27
  port.restore_skipped
28
-
28
+
29
29
  port.receive.should == :foo
30
30
  port.receive.should == :bar
31
31
  port.receive.should == :baz
32
32
  port.receive.should == nil
33
-
34
33
  end
35
34
  end
@@ -13,21 +13,20 @@ def simple_receiver_and_port(*terms, &block)
13
13
  end
14
14
  end
15
15
 
16
-
17
16
  context "When a receiver is passed a message that matches two match blocks it" do
18
17
  setup do
19
18
  @port = FakePort.new([:foo, :foo])
20
19
  @receiver = Erlectricity::Receiver.new(@port) do |f|
21
- f.when(:foo, :foo) do
20
+ f.when([:foo, :foo]) do
22
21
  :first
23
22
  end
24
-
25
- f.when(:foo, Erl.any) do
23
+
24
+ f.when([:foo, Erl.any]) do
26
25
  :second
27
26
  end
28
27
  end
29
28
  end
30
-
29
+
31
30
  specify "should run the first matching receiver's block" do
32
31
  @receiver.run.should == :first
33
32
  end
@@ -39,17 +38,17 @@ context "A receiver" do
39
38
  simple_receiver_and_port(:bar).run.should == :matched
40
39
  simple_receiver_and_port(:bar, :baz).run.should == :matched
41
40
  end
42
-
41
+
43
42
  specify "should process another message if the matched block returns the results of receive_loop" do
44
43
  recv = simple_receiver_and_port(:foo, :bar, :baz) do |f|
45
44
  f.when(:bar) { }
46
45
  f.when(Erl.any) { f.receive_loop }
47
46
  end
48
-
47
+
49
48
  recv.run
50
49
  recv.port.terms.should == [:baz]
51
50
  end
52
-
51
+
53
52
  specify "should properly nest" do
54
53
  @port = FakePort.new(:foo, :bar, :baz)
55
54
  @receiver = Erlectricity::Receiver.new(@port) do |f|
@@ -57,18 +56,18 @@ context "A receiver" do
57
56
  f.receive do |g|
58
57
  g.when(:bar){ :ok }
59
58
  end
60
- f.receive_loop
59
+ f.receive_loop
61
60
  end
62
-
61
+
63
62
  f.when(:baz) do
64
63
  :done
65
64
  end
66
65
  end
67
-
66
+
68
67
  @receiver.run.should == :done
69
68
  @port.terms.should == []
70
69
  end
71
-
70
+
72
71
  specify "should queue up skipped results and restore them when a match happens" do
73
72
  @port = FakePort.new(:foo, :baz, :bar)
74
73
  @receiver = Erlectricity::Receiver.new(@port) do |f|
@@ -76,30 +75,29 @@ context "A receiver" do
76
75
  f.receive do |g|
77
76
  g.when(:bar){ :ok }
78
77
  end
79
- f.receive_loop
78
+ f.receive_loop
80
79
  end
81
-
80
+
82
81
  f.when(:baz) do
83
82
  :done
84
83
  end
85
84
  end
86
-
85
+
87
86
  @receiver.run.should == :done
88
- @port.terms.should == []
87
+ @port.terms.should == []
89
88
  end
90
-
89
+
91
90
  specify "should expose bindings to the matched block" do
92
91
  @port = FakePort.new(:foo, :bar, :baz)
93
92
  results = []
94
93
  @receiver = Erlectricity::Receiver.new(@port) do |f|
95
94
  f.when(Erl.atom) do |bindinated|
96
95
  results << bindinated
97
- f.receive_loop
96
+ f.receive_loop
98
97
  end
99
98
  end
100
-
99
+
101
100
  @receiver.run.should == nil
102
101
  results.should == [:foo, :bar, :baz]
103
102
  end
104
-
105
103
  end