fastruby 0.0.21 → 0.0.22
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/Rakefile +1 -1
- data/benchmarks/benchmark.rb +3 -0
- data/benchmarks/benchmark.rb~ +3 -12
- data/benchmarks/benchmark8.rb +48 -0
- data/benchmarks/benchmark8.rb~ +46 -0
- data/lib/fastruby.rb +2 -1
- data/lib/fastruby.rb~ +2 -1
- data/lib/fastruby/builder.rb +18 -1
- data/lib/fastruby/builder.rb~ +18 -5
- data/lib/fastruby/modules/lvar_type/lasgn.rb~ +41 -0
- data/lib/fastruby/modules/translator/block.rb +1 -1
- data/lib/fastruby/modules/translator/block.rb~ +128 -0
- data/lib/fastruby/modules/translator/call.rb +62 -139
- data/lib/fastruby/modules/translator/call.rb~ +61 -140
- data/lib/fastruby/modules/translator/defn.rb +49 -105
- data/lib/fastruby/modules/translator/defn.rb~ +211 -0
- data/lib/fastruby/modules/translator/exceptions.rb +1 -0
- data/lib/fastruby/modules/translator/exceptions.rb~ +120 -0
- data/lib/fastruby/modules/translator/iter.rb +13 -20
- data/lib/fastruby/modules/translator/iter.rb~ +738 -0
- data/lib/fastruby/modules/translator/literal.rb +8 -1
- data/lib/fastruby/modules/translator/literal.rb~ +157 -0
- data/lib/fastruby/modules/translator/nonlocal.rb +7 -0
- data/lib/fastruby/modules/translator/nonlocal.rb~ +304 -0
- data/lib/fastruby/modules/translator/static.rb +1 -0
- data/lib/fastruby/modules/translator/static.rb~ +290 -0
- data/lib/fastruby/modules/translator/variable.rb +24 -6
- data/lib/fastruby/modules/translator/variable.rb~ +298 -0
- data/lib/fastruby/translator/translator.rb +411 -284
- data/lib/fastruby/translator/translator.rb~ +1728 -0
- data/spec/fastruby_only/base_spec.rb~ +74 -0
- data/spec/ruby/base_spec.rb~ +1 -338
- data/spec/ruby/block/break_spec.rb~ +21 -0
- data/spec/ruby/block/callcc_spec.rb~ +236 -0
- data/spec/ruby/block/lambda_spec.rb~ +1 -178
- data/spec/ruby/block/next_spec.rb~ +85 -0
- data/spec/ruby/block/proc_spec.rb~ +22 -0
- data/spec/ruby/block/redo_spec.rb~ +133 -0
- data/spec/ruby/block/retry_spec.rb~ +135 -0
- data/spec/ruby/block_spec.rb~ +494 -2
- data/spec/ruby/call/base_call_spec.rb~ +60 -2
- data/spec/ruby/defn/default_args_spec.rb~ +303 -0
- data/spec/ruby/defn/multiple_args_spec.rb~ +317 -0
- data/spec/ruby/defn/replacement_spec.rb +29 -1
- data/spec/ruby/defn/replacement_spec.rb~ +52 -21
- data/spec/ruby/exception/internal_ex_spec.rb~ +2 -2
- data/spec/ruby/variable_spec.rb~ +46 -23
- data/spec/static/flow_spec.rb~ +48 -0
- metadata +34 -12
@@ -1,7 +1,36 @@
|
|
1
1
|
require "fastruby"
|
2
2
|
|
3
3
|
describe FastRuby, "fastruby" do
|
4
|
-
|
4
|
+
def self.test_arguments(x)
|
5
|
+
it "should allow #{x} arguments calling to cfunc" do
|
6
|
+
|
7
|
+
arguments = (0..x).map(&:to_s).join(",")
|
8
|
+
|
9
|
+
fastruby "
|
10
|
+
class ::CYR#{x}
|
11
|
+
def foo
|
12
|
+
a = []
|
13
|
+
a.infer(Array).push(#{arguments})
|
14
|
+
a
|
15
|
+
end
|
16
|
+
end
|
17
|
+
"
|
18
|
+
|
19
|
+
eval("::CYR#{x}").new.foo.should be == eval("[#{arguments}]")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
#test_arguments(10)
|
24
|
+
#test_arguments(15)
|
25
|
+
#test_arguments(20)
|
26
|
+
|
27
|
+
(23..27).each do |i|
|
28
|
+
# test_arguments(i)
|
29
|
+
end
|
30
|
+
|
31
|
+
#test_arguments(20)
|
32
|
+
|
33
|
+
|
5
34
|
def self.test_fastruby_arguments(argnum)
|
6
35
|
it "should allow #{argnum} arguments calling fastruby" do
|
7
36
|
|
@@ -21,5 +50,34 @@ describe FastRuby, "fastruby" do
|
|
21
50
|
eval("::CYR1_#{argnum}").new.foo(*array).should be == array
|
22
51
|
end
|
23
52
|
end
|
24
|
-
|
53
|
+
|
54
|
+
#(8..12).each do |i|
|
55
|
+
# test_fastruby_arguments(i)
|
56
|
+
#end
|
57
|
+
|
58
|
+
def self.test_invalid_fastruby_arguments(argnum)
|
59
|
+
it "should allow #{argnum} arguments calling fastruby" do
|
60
|
+
|
61
|
+
arguments_name = (0..argnum-1).map{|x| "a"+x.to_s}.join(",")
|
62
|
+
arguments = (0..argnum-1).map(&:to_s).join(",")
|
63
|
+
|
64
|
+
fastruby "
|
65
|
+
class ::CYR1_#{argnum}
|
66
|
+
def foo(#{arguments_name})
|
67
|
+
[#{arguments_name}]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
"
|
71
|
+
|
72
|
+
array = eval("[#{arguments}]")
|
73
|
+
|
74
|
+
lambda {
|
75
|
+
eval("::CYR1_#{argnum}").new.foo(*array).should be == array
|
76
|
+
}.should raise_error(ArgumentError)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
#test_invalid_fastruby_arguments(15)
|
81
|
+
|
82
|
+
test_fastruby_arguments(1000)
|
25
83
|
end
|
@@ -0,0 +1,303 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
it "should allow one optional argument" do
|
5
|
+
fastruby "
|
6
|
+
class CFX1
|
7
|
+
def foo(a=0)
|
8
|
+
a
|
9
|
+
end
|
10
|
+
end
|
11
|
+
"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should allow one optional argument and should return the default when no specified" do
|
15
|
+
fastruby "
|
16
|
+
class CFX2
|
17
|
+
def foo(a=0)
|
18
|
+
a
|
19
|
+
end
|
20
|
+
end
|
21
|
+
"
|
22
|
+
|
23
|
+
CFX2.new.foo.should be == 0
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should allow one optional argument and should return the passed value when specified" do
|
27
|
+
fastruby "
|
28
|
+
class CFX3
|
29
|
+
def foo(a=0)
|
30
|
+
a
|
31
|
+
end
|
32
|
+
end
|
33
|
+
"
|
34
|
+
|
35
|
+
CFX3.new.foo(99).should be == 99
|
36
|
+
end
|
37
|
+
|
38
|
+
fastruby "
|
39
|
+
class CFX4
|
40
|
+
def foo(a=7,b=4)
|
41
|
+
[a,b]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
"
|
45
|
+
|
46
|
+
it "should allow two optional argument and should return the passed value when no arguments is passed" do
|
47
|
+
cfx4 = CFX4.new
|
48
|
+
cfx4.foo().should be == [7,4]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should allow two optional argument and should return the passed value when one argument is passed" do
|
52
|
+
cfx4 = CFX4.new
|
53
|
+
cfx4.foo(99).should be == [99,4]
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should allow two optional argument and should return the passed value when two arguments are passed" do
|
57
|
+
cfx4 = CFX4.new
|
58
|
+
cfx4.foo(99,88).should be == [99,88]
|
59
|
+
end
|
60
|
+
|
61
|
+
fastruby "
|
62
|
+
class CFX5
|
63
|
+
def foo(a,b=4)
|
64
|
+
[a,b]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
"
|
68
|
+
|
69
|
+
it "should allow one mandatory and one optional argument and should return the passed value when one argument is passed" do
|
70
|
+
cfx5 = CFX5.new
|
71
|
+
cfx5.foo(99).should be == [99,4]
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should allow one mandatory and one optional argument and should return the passed value when two arguments are passed" do
|
75
|
+
cfx5 = CFX5.new
|
76
|
+
cfx5.foo(99,88).should be == [99,88]
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should raise ArgumentError when no arguments are passed" do
|
80
|
+
lambda {
|
81
|
+
cfx5 = CFX5.new
|
82
|
+
cfx5.foo
|
83
|
+
}.should raise_error(ArgumentError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should raise ArgumentError when three arguments are passed" do
|
87
|
+
lambda {
|
88
|
+
cfx5 = CFX5.new
|
89
|
+
cfx5.foo(1,2,3)
|
90
|
+
}.should raise_error(ArgumentError)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should allow splat arguments with default arguments " do
|
94
|
+
fastruby "
|
95
|
+
class CFX6
|
96
|
+
def foo(x=44,*y)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
"
|
100
|
+
end
|
101
|
+
|
102
|
+
fastruby "
|
103
|
+
class CFX7
|
104
|
+
def foo(x=44,*y)
|
105
|
+
x
|
106
|
+
end
|
107
|
+
end
|
108
|
+
"
|
109
|
+
|
110
|
+
it "should allow splat arguments with default arguments accepting no arguments " do
|
111
|
+
CFX7.new.foo.should be == 44
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should allow splat arguments with default arguments accepting one argument" do
|
115
|
+
CFX7.new.foo(55).should be == 55
|
116
|
+
end
|
117
|
+
|
118
|
+
fastruby "
|
119
|
+
class CFX8
|
120
|
+
def foo(x=44,*y)
|
121
|
+
y
|
122
|
+
end
|
123
|
+
end
|
124
|
+
"
|
125
|
+
|
126
|
+
it "should allow splat arguments with default arguments accepting no arguments" do
|
127
|
+
CFX8.new.foo.should be == []
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should allow splat arguments with default arguments accepting one arguments" do
|
131
|
+
CFX8.new.foo(55).should be == []
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should allow splat arguments with default arguments accepting two arguments" do
|
135
|
+
CFX8.new.foo(55,66).should be == [66]
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should allow splat arguments with default arguments accepting three arguments" do
|
139
|
+
CFX8.new.foo(55,66,67,68).should be == [66,67,68]
|
140
|
+
end
|
141
|
+
|
142
|
+
fastruby "
|
143
|
+
class CFX9
|
144
|
+
def foo(a,x=44,*y)
|
145
|
+
a
|
146
|
+
end
|
147
|
+
end
|
148
|
+
"
|
149
|
+
|
150
|
+
it "should allow splat arguments with default arguments accepting one argument" do
|
151
|
+
CFX9.new.foo(55).should be == 55
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should allow splat arguments with default arguments accepting two argument" do
|
155
|
+
CFX9.new.foo(55,66).should be == 55
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should allow splat arguments with default arguments accepting three argument" do
|
159
|
+
CFX9.new.foo(55,66,77).should be == 55
|
160
|
+
end
|
161
|
+
|
162
|
+
fastruby "
|
163
|
+
class CFX10
|
164
|
+
def foo(a,x=44,*y)
|
165
|
+
x
|
166
|
+
end
|
167
|
+
end
|
168
|
+
"
|
169
|
+
it "should allow splat arguments with default arguments accepting one argument" do
|
170
|
+
CFX10.new.foo(55).should be == 44
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should allow splat arguments with default arguments accepting two argument" do
|
174
|
+
CFX10.new.foo(55,66).should be == 66
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should allow splat arguments with default arguments accepting three argument" do
|
178
|
+
CFX10.new.foo(55,66,77).should be == 66
|
179
|
+
end
|
180
|
+
|
181
|
+
fastruby "
|
182
|
+
class CFX11
|
183
|
+
def foo(a,x=44,*y)
|
184
|
+
y
|
185
|
+
end
|
186
|
+
end
|
187
|
+
"
|
188
|
+
|
189
|
+
it "should raise ArgumentError with splat arguments with default arguments when no arguments are passed" do
|
190
|
+
lambda {
|
191
|
+
CFX11.new.foo
|
192
|
+
}.should raise_error(ArgumentError)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should allow splat arguments with default arguments accepting one argument" do
|
196
|
+
CFX11.new.foo(55).should be == []
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should allow splat arguments with default arguments accepting two argument" do
|
200
|
+
CFX11.new.foo(55,66).should be == []
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should allow splat arguments with default arguments accepting three argument" do
|
204
|
+
CFX11.new.foo(55,66,77).should be == [77]
|
205
|
+
end
|
206
|
+
|
207
|
+
fastruby "
|
208
|
+
class CFX12
|
209
|
+
def foo(a=0,&block)
|
210
|
+
a
|
211
|
+
end
|
212
|
+
end
|
213
|
+
"
|
214
|
+
|
215
|
+
it "should allow splat arguments with default with block arguments accepting no argument" do
|
216
|
+
CFX12.new.foo() {
|
217
|
+
|
218
|
+
}.should be == 0
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should allow splat arguments with default with block arguments accepting one argument" do
|
222
|
+
CFX12.new.foo(44) {
|
223
|
+
|
224
|
+
}.should be == 44
|
225
|
+
end
|
226
|
+
|
227
|
+
fastruby "
|
228
|
+
class CFX13
|
229
|
+
def foo(a=0,&block)
|
230
|
+
block.call
|
231
|
+
end
|
232
|
+
end
|
233
|
+
"
|
234
|
+
|
235
|
+
it "should allow splat arguments with default with block arguments accepting no argument" do
|
236
|
+
CFX13.new.foo() {
|
237
|
+
66
|
238
|
+
}.should be == 66
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should allow splat arguments with default with block arguments accepting one argument" do
|
242
|
+
CFX13.new.foo(44) {
|
243
|
+
77
|
244
|
+
}.should be == 77
|
245
|
+
end
|
246
|
+
|
247
|
+
fastruby "
|
248
|
+
class CFX14
|
249
|
+
def foo
|
250
|
+
55
|
251
|
+
end
|
252
|
+
end
|
253
|
+
"
|
254
|
+
|
255
|
+
fastruby "
|
256
|
+
class CFX15
|
257
|
+
def foo(cfx14,b = cfx14.foo)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
"
|
261
|
+
|
262
|
+
it "should execute default blocks when no argument is passed" do
|
263
|
+
cfx14 = CFX14.new
|
264
|
+
cfx15 = CFX15.new
|
265
|
+
|
266
|
+
cfx14.should_receive :foo
|
267
|
+
|
268
|
+
cfx15.foo(cfx14)
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should not execute default blocks when argument is passed" do
|
272
|
+
cfx14 = CFX14.new
|
273
|
+
cfx15 = CFX15.new
|
274
|
+
|
275
|
+
cfx14.should_not_receive :foo
|
276
|
+
|
277
|
+
cfx15.foo(cfx14,99)
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should allow if on default argument" do
|
281
|
+
fastruby "
|
282
|
+
class ::CFX16
|
283
|
+
def foo(a, b = if a
|
284
|
+
87
|
285
|
+
else
|
286
|
+
55
|
287
|
+
end
|
288
|
+
)
|
289
|
+
b
|
290
|
+
end
|
291
|
+
end
|
292
|
+
"
|
293
|
+
|
294
|
+
|
295
|
+
cfx16 = ::CFX16.new
|
296
|
+
|
297
|
+
cfx16.foo(false).should be == 55
|
298
|
+
cfx16.foo(true).should be == 87
|
299
|
+
cfx16.foo(true,99).should be == 99
|
300
|
+
cfx16.foo(false,99).should be == 99
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
@@ -0,0 +1,317 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
it "should allow define method with array arguments" do
|
5
|
+
lambda {
|
6
|
+
fastruby "
|
7
|
+
class CF1
|
8
|
+
def foo(*x)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
"
|
12
|
+
}.should_not raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should allow define method with array arguments and call with no arguments" do
|
16
|
+
lambda {
|
17
|
+
fastruby "
|
18
|
+
class ::CF2
|
19
|
+
def foo(*x)
|
20
|
+
x
|
21
|
+
end
|
22
|
+
end
|
23
|
+
"
|
24
|
+
|
25
|
+
::CF2.new.foo().should be == []
|
26
|
+
}.should_not raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should allow define method with array arguments and call with one argument" do
|
30
|
+
lambda {
|
31
|
+
fastruby "
|
32
|
+
class ::CF3
|
33
|
+
def foo(*x)
|
34
|
+
x
|
35
|
+
end
|
36
|
+
end
|
37
|
+
"
|
38
|
+
|
39
|
+
::CF3.new.foo(1).should be == [1]
|
40
|
+
}.should_not raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should allow define method with array arguments and call with two arguments" do
|
44
|
+
lambda {
|
45
|
+
fastruby "
|
46
|
+
class ::CF4
|
47
|
+
def foo(*x)
|
48
|
+
x
|
49
|
+
end
|
50
|
+
end
|
51
|
+
"
|
52
|
+
|
53
|
+
::CF4.new.foo(1,2).should be == [1,2]
|
54
|
+
}.should_not raise_error
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should allow define method with normal argument plus array arguments and call with one argument" do
|
58
|
+
lambda {
|
59
|
+
fastruby "
|
60
|
+
class ::CF5
|
61
|
+
def foo(a, *x)
|
62
|
+
x
|
63
|
+
end
|
64
|
+
end
|
65
|
+
"
|
66
|
+
|
67
|
+
::CF5.new.foo(1).should be == []
|
68
|
+
}.should_not raise_error
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should allow define method with normal argument plus array arguments and call with two arguments" do
|
72
|
+
lambda {
|
73
|
+
fastruby "
|
74
|
+
class ::CF6
|
75
|
+
def foo(a, *x)
|
76
|
+
x
|
77
|
+
end
|
78
|
+
end
|
79
|
+
"
|
80
|
+
|
81
|
+
::CF6.new.foo(1,2).should be == [2]
|
82
|
+
}.should_not raise_error
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should allow define method with normal argument plus array arguments and call with one argument" do
|
86
|
+
lambda {
|
87
|
+
fastruby "
|
88
|
+
class ::CF7
|
89
|
+
def foo(a, *x)
|
90
|
+
a
|
91
|
+
end
|
92
|
+
end
|
93
|
+
"
|
94
|
+
|
95
|
+
::CF7.new.foo(1).should be == 1
|
96
|
+
}.should_not raise_error
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should allow define method with normal argument plus array arguments and call with two arguments" do
|
100
|
+
lambda {
|
101
|
+
fastruby "
|
102
|
+
class ::CF8
|
103
|
+
def foo(a, *x)
|
104
|
+
a
|
105
|
+
end
|
106
|
+
end
|
107
|
+
"
|
108
|
+
|
109
|
+
::CF8.new.foo(1,2).should be == 1
|
110
|
+
}.should_not raise_error
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should allow define method with array arguments and call with no arguments from fastruby" do
|
114
|
+
lambda {
|
115
|
+
fastruby "
|
116
|
+
class ::CF9
|
117
|
+
def foo(*x)
|
118
|
+
x
|
119
|
+
end
|
120
|
+
|
121
|
+
def bar
|
122
|
+
foo
|
123
|
+
end
|
124
|
+
end
|
125
|
+
"
|
126
|
+
|
127
|
+
::CF9.new.bar.should be == []
|
128
|
+
}.should_not raise_error
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should allow define method with array arguments and call with one argument from fastruby" do
|
132
|
+
lambda {
|
133
|
+
fastruby "
|
134
|
+
class ::CF10
|
135
|
+
def foo(*x)
|
136
|
+
x
|
137
|
+
end
|
138
|
+
|
139
|
+
def bar
|
140
|
+
foo(1)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
"
|
144
|
+
|
145
|
+
::CF10.new.bar.should be == [1]
|
146
|
+
}.should_not raise_error
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should allow define method with array arguments and call with two arguments from fastruby" do
|
150
|
+
lambda {
|
151
|
+
fastruby "
|
152
|
+
class ::CF11
|
153
|
+
def foo(*x)
|
154
|
+
x
|
155
|
+
end
|
156
|
+
|
157
|
+
def bar
|
158
|
+
foo(1,2)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
"
|
162
|
+
|
163
|
+
::CF11.new.bar.should be == [1,2]
|
164
|
+
}.should_not raise_error
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should allow define method with normal argument plus array arguments and call with one argument from fastruby" do
|
168
|
+
lambda {
|
169
|
+
fastruby "
|
170
|
+
class ::CF12
|
171
|
+
def foo(a, *x)
|
172
|
+
x
|
173
|
+
end
|
174
|
+
|
175
|
+
def bar
|
176
|
+
foo(1)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
"
|
180
|
+
|
181
|
+
::CF12.new.bar.should be == []
|
182
|
+
}.should_not raise_error
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should allow define method with normal argument plus array arguments and call with two arguments from fastruby" do
|
186
|
+
lambda {
|
187
|
+
fastruby "
|
188
|
+
class ::CF13
|
189
|
+
def foo(a, *x)
|
190
|
+
x
|
191
|
+
end
|
192
|
+
|
193
|
+
def bar
|
194
|
+
foo(1,2)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
"
|
198
|
+
|
199
|
+
::CF13.new.bar.should be == [2]
|
200
|
+
}.should_not raise_error
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should allow define method with normal argument plus array arguments and call with one argument from fastruby" do
|
204
|
+
lambda {
|
205
|
+
fastruby "
|
206
|
+
class ::CF14
|
207
|
+
def foo(a, *x)
|
208
|
+
a
|
209
|
+
end
|
210
|
+
|
211
|
+
def bar
|
212
|
+
foo(1)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
"
|
216
|
+
|
217
|
+
::CF14.new.bar.should be == 1
|
218
|
+
}.should_not raise_error
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should allow define method with normal argument plus array arguments and call with two arguments from fastruby" do
|
222
|
+
lambda {
|
223
|
+
fastruby "
|
224
|
+
class ::CF15
|
225
|
+
def foo(a, *x)
|
226
|
+
a
|
227
|
+
end
|
228
|
+
|
229
|
+
def bar
|
230
|
+
foo(1.2)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
"
|
234
|
+
|
235
|
+
::CF15.new.foo(1,2).should be == 1
|
236
|
+
}.should_not raise_error
|
237
|
+
end
|
238
|
+
|
239
|
+
it "should raise ArgumentError when trying to call with too few arguments" do
|
240
|
+
lambda {
|
241
|
+
fastruby "
|
242
|
+
class ::CF16
|
243
|
+
def foo(a, *x)
|
244
|
+
a
|
245
|
+
end
|
246
|
+
end
|
247
|
+
"
|
248
|
+
|
249
|
+
::CF16.new.foo
|
250
|
+
}.should raise_error(ArgumentError)
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should raise ArgumentError when trying to call with too few arguments from fastruby" do
|
254
|
+
lambda {
|
255
|
+
fastruby "
|
256
|
+
class ::CF17
|
257
|
+
def foo(a, *x)
|
258
|
+
a
|
259
|
+
end
|
260
|
+
|
261
|
+
def bar
|
262
|
+
foo
|
263
|
+
end
|
264
|
+
end
|
265
|
+
"
|
266
|
+
|
267
|
+
::CF17.new.bar
|
268
|
+
}.should raise_error(ArgumentError)
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should call Array#to_s when infering array type for splat argument" do
|
272
|
+
fastruby "
|
273
|
+
class ::CF18
|
274
|
+
def foo(*x)
|
275
|
+
x
|
276
|
+
end
|
277
|
+
end
|
278
|
+
"
|
279
|
+
|
280
|
+
::CF18.new.foo(1,2,3,4,5).should be == [1,2,3,4,5]
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
class ::CFF
|
285
|
+
|
286
|
+
end
|
287
|
+
it "should allow define splat arguments on singleton method" do
|
288
|
+
fastruby "
|
289
|
+
class ::CF19
|
290
|
+
def bar(x)
|
291
|
+
def x.foo(*y)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
"
|
296
|
+
|
297
|
+
x = ::CFF.new
|
298
|
+
::CF19.new.bar(x)
|
299
|
+
x.foo(1,2,3,4,5)
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should read splat arguments on singleton method" do
|
303
|
+
fastruby "
|
304
|
+
class ::CF20
|
305
|
+
def bar(x)
|
306
|
+
def x.foo(*y)
|
307
|
+
y
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
"
|
312
|
+
|
313
|
+
x = ::CFF.new
|
314
|
+
::CF20.new.bar(x)
|
315
|
+
x.foo(1,2,3,4,5).should be == [1,2,3,4,5]
|
316
|
+
end
|
317
|
+
end
|