erlectricity-funbox 1.1.2
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.
- data/.gitignore +24 -0
- data/History.txt +35 -0
- data/LICENSE +20 -0
- data/README.md +130 -0
- data/Rakefile +74 -0
- data/VERSION.yml +4 -0
- data/benchmarks/bench.rb +21 -0
- data/erlectricity.gemspec +105 -0
- data/examples/echo/README.md +12 -0
- data/examples/echo/echo.erl +13 -0
- data/examples/echo/echo.rb +11 -0
- data/examples/gruff/gruff.erl +61 -0
- data/examples/gruff/gruff_provider.rb +31 -0
- data/examples/gruff/gruff_run.sh +19 -0
- data/examples/gruff/stat_run.sh +20 -0
- data/examples/gruff/stat_writer.erl +40 -0
- data/examples/simple/README.md +5 -0
- data/examples/simple/rerl.rb +111 -0
- data/examples/simple/rerl.sh +37 -0
- data/examples/tinderl/README.md +14 -0
- data/examples/tinderl/tinderl.erl +43 -0
- data/examples/tinderl/tinderl.rb +28 -0
- data/ext/decoder.c +398 -0
- data/ext/extconf.rb +11 -0
- data/lib/erlectricity.rb +33 -0
- data/lib/erlectricity/condition.rb +66 -0
- data/lib/erlectricity/conditions/boolean.rb +11 -0
- data/lib/erlectricity/conditions/hash.rb +13 -0
- data/lib/erlectricity/conditions/static.rb +34 -0
- data/lib/erlectricity/conditions/type.rb +17 -0
- data/lib/erlectricity/constants.rb +36 -0
- data/lib/erlectricity/decoder.rb +212 -0
- data/lib/erlectricity/encoder.rb +164 -0
- data/lib/erlectricity/errors/decode_error.rb +3 -0
- data/lib/erlectricity/errors/encode_error.rb +3 -0
- data/lib/erlectricity/errors/erlectricity_error.rb +3 -0
- data/lib/erlectricity/matcher.rb +21 -0
- data/lib/erlectricity/port.rb +46 -0
- data/lib/erlectricity/receiver.rb +69 -0
- data/lib/erlectricity/types/function.rb +3 -0
- data/lib/erlectricity/types/list.rb +3 -0
- data/lib/erlectricity/types/new_function.rb +3 -0
- data/lib/erlectricity/types/new_reference.rb +3 -0
- data/lib/erlectricity/types/pid.rb +3 -0
- data/lib/erlectricity/types/reference.rb +3 -0
- data/lib/erlectricity/version.rb +9 -0
- data/test/condition_spec.rb +72 -0
- data/test/decode_spec.rb +145 -0
- data/test/encode_spec.rb +146 -0
- data/test/matcher_spec.rb +81 -0
- data/test/port_spec.rb +34 -0
- data/test/receiver_spec.rb +103 -0
- data/test/spec_suite.rb +2 -0
- data/test/test_helper.rb +46 -0
- metadata +116 -0
data/test/encode_spec.rb
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
|
|
3
|
+
context "When packing to a binary stream" do
|
|
4
|
+
setup do
|
|
5
|
+
@out = StringIO.new('', 'w')
|
|
6
|
+
@encoder = Erlectricity::Encoder.new(@out)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
specify "A symbol should be encoded to an erlang atom" do
|
|
10
|
+
get{@encoder.write_symbol :haha}.should == get_erl("haha")
|
|
11
|
+
write_any(:haha).should == get_erl_with_magic("haha")
|
|
12
|
+
end
|
|
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
|
+
|
|
21
|
+
specify "A number should be encoded as an erlang number would be" do
|
|
22
|
+
#SMALL_INTS
|
|
23
|
+
get{@encoder.write_fixnum 0}.should == get_erl("0")
|
|
24
|
+
get{@encoder.write_fixnum 255}.should == get_erl("255")
|
|
25
|
+
write_any(0).should == get_erl_with_magic("0")
|
|
26
|
+
write_any(255).should == get_erl_with_magic("255")
|
|
27
|
+
|
|
28
|
+
#INTS
|
|
29
|
+
get{@encoder.write_fixnum 256}.should == get_erl("256")
|
|
30
|
+
get{@encoder.write_fixnum((1 << 27) - 1)}.should == get_erl("#{(1 << 27) - 1}")
|
|
31
|
+
get{@encoder.write_fixnum(-1)}.should == get_erl("-1")
|
|
32
|
+
get{@encoder.write_fixnum(-(1 << 27))}.should == get_erl("#{-(1 << 27)}")
|
|
33
|
+
write_any(256).should == get_erl_with_magic("256")
|
|
34
|
+
write_any((1 << 27) - 1).should == get_erl_with_magic("#{(1 << 27) - 1}")
|
|
35
|
+
write_any(-1).should == get_erl_with_magic("-1")
|
|
36
|
+
write_any(-(1 << 27)).should == get_erl_with_magic("#{-(1 << 27)}")
|
|
37
|
+
|
|
38
|
+
# #SMALL_BIGNUMS
|
|
39
|
+
get{@encoder.write_fixnum(10_000_000_000_000_000_000)}.should == get_erl("10000000000000000000")
|
|
40
|
+
get{@encoder.write_fixnum(1254976067)}.should == get_erl("1254976067")
|
|
41
|
+
get{@encoder.write_fixnum(-1254976067)}.should == get_erl("-1254976067")
|
|
42
|
+
# get{@encoder.write_fixnum((1 << word_length))}.should == get_erl("#{(1 << word_length)}")
|
|
43
|
+
# get{@encoder.write_fixnum(-(1 << word_length) - 1)}.should == get_erl("#{-(1 << word_length) - 1}")
|
|
44
|
+
# get{@encoder.write_fixnum((1 << (255 * 8)) - 1)}.should == get_erl("#{(1 << (255 * 8)) - 1}")
|
|
45
|
+
# get{@encoder.write_fixnum(-((1 << (255 * 8)) - 1))}.should == get_erl("#{-((1 << (255 * 8)) - 1)}")
|
|
46
|
+
#
|
|
47
|
+
# write_any((1 << word_length)).should == get_erl_with_magic("#{(1 << word_length)}")
|
|
48
|
+
# write_any(-(1 << word_length) - 1).should == get_erl_with_magic("#{-(1 << word_length) - 1}")
|
|
49
|
+
# write_any((1 << (255 * 8)) - 1).should == get_erl_with_magic("#{(1 << (255 * 8)) - 1}")
|
|
50
|
+
# write_any(-((1 << (255 * 8)) - 1)).should == get_erl_with_magic("#{-((1 << (255 * 8)) - 1)}")
|
|
51
|
+
#
|
|
52
|
+
# #LARGE_BIGNUMS
|
|
53
|
+
x = 1254976067 ** 256
|
|
54
|
+
get{@encoder.write_fixnum(x)}.should == get_erl("#{x}")
|
|
55
|
+
get{@encoder.write_fixnum(-x)}.should == get_erl("-#{x}")
|
|
56
|
+
# get{@encoder.write_fixnum((1 << (255 * 8)))}.should == get_erl("#{(1 << (255 * 8))}")
|
|
57
|
+
# get{@encoder.write_fixnum(-(1 << (255 * 8))}.should == get_erl("#{-(1 << (255 * 8)}")
|
|
58
|
+
# get{@encoder.write_fixnum((1 << (512 * 8))}.should == get_erl("#{(1 << (512 * 8))}")
|
|
59
|
+
# get{@encoder.write_fixnum(-((1 << (512 * 8)) - 1))}.should == get_erl("#{-((1 << (512 * 8)) - 1)}")
|
|
60
|
+
#
|
|
61
|
+
# write_any((1 << (255 * 8))).should == get_erl_with_magic("#{(1 << (255 * 8))}")
|
|
62
|
+
# write_any(-(1 << (255 * 8)).should == get_erl_with_magic("#{-(1 << (255 * 8)}")
|
|
63
|
+
# write_any((1 << (512 * 8))).should == get_erl_with_magic("#{(1 << (512 * 8))}")
|
|
64
|
+
# write_any(-((1 << (512 * 8)) - 1)).should == get_erl_with_magic("#{-((1 << (512 * 8)) - 1)}")
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# specify "A float (that is within the truncated precision of ruby compared to erlang) should encode as erlang does" do
|
|
68
|
+
# get{@encoder.write_float 1.0}.should == get_erl("1.0")
|
|
69
|
+
# get{@encoder.write_float -1.0}.should == get_erl("-1.0")
|
|
70
|
+
# get{@encoder.write_float 123.456}.should == get_erl("123.456")
|
|
71
|
+
# get{@encoder.write_float 123.456789012345}.should == get_erl("123.456789012345")
|
|
72
|
+
# end
|
|
73
|
+
|
|
74
|
+
specify "An Erlectiricity::NewReference should encode back to its original form" do
|
|
75
|
+
ref_bin = run_erl("term_to_binary(make_ref())")
|
|
76
|
+
ruby_ref = Erlectricity::Decoder.decode(ref_bin)
|
|
77
|
+
|
|
78
|
+
get{@encoder.write_new_reference(ruby_ref)}.should == ref_bin[1..-1]
|
|
79
|
+
write_any(ruby_ref).should == ref_bin
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
specify "An Erlectiricity::Pid should encode back to its original form" do
|
|
83
|
+
pid_bin = run_erl("term_to_binary(spawn(fun() -> 3 end))")
|
|
84
|
+
ruby_pid = Erlectricity::Decoder.decode(pid_bin)
|
|
85
|
+
|
|
86
|
+
get{@encoder.write_pid(ruby_pid)}.should == pid_bin[1..-1]
|
|
87
|
+
write_any(ruby_pid).should == pid_bin
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
specify "An array written with write_tuple should encode as erlang would a tuple" do
|
|
91
|
+
get{@encoder.write_tuple [1,2,3]}.should == get_erl("{1,2,3}")
|
|
92
|
+
get{@encoder.write_tuple [3] * 255}.should == get_erl("{#{([3] * 255).join(',')}}")
|
|
93
|
+
get{@encoder.write_tuple [3] * 256}.should == get_erl("{#{([3] * 256).join(',')}}")
|
|
94
|
+
get{@encoder.write_tuple [3] * 512}.should == get_erl("{#{([3] * 512).join(',')}}")
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
specify "An array should by default be written as a tuple" do
|
|
98
|
+
write_any([1,2,3]).should == get_erl_with_magic("{1,2,3}")
|
|
99
|
+
write_any([3] * 255).should == get_erl_with_magic("{#{([3] * 255).join(',')}}")
|
|
100
|
+
write_any([3] * 256).should == get_erl_with_magic("{#{([3] * 256).join(',')}}")
|
|
101
|
+
write_any([3] * 512).should == get_erl_with_magic("{#{([3] * 512).join(',')}}")
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
specify "An Erlectricity::List should by default be written as a list" do
|
|
105
|
+
write_any(Erl::List.new([1,2,300])).should == get_erl_with_magic("[1,2,300]")
|
|
106
|
+
write_any(Erl::List.new([300] * 255)).should == get_erl_with_magic("[#{([300] * 255).join(',')}]")
|
|
107
|
+
write_any(Erl::List.new([300] * 256)).should == get_erl_with_magic("[#{([300] * 256).join(',')}]")
|
|
108
|
+
write_any(Erl::List.new([300] * 512)).should == get_erl_with_magic("[#{([300] * 512).join(',')}]")
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
specify "An array written with write_list should encode as erlang would a list" do
|
|
112
|
+
get{@encoder.write_list [1,2,300]}.should == get_erl("[1,2,300]")
|
|
113
|
+
get{@encoder.write_list [300] * 255}.should == get_erl("[#{([300] * 255).join(',')}]")
|
|
114
|
+
get{@encoder.write_list [300] * 256}.should == get_erl("[#{([300] * 256).join(',')}]")
|
|
115
|
+
get{@encoder.write_list [300] * 512}.should == get_erl("[#{([300] * 512).join(',')}]")
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
specify "a string should be encoded as a erlang binary would be" do
|
|
119
|
+
get{@encoder.write_binary "hey who"}.should == get_erl("<< \"hey who\" >>")
|
|
120
|
+
get{@encoder.write_binary ""}.should == get_erl("<< \"\" >>")
|
|
121
|
+
get{@encoder.write_binary "c\000c"}.should == get_erl("<< 99,0,99 >>")
|
|
122
|
+
|
|
123
|
+
write_any("hey who").should == get_erl_with_magic("<< \"hey who\" >>")
|
|
124
|
+
write_any("").should == get_erl_with_magic("<< \"\" >>")
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def get
|
|
128
|
+
@encoder.out = StringIO.new('', 'w')
|
|
129
|
+
yield
|
|
130
|
+
@encoder.out.string
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def write_any(term)
|
|
134
|
+
@encoder.out = StringIO.new('', 'w')
|
|
135
|
+
@encoder.write_any term
|
|
136
|
+
@encoder.out.string
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def get_erl(str)
|
|
140
|
+
get_erl_with_magic(str)[1..-1] #[1..-1] to chop off the magic number
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def get_erl_with_magic(str)
|
|
144
|
+
run_erl("term_to_binary(#{str.gsub(/"/, '\\\"')})")
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
|
|
3
|
+
def false_match(matcher, arg)
|
|
4
|
+
matcher.matches?(arg).should == false
|
|
5
|
+
end
|
|
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
|
+
|
|
21
|
+
context "A matcher whose condition is Symbol (the class object)" do
|
|
22
|
+
setup do
|
|
23
|
+
@matcher = Erlectricity::Matcher.new(nil, Erlectricity::TypeCondition.new(Symbol), nil)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
specify "should match any symbol" do
|
|
27
|
+
@matcher.matches?(:foo).should == true
|
|
28
|
+
@matcher.matches?(:bar).should == true
|
|
29
|
+
@matcher.matches?(:baz).should == true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
specify "should not match strings" do
|
|
33
|
+
@matcher.matches?("foo").should == false
|
|
34
|
+
@matcher.matches?("bar").should == false
|
|
35
|
+
@matcher.matches?("baz").should == false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
specify "should not match a arrays" do
|
|
39
|
+
@matcher.matches?([:foo]).should == false
|
|
40
|
+
@matcher.matches?([:foo, :bar]).should == false
|
|
41
|
+
@matcher.matches?([:foo, :bar, :baz]).should == false
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "a matcher whose condition is a symbol" do
|
|
46
|
+
setup do
|
|
47
|
+
@matcher = Erlectricity::Matcher.new(nil, Erlectricity::StaticCondition.new(:foo), nil)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
specify "should match that symbol" do
|
|
51
|
+
@matcher.matches?(:foo).should == true
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
specify "should not match any other symbol" do
|
|
55
|
+
@matcher.matches?(:bar).should == false
|
|
56
|
+
@matcher.matches?(:baz).should == false
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
context "a matcher whose matcher is an array" do
|
|
61
|
+
|
|
62
|
+
specify "should match if all of its children match" do
|
|
63
|
+
Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:speak), Erlectricity::TypeCondition.new(Object)], nil).matches?([:paste, "haha"]).should == false
|
|
64
|
+
|
|
65
|
+
matcher = Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:foo), Erlectricity::StaticCondition.new(:bar)], nil)
|
|
66
|
+
matcher.matches?([:foo, :bar]).should == true
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
specify "should not match any of its children dont match" do
|
|
70
|
+
matcher = Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:foo), Erlectricity::StaticCondition.new(:bar)], nil)
|
|
71
|
+
matcher.matches?([:foo]).should == false
|
|
72
|
+
matcher.matches?([:foo, :bar, :baz]).should == false
|
|
73
|
+
matcher.matches?([:fooo, :barr]).should == false
|
|
74
|
+
matcher.matches?([3, :bar]).should == false
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
specify "should not match if arg isn't an array" do
|
|
78
|
+
matcher = Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:foo), Erlectricity::StaticCondition.new(:bar)], nil)
|
|
79
|
+
matcher.matches?(:foo).should == false
|
|
80
|
+
end
|
|
81
|
+
end
|
data/test/port_spec.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
|
|
3
|
+
context "A port" do
|
|
4
|
+
specify "should return terms from the queue if it is not empty" do
|
|
5
|
+
port = FakePort.new()
|
|
6
|
+
port.queue.clear
|
|
7
|
+
port.queue << :foo << :bar
|
|
8
|
+
port.receive.should == :foo
|
|
9
|
+
port.receive.should == :bar
|
|
10
|
+
port.receive.should == nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
specify "should read_from_input if the queue gets empty" do
|
|
14
|
+
port = FakePort.new(:bar)
|
|
15
|
+
port.queue.clear
|
|
16
|
+
port.queue << :foo
|
|
17
|
+
port.receive.should == :foo
|
|
18
|
+
port.receive.should == :bar
|
|
19
|
+
port.receive.should == nil
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
specify "should put the terms in skipped at the front of queue when restore_skipped is called" do
|
|
23
|
+
port = FakePort.new(:baz)
|
|
24
|
+
port.queue.clear
|
|
25
|
+
port.queue << :bar
|
|
26
|
+
port.skipped << :foo
|
|
27
|
+
port.restore_skipped
|
|
28
|
+
|
|
29
|
+
port.receive.should == :foo
|
|
30
|
+
port.receive.should == :bar
|
|
31
|
+
port.receive.should == :baz
|
|
32
|
+
port.receive.should == nil
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
|
|
3
|
+
def simple_receiver_and_port(*terms, &block)
|
|
4
|
+
port = FakePort.new(*terms)
|
|
5
|
+
receiver = if block
|
|
6
|
+
Erlectricity::Receiver.new(port, &block)
|
|
7
|
+
else
|
|
8
|
+
Erlectricity::Receiver.new(port) do |f|
|
|
9
|
+
f.when Erl.any do
|
|
10
|
+
:matched
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context "When a receiver is passed a message that matches two match blocks it" do
|
|
17
|
+
setup do
|
|
18
|
+
@port = FakePort.new([:foo, :foo])
|
|
19
|
+
@receiver = Erlectricity::Receiver.new(@port) do |f|
|
|
20
|
+
f.when([:foo, :foo]) do
|
|
21
|
+
:first
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
f.when([:foo, Erl.any]) do
|
|
25
|
+
:second
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
specify "should run the first matching receiver's block" do
|
|
31
|
+
@receiver.run.should == :first
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context "A receiver" do
|
|
36
|
+
specify "should return the result of the match block when finished" do
|
|
37
|
+
simple_receiver_and_port(:foo).run.should == :matched
|
|
38
|
+
simple_receiver_and_port(:bar).run.should == :matched
|
|
39
|
+
simple_receiver_and_port(:bar, :baz).run.should == :matched
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
specify "should process another message if the matched block returns the results of receive_loop" do
|
|
43
|
+
recv = simple_receiver_and_port(:foo, :bar, :baz) do |f|
|
|
44
|
+
f.when(:bar) { }
|
|
45
|
+
f.when(Erl.any) { f.receive_loop }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
recv.run
|
|
49
|
+
recv.port.terms.should == [:baz]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
specify "should properly nest" do
|
|
53
|
+
@port = FakePort.new(:foo, :bar, :baz)
|
|
54
|
+
@receiver = Erlectricity::Receiver.new(@port) do |f|
|
|
55
|
+
f.when(:foo) do
|
|
56
|
+
f.receive do |g|
|
|
57
|
+
g.when(:bar){ :ok }
|
|
58
|
+
end
|
|
59
|
+
f.receive_loop
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
f.when(:baz) do
|
|
63
|
+
:done
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
@receiver.run.should == :done
|
|
68
|
+
@port.terms.should == []
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
specify "should queue up skipped results and restore them when a match happens" do
|
|
72
|
+
@port = FakePort.new(:foo, :baz, :bar)
|
|
73
|
+
@receiver = Erlectricity::Receiver.new(@port) do |f|
|
|
74
|
+
f.when(:foo) do
|
|
75
|
+
f.receive do |g|
|
|
76
|
+
g.when(:bar){ :ok }
|
|
77
|
+
end
|
|
78
|
+
f.receive_loop
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
f.when(:baz) do
|
|
82
|
+
:done
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
@receiver.run.should == :done
|
|
87
|
+
@port.terms.should == []
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
specify "should expose bindings to the matched block" do
|
|
91
|
+
@port = FakePort.new(:foo, :bar, :baz)
|
|
92
|
+
results = []
|
|
93
|
+
@receiver = Erlectricity::Receiver.new(@port) do |f|
|
|
94
|
+
f.when(Erl.atom) do |bindinated|
|
|
95
|
+
results << bindinated
|
|
96
|
+
f.receive_loop
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
@receiver.run.should == nil
|
|
101
|
+
results.should == [:foo, :bar, :baz]
|
|
102
|
+
end
|
|
103
|
+
end
|
data/test/spec_suite.rb
ADDED
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
2
|
+
|
|
3
|
+
require 'erlectricity'
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
require 'test/unit'
|
|
6
|
+
require 'test/spec'
|
|
7
|
+
require 'stringio'
|
|
8
|
+
|
|
9
|
+
$stdout.sync = true
|
|
10
|
+
|
|
11
|
+
class Test::Unit::TestCase
|
|
12
|
+
def run_erl(code)
|
|
13
|
+
cmd = %Q{erl -noshell -eval "A = #{code.split.join(' ')}, io:put_chars(binary_to_list(A))." -s erlang halt}
|
|
14
|
+
`#{cmd}`
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def encode_packet(code)
|
|
18
|
+
bin = run_erl("term_to_binary(#{code})")
|
|
19
|
+
[bin.length, bin].pack("Na#{bin.length}")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def word_length
|
|
23
|
+
(1.size * 8) - 2
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class FakePort < Erlectricity::Port
|
|
28
|
+
attr_reader :sent
|
|
29
|
+
attr_reader :terms
|
|
30
|
+
|
|
31
|
+
def initialize(*terms)
|
|
32
|
+
@terms = terms
|
|
33
|
+
@sent = []
|
|
34
|
+
super(StringIO.new(""), StringIO.new(""))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def send(term)
|
|
38
|
+
sent << term
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def read_from_input
|
|
44
|
+
@terms.shift
|
|
45
|
+
end
|
|
46
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: erlectricity-funbox
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.2
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Scott Fleckenstein
|
|
9
|
+
- Tom Preston-Werner
|
|
10
|
+
autorequire:
|
|
11
|
+
bindir: bin
|
|
12
|
+
cert_chain: []
|
|
13
|
+
date: 2009-10-28 00:00:00.000000000 Z
|
|
14
|
+
dependencies: []
|
|
15
|
+
description:
|
|
16
|
+
email: tom@mojombo.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions:
|
|
19
|
+
- ext/extconf.rb
|
|
20
|
+
extra_rdoc_files:
|
|
21
|
+
- LICENSE
|
|
22
|
+
- README.md
|
|
23
|
+
files:
|
|
24
|
+
- .gitignore
|
|
25
|
+
- History.txt
|
|
26
|
+
- LICENSE
|
|
27
|
+
- README.md
|
|
28
|
+
- Rakefile
|
|
29
|
+
- VERSION.yml
|
|
30
|
+
- benchmarks/bench.rb
|
|
31
|
+
- erlectricity.gemspec
|
|
32
|
+
- examples/echo/README.md
|
|
33
|
+
- examples/echo/echo.erl
|
|
34
|
+
- examples/echo/echo.rb
|
|
35
|
+
- examples/gruff/gruff.erl
|
|
36
|
+
- examples/gruff/gruff_provider.rb
|
|
37
|
+
- examples/gruff/gruff_run.sh
|
|
38
|
+
- examples/gruff/stat_run.sh
|
|
39
|
+
- examples/gruff/stat_writer.erl
|
|
40
|
+
- examples/simple/README.md
|
|
41
|
+
- examples/simple/rerl.rb
|
|
42
|
+
- examples/simple/rerl.sh
|
|
43
|
+
- examples/tinderl/README.md
|
|
44
|
+
- examples/tinderl/tinderl.erl
|
|
45
|
+
- examples/tinderl/tinderl.rb
|
|
46
|
+
- ext/decoder.c
|
|
47
|
+
- ext/extconf.rb
|
|
48
|
+
- lib/erlectricity.rb
|
|
49
|
+
- lib/erlectricity/condition.rb
|
|
50
|
+
- lib/erlectricity/conditions/boolean.rb
|
|
51
|
+
- lib/erlectricity/conditions/hash.rb
|
|
52
|
+
- lib/erlectricity/conditions/static.rb
|
|
53
|
+
- lib/erlectricity/conditions/type.rb
|
|
54
|
+
- lib/erlectricity/constants.rb
|
|
55
|
+
- lib/erlectricity/decoder.rb
|
|
56
|
+
- lib/erlectricity/encoder.rb
|
|
57
|
+
- lib/erlectricity/errors/decode_error.rb
|
|
58
|
+
- lib/erlectricity/errors/encode_error.rb
|
|
59
|
+
- lib/erlectricity/errors/erlectricity_error.rb
|
|
60
|
+
- lib/erlectricity/matcher.rb
|
|
61
|
+
- lib/erlectricity/port.rb
|
|
62
|
+
- lib/erlectricity/receiver.rb
|
|
63
|
+
- lib/erlectricity/types/function.rb
|
|
64
|
+
- lib/erlectricity/types/list.rb
|
|
65
|
+
- lib/erlectricity/types/new_function.rb
|
|
66
|
+
- lib/erlectricity/types/new_reference.rb
|
|
67
|
+
- lib/erlectricity/types/pid.rb
|
|
68
|
+
- lib/erlectricity/types/reference.rb
|
|
69
|
+
- lib/erlectricity/version.rb
|
|
70
|
+
- test/condition_spec.rb
|
|
71
|
+
- test/decode_spec.rb
|
|
72
|
+
- test/encode_spec.rb
|
|
73
|
+
- test/matcher_spec.rb
|
|
74
|
+
- test/port_spec.rb
|
|
75
|
+
- test/receiver_spec.rb
|
|
76
|
+
- test/spec_suite.rb
|
|
77
|
+
- test/test_helper.rb
|
|
78
|
+
homepage: http://github.com/mojombo/erlectricity
|
|
79
|
+
licenses: []
|
|
80
|
+
post_install_message:
|
|
81
|
+
rdoc_options:
|
|
82
|
+
- --charset=UTF-8
|
|
83
|
+
require_paths:
|
|
84
|
+
- lib
|
|
85
|
+
- ext
|
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
|
+
none: false
|
|
88
|
+
requirements:
|
|
89
|
+
- - ! '>='
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
version: '0'
|
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
|
+
none: false
|
|
94
|
+
requirements:
|
|
95
|
+
- - ! '>='
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: '0'
|
|
98
|
+
requirements: []
|
|
99
|
+
rubyforge_project: erlectricity
|
|
100
|
+
rubygems_version: 1.8.23
|
|
101
|
+
signing_key:
|
|
102
|
+
specification_version: 3
|
|
103
|
+
summary: A library to interface erlang and ruby through the erlang port system
|
|
104
|
+
test_files:
|
|
105
|
+
- test/condition_spec.rb
|
|
106
|
+
- test/decode_spec.rb
|
|
107
|
+
- test/encode_spec.rb
|
|
108
|
+
- test/matcher_spec.rb
|
|
109
|
+
- test/port_spec.rb
|
|
110
|
+
- test/receiver_spec.rb
|
|
111
|
+
- test/spec_suite.rb
|
|
112
|
+
- test/test_helper.rb
|
|
113
|
+
- examples/echo/echo.rb
|
|
114
|
+
- examples/gruff/gruff_provider.rb
|
|
115
|
+
- examples/simple/rerl.rb
|
|
116
|
+
- examples/tinderl/tinderl.rb
|