fastruby 0.0.3 → 0.0.4

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/lib/fastruby.rb CHANGED
@@ -21,4 +21,8 @@ along with fastruby. if not, see <http://www.gnu.org/licenses/>.
21
21
  require "fastruby/translator"
22
22
  require "fastruby/object"
23
23
  require "fastruby/exceptions"
24
+ require "fastruby/custom_require"
24
25
 
26
+ module FastRuby
27
+ VERSION = "0.0.3"
28
+ end
data/spec/base_spec.rb CHANGED
@@ -354,4 +354,41 @@ describe FastRuby, "fastruby" do
354
354
  ::A14.new.foo(55).should be == 44;
355
355
  end
356
356
 
357
+ it "should do nothing when execute fastruby with nothing" do
358
+ lambda {
359
+ fastruby ""
360
+ }.should_not raise_error
361
+ end
362
+
363
+ it "should allow basic inheritance" do
364
+ fastruby "
365
+ class J56
366
+ def foo
367
+ 43
368
+ end
369
+ end
370
+
371
+ class ::K56 < J56
372
+ end
373
+ "
374
+
375
+ ::K56.new.foo.should be == 43
376
+ end
377
+
378
+ it "should allow call to self method" do
379
+ fastruby "
380
+ class J57
381
+ def foo
382
+ 43
383
+ end
384
+ def bar
385
+ foo
386
+ end
387
+ end
388
+ "
389
+
390
+ ::J57.new.foo.should be == 43
391
+ ::J57.new.bar.should be == 43
392
+ end
393
+
357
394
  end
@@ -0,0 +1,190 @@
1
+ require "fastruby"
2
+
3
+ describe FastRuby, "fastruby" do
4
+ class ::V1
5
+ fastruby "
6
+ def foo(ary)
7
+ sum = 0
8
+ ary.each do |a|
9
+ sum = sum + a
10
+ end
11
+
12
+ sum
13
+ end
14
+ "
15
+ end
16
+
17
+ it "should execute basic test iterating an array" do
18
+ ::V1.new.foo([1,2,3]).should be == 6
19
+ end
20
+
21
+ class ::V2
22
+ fastruby "
23
+ def foo(ary)
24
+ sum = 0
25
+ ary.each do |a|
26
+ sum = sum + a
27
+ break
28
+ end
29
+
30
+ sum
31
+ end
32
+ "
33
+ end
34
+
35
+ it "should execute basic test iterating an array with a break" do
36
+ ::V2.new.foo([1,2,3]).should be == 1
37
+ end
38
+
39
+ class ::V3
40
+ fastruby "
41
+ def foo(ary)
42
+ sum = 0
43
+ ary.each do |a|
44
+ sum = sum + a
45
+ break if a == 2
46
+ end
47
+
48
+ sum
49
+ end
50
+ "
51
+ end
52
+
53
+ it "should execute basic test iterating an array with a conditional break" do
54
+ ::V3.new.foo([1,2,3]).should be == 3
55
+ end
56
+
57
+ class ::V4
58
+ fastruby "
59
+ def foo
60
+ break
61
+ end
62
+ "
63
+ end
64
+
65
+ it "should raise LocalJumpError with illegal break" do
66
+ lambda {
67
+ ::V4.new.foo
68
+ }.should raise_error(LocalJumpError)
69
+ end
70
+
71
+ class ::V5
72
+ fastruby "
73
+
74
+ def each
75
+ yield(1)
76
+ yield(2)
77
+ yield(3)
78
+ end
79
+
80
+ def foo
81
+ sum = 0
82
+ each do |a|
83
+ sum = sum + a
84
+ break if a == 2
85
+ end
86
+
87
+ sum
88
+ end
89
+ "
90
+ end
91
+
92
+ it "should execute basic test iterating an array with a conditional break (method with block on fastruby)" do
93
+ ::V5.new.foo.should be == 3
94
+ end
95
+
96
+ class ::V6
97
+ fastruby "
98
+ def foo(ary)
99
+ ary.each do |a|
100
+ break 85 if a == 2
101
+ end
102
+ end
103
+ "
104
+ end
105
+
106
+ it "should allow return value on parent method using break" do
107
+ ::V6.new.foo([1,2,3]).should be == 85
108
+ end
109
+
110
+ class ::V7
111
+
112
+ attr_reader :a
113
+
114
+ fastruby "
115
+
116
+ def each
117
+ yield(1)
118
+ yield(2)
119
+ yield(3)
120
+ ensure
121
+ @a = 87
122
+ end
123
+
124
+ def foo
125
+ each do |a|
126
+ break if a == 2
127
+ end
128
+ end
129
+ "
130
+ end
131
+
132
+ it "should execute ensure on parent frame when using break" do
133
+ x = ::V7.new
134
+
135
+ x.foo
136
+ x.a.should be == 87
137
+ end
138
+
139
+
140
+ class ::V8
141
+
142
+ attr_reader :a
143
+
144
+ def each
145
+ yield(1)
146
+ yield(2)
147
+ yield(3)
148
+ ensure
149
+ @a = 87
150
+ end
151
+
152
+ fastruby "
153
+
154
+ def foo
155
+ each do |x|
156
+ break if x == 2
157
+ end
158
+ end
159
+ "
160
+ end
161
+
162
+ it "should execute ensure on parent frame when using break (and called method is ruby)" do
163
+ x = ::V8.new
164
+
165
+ x.foo
166
+ x.a.should be == 87
167
+ end
168
+
169
+ class ::V9
170
+ fastruby "
171
+ def each
172
+ yield(1)
173
+ yield(2)
174
+ yield(3)
175
+ end
176
+
177
+ def foo
178
+ each do |a|
179
+ break 85
180
+ end
181
+ end
182
+ "
183
+ end
184
+
185
+ it "should allow return value on parent method using break when called method is fastruby" do
186
+ ::V9.new.foo.should be == 85
187
+ end
188
+
189
+
190
+ end
@@ -0,0 +1,85 @@
1
+ require "fastruby"
2
+
3
+ describe FastRuby, "fastruby" do
4
+ class ::W1
5
+ fastruby "
6
+ def foo(ary)
7
+ sum = 0
8
+ ary.each do |a|
9
+ next if a == 2
10
+ sum = sum + a
11
+ end
12
+
13
+ sum
14
+ end
15
+ "
16
+ end
17
+
18
+ it "should execute basic test iterating an array" do
19
+ ::W1.new.foo([1,2,3]).should be == 4
20
+ end
21
+
22
+ class ::W2
23
+ fastruby "
24
+ def foo
25
+ next
26
+ end
27
+ "
28
+ end
29
+
30
+ it "should raise LocalJumpError with illegal next" do
31
+ lambda {
32
+ ::W2.new.foo
33
+ }.should raise_error(LocalJumpError)
34
+ end
35
+
36
+ class ::W3
37
+ attr_reader :x, :y
38
+
39
+ fastruby "
40
+ def bar
41
+ @x = yield(1)
42
+ @y = yield(2)
43
+ end
44
+
45
+ def foo
46
+ bar do |a|
47
+ next 16 if a == 1
48
+ next 32 if a == 2
49
+ end
50
+ end
51
+ "
52
+ end
53
+
54
+ it "should return values on block using next" do
55
+ x = ::W3.new
56
+ x.foo
57
+ x.x.should be == 16
58
+ x.y.should be == 32
59
+ end
60
+
61
+ class ::W4
62
+ attr_reader :x, :y
63
+
64
+ fastruby "
65
+ def foo(ary)
66
+ sum = 0
67
+ ary.each do |a|
68
+ begin
69
+ next if a == 2
70
+ ensure
71
+ sum = sum + a
72
+ end
73
+ end
74
+
75
+ sum
76
+ end
77
+ "
78
+ end
79
+
80
+ it "should execute ensure when using next" do
81
+ x = ::W4.new
82
+ x.foo([1,2,3]).should be == 6
83
+ end
84
+
85
+ end