otaku 0.2.2 → 0.3.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.
- data/HISTORY.txt +8 -0
- data/README.rdoc +18 -5
- data/VERSION +1 -1
- data/examples/unittest/client.rb +17 -0
- data/examples/unittest/server.rb +56 -0
- data/examples/unittest/server2.rb +11 -0
- data/examples/unittest/tests/a_test.rb +9 -0
- data/examples/unittest/tests/b_test.rb +9 -0
- data/lib/otaku.rb +1 -0
- data/lib/otaku/handler.rb +16 -108
- data/lib/otaku/handler/context.rb +43 -0
- data/lib/otaku/handler/magic_proc.rb +116 -0
- data/lib/otaku/handler/processor.rb +78 -0
- data/otaku.gemspec +11 -3
- data/spec/handler_spec.rb +905 -23
- data/spec/integration_spec.rb +6 -1
- metadata +17 -4
@@ -0,0 +1,78 @@
|
|
1
|
+
module Otaku
|
2
|
+
class Handler
|
3
|
+
class Processor #:nodoc:
|
4
|
+
|
5
|
+
extend Forwardable
|
6
|
+
%w{file line code eval!}.each do |meth|
|
7
|
+
def_delegator :@magic_proc, meth.to_sym
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(block)
|
11
|
+
@magic_proc = MagicProc.new(block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def marshal_dump
|
15
|
+
[@magic_proc]
|
16
|
+
end
|
17
|
+
|
18
|
+
def marshal_load(data)
|
19
|
+
@magic_proc, _ = data
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
class MagicProc < Handler::MagicProc
|
25
|
+
|
26
|
+
def code_fragments
|
27
|
+
ignore, start_marker, arg =
|
28
|
+
[:ignore, :start_marker, :arg].map{|key| code_match_args[key] }
|
29
|
+
[
|
30
|
+
"proc #{start_marker} |#{arg}| ",
|
31
|
+
source_code.sub(ignore, '')
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
35
|
+
def sexp_regexp
|
36
|
+
@cache[:sexp_regexp] ||= (
|
37
|
+
Regexp.new([
|
38
|
+
Regexp.quote("s(:iter, s(:call, nil, :"),
|
39
|
+
"(proc|lambda)",
|
40
|
+
Regexp.quote(", s(:arglist)), s(:lasgn, :#{code_match_args[:arg]}), s("),
|
41
|
+
].join)
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def code_match_args
|
46
|
+
@cache[:code_match_args] ||= (
|
47
|
+
arg_idx, marker_idx = 5, 3
|
48
|
+
args = source_code.match(code_regexp)
|
49
|
+
while args && prob_regexp =~ args[1]
|
50
|
+
arg_idx, marker_idx = 4, 2
|
51
|
+
args = source_code.match(revised_regexp(args[1]))
|
52
|
+
end
|
53
|
+
{
|
54
|
+
:ignore => args[1],
|
55
|
+
:start_marker => args[marker_idx],
|
56
|
+
:arg => args[arg_idx]
|
57
|
+
}
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
def code_regexp
|
62
|
+
/^(.*?(Otaku\.start.*?|lambda|proc|Proc\.new)\s*(do|\{)\s*(\|(\w+)\|\s*))/m
|
63
|
+
end
|
64
|
+
|
65
|
+
def revised_regexp(e)
|
66
|
+
/^(.*?#{Regexp.quote(e)}.*?\s*(\{|do)\s*(\|(\w+)\|)\s*)/m
|
67
|
+
end
|
68
|
+
|
69
|
+
def prob_regexp
|
70
|
+
/Otaku\.start.*?(lambda|proc|Proc\.new)\s*(\{|do)\s*\|\w+\|\s*$/m
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
data/otaku.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{otaku}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["NgTzeYang"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-05}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{ngty77@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,6 +28,9 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/otaku/client.rb",
|
29
29
|
"lib/otaku/encoder.rb",
|
30
30
|
"lib/otaku/handler.rb",
|
31
|
+
"lib/otaku/handler/context.rb",
|
32
|
+
"lib/otaku/handler/magic_proc.rb",
|
33
|
+
"lib/otaku/handler/processor.rb",
|
31
34
|
"lib/otaku/server.rb",
|
32
35
|
"otaku.gemspec",
|
33
36
|
"spec/handler_spec.rb",
|
@@ -42,7 +45,12 @@ Gem::Specification.new do |s|
|
|
42
45
|
s.test_files = [
|
43
46
|
"spec/integration_spec.rb",
|
44
47
|
"spec/handler_spec.rb",
|
45
|
-
"spec/spec_helper.rb"
|
48
|
+
"spec/spec_helper.rb",
|
49
|
+
"examples/unittest/client.rb",
|
50
|
+
"examples/unittest/tests/b_test.rb",
|
51
|
+
"examples/unittest/tests/a_test.rb",
|
52
|
+
"examples/unittest/server.rb",
|
53
|
+
"examples/unittest/server2.rb"
|
46
54
|
]
|
47
55
|
|
48
56
|
if s.respond_to? :specification_version then
|
data/spec/handler_spec.rb
CHANGED
@@ -6,30 +6,830 @@ end
|
|
6
6
|
|
7
7
|
Otaku.instance_eval do
|
8
8
|
def start(context = {}, &block)
|
9
|
-
Otaku::Handler.new(
|
9
|
+
Otaku::Handler.new(context, block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Otaku::Handler::Context
|
14
|
+
alias_method :orig_magic_proc, :magic_proc
|
15
|
+
attr_reader :magic_procs
|
16
|
+
def magic_proc(val)
|
17
|
+
(@magic_procs ||= []) << orig_magic_proc(val)
|
18
|
+
@magic_procs.last
|
10
19
|
end
|
11
20
|
end
|
12
21
|
|
13
22
|
describe "Otaku Service Handler" do
|
14
23
|
|
15
|
-
describe '>> initializing context' do
|
24
|
+
describe '>> initializing @context' do
|
16
25
|
|
17
26
|
should 'assign to empty anoynmous class instance code when given {}' do
|
18
|
-
Otaku::Handler.new({}, lambda{}).context.should.equal('Class.new{ }.new')
|
27
|
+
Otaku::Handler.new({}, lambda{}).context.code.should.equal('Class.new{ }.new')
|
19
28
|
end
|
20
29
|
|
21
30
|
should 'assign to non-empty anoynmous class instance code when given {:m1 => v1, :m2 => v2, ...}' do
|
22
31
|
encode = lambda{|val| Otaku::Encoder.encode(val).gsub('|','\|') }
|
23
|
-
Otaku::Handler.new({:m1 => 'v|1', :m2 => 'v|2'}, lambda{}).context.should.equal(
|
32
|
+
Otaku::Handler.new({:m1 => 'v|1', :m2 => 'v|2'}, lambda{}).context.code.should.equal(
|
24
33
|
'Class.new{ %s; %s }.new' % [
|
25
34
|
"def m1; Encoder.decode(%|#{encode['v|1']}|); end",
|
26
35
|
"def m2; Encoder.decode(%|#{encode['v|2']}|); end"
|
27
36
|
])
|
28
37
|
end
|
29
38
|
|
39
|
+
describe '>>> handling serializing of proc variable' do
|
40
|
+
|
41
|
+
class << self
|
42
|
+
|
43
|
+
def new_otaku_handler(*args, &block)
|
44
|
+
Otaku::Handler.new({:processor => block}, lambda{})
|
45
|
+
end
|
46
|
+
|
47
|
+
def should_have_expected_context(context, code, line)
|
48
|
+
context.magic_procs[0].code.should.equal(code)
|
49
|
+
context.magic_procs[0].file.should.equal(File.expand_path(__FILE__))
|
50
|
+
context.magic_procs[0].line.should.equal(line)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
no_arg_expected = "lambda { [\"a\", \"b\"].map { |x| puts(x) } }"
|
56
|
+
single_arg_expected = "lambda { |arg| [\"a\", \"b\"].map { |x| puts(x) } }"
|
57
|
+
multiple_args_expected = "lambda { |arg1, arg2| [\"a\", \"b\"].map { |x| puts(x) } }"
|
58
|
+
unlimited_args_expected = "lambda { |*args| [\"a\", \"b\"].map { |x| puts(x) } }"
|
59
|
+
|
60
|
+
{
|
61
|
+
# ////////////////////////////////////////////////////////////////////////
|
62
|
+
# >> Always newlinling (single arg)
|
63
|
+
# ////////////////////////////////////////////////////////////////////////
|
64
|
+
__LINE__ => [
|
65
|
+
lambda do |arg|
|
66
|
+
%w{a b}.map do |x|
|
67
|
+
puts x
|
68
|
+
end
|
69
|
+
end,
|
70
|
+
single_arg_expected
|
71
|
+
],
|
72
|
+
__LINE__ => [
|
73
|
+
lambda { |arg|
|
74
|
+
%w{a b}.map{|x|
|
75
|
+
puts x
|
76
|
+
}
|
77
|
+
},
|
78
|
+
single_arg_expected
|
79
|
+
],
|
80
|
+
__LINE__ => [
|
81
|
+
proc do |arg|
|
82
|
+
%w{a b}.map do |x|
|
83
|
+
puts x
|
84
|
+
end
|
85
|
+
end,
|
86
|
+
single_arg_expected
|
87
|
+
],
|
88
|
+
__LINE__ => [
|
89
|
+
lambda { |arg|
|
90
|
+
%w{a b}.map{|x|
|
91
|
+
puts x
|
92
|
+
}
|
93
|
+
},
|
94
|
+
single_arg_expected
|
95
|
+
],
|
96
|
+
__LINE__ => [
|
97
|
+
Proc.new do |arg|
|
98
|
+
%w{a b}.map do |x|
|
99
|
+
puts x
|
100
|
+
end
|
101
|
+
end,
|
102
|
+
single_arg_expected
|
103
|
+
],
|
104
|
+
__LINE__ => [
|
105
|
+
Proc.new { |arg|
|
106
|
+
%w{a b}.map{|x|
|
107
|
+
puts x
|
108
|
+
}
|
109
|
+
},
|
110
|
+
single_arg_expected
|
111
|
+
],
|
112
|
+
# ////////////////////////////////////////////////////////////////////////
|
113
|
+
# >> Always newlinling (multiple args)
|
114
|
+
# ////////////////////////////////////////////////////////////////////////
|
115
|
+
__LINE__ => [
|
116
|
+
lambda do |arg1, arg2|
|
117
|
+
%w{a b}.map do |x|
|
118
|
+
puts x
|
119
|
+
end
|
120
|
+
end,
|
121
|
+
multiple_args_expected
|
122
|
+
],
|
123
|
+
__LINE__ => [
|
124
|
+
lambda { |arg1, arg2|
|
125
|
+
%w{a b}.map{|x|
|
126
|
+
puts x
|
127
|
+
}
|
128
|
+
},
|
129
|
+
multiple_args_expected
|
130
|
+
],
|
131
|
+
__LINE__ => [
|
132
|
+
proc do |arg1, arg2|
|
133
|
+
%w{a b}.map do |x|
|
134
|
+
puts x
|
135
|
+
end
|
136
|
+
end,
|
137
|
+
multiple_args_expected
|
138
|
+
],
|
139
|
+
__LINE__ => [
|
140
|
+
lambda { |arg1, arg2|
|
141
|
+
%w{a b}.map{|x|
|
142
|
+
puts x
|
143
|
+
}
|
144
|
+
},
|
145
|
+
multiple_args_expected
|
146
|
+
],
|
147
|
+
__LINE__ => [
|
148
|
+
Proc.new do |arg1, arg2|
|
149
|
+
%w{a b}.map do |x|
|
150
|
+
puts x
|
151
|
+
end
|
152
|
+
end,
|
153
|
+
multiple_args_expected
|
154
|
+
],
|
155
|
+
__LINE__ => [
|
156
|
+
Proc.new { |arg1, arg2|
|
157
|
+
%w{a b}.map{|x|
|
158
|
+
puts x
|
159
|
+
}
|
160
|
+
},
|
161
|
+
multiple_args_expected
|
162
|
+
],
|
163
|
+
# ////////////////////////////////////////////////////////////////////////
|
164
|
+
# >> Always newlinling (unlimited args)
|
165
|
+
# ////////////////////////////////////////////////////////////////////////
|
166
|
+
__LINE__ => [
|
167
|
+
lambda do |*args|
|
168
|
+
%w{a b}.map do |x|
|
169
|
+
puts x
|
170
|
+
end
|
171
|
+
end,
|
172
|
+
unlimited_args_expected
|
173
|
+
],
|
174
|
+
__LINE__ => [
|
175
|
+
lambda { |*args|
|
176
|
+
%w{a b}.map{|x|
|
177
|
+
puts x
|
178
|
+
}
|
179
|
+
},
|
180
|
+
unlimited_args_expected
|
181
|
+
],
|
182
|
+
__LINE__ => [
|
183
|
+
proc do |*args|
|
184
|
+
%w{a b}.map do |x|
|
185
|
+
puts x
|
186
|
+
end
|
187
|
+
end,
|
188
|
+
unlimited_args_expected
|
189
|
+
],
|
190
|
+
__LINE__ => [
|
191
|
+
lambda { |*args|
|
192
|
+
%w{a b}.map{|x|
|
193
|
+
puts x
|
194
|
+
}
|
195
|
+
},
|
196
|
+
unlimited_args_expected
|
197
|
+
],
|
198
|
+
__LINE__ => [
|
199
|
+
Proc.new do |*args|
|
200
|
+
%w{a b}.map do |x|
|
201
|
+
puts x
|
202
|
+
end
|
203
|
+
end,
|
204
|
+
unlimited_args_expected
|
205
|
+
],
|
206
|
+
__LINE__ => [
|
207
|
+
Proc.new { |*args|
|
208
|
+
%w{a b}.map{|x|
|
209
|
+
puts x
|
210
|
+
}
|
211
|
+
},
|
212
|
+
unlimited_args_expected
|
213
|
+
],
|
214
|
+
# ////////////////////////////////////////////////////////////////////////
|
215
|
+
# >> Always newlinling (no arg)
|
216
|
+
# ////////////////////////////////////////////////////////////////////////
|
217
|
+
__LINE__ => [
|
218
|
+
lambda do
|
219
|
+
%w{a b}.map do |x|
|
220
|
+
puts x
|
221
|
+
end
|
222
|
+
end,
|
223
|
+
no_arg_expected
|
224
|
+
],
|
225
|
+
__LINE__ => [
|
226
|
+
lambda {
|
227
|
+
%w{a b}.map{|x|
|
228
|
+
puts x
|
229
|
+
}
|
230
|
+
},
|
231
|
+
no_arg_expected
|
232
|
+
],
|
233
|
+
__LINE__ => [
|
234
|
+
proc do
|
235
|
+
%w{a b}.map do |x|
|
236
|
+
puts x
|
237
|
+
end
|
238
|
+
end,
|
239
|
+
no_arg_expected
|
240
|
+
],
|
241
|
+
__LINE__ => [
|
242
|
+
lambda {
|
243
|
+
%w{a b}.map{|x|
|
244
|
+
puts x
|
245
|
+
}
|
246
|
+
},
|
247
|
+
no_arg_expected
|
248
|
+
],
|
249
|
+
__LINE__ => [
|
250
|
+
Proc.new do
|
251
|
+
%w{a b}.map do |x|
|
252
|
+
puts x
|
253
|
+
end
|
254
|
+
end,
|
255
|
+
no_arg_expected
|
256
|
+
],
|
257
|
+
__LINE__ => [
|
258
|
+
Proc.new {
|
259
|
+
%w{a b}.map{|x|
|
260
|
+
puts x
|
261
|
+
}
|
262
|
+
},
|
263
|
+
no_arg_expected
|
264
|
+
],
|
265
|
+
# ////////////////////////////////////////////////////////////////////////
|
266
|
+
# >> Partial newlining (single arg)
|
267
|
+
# ////////////////////////////////////////////////////////////////////////
|
268
|
+
__LINE__ => [
|
269
|
+
lambda do |arg|
|
270
|
+
%w{a b}.map do |x| puts x end
|
271
|
+
end,
|
272
|
+
single_arg_expected
|
273
|
+
],
|
274
|
+
__LINE__ => [
|
275
|
+
lambda { |arg|
|
276
|
+
%w{a b}.map{|x| puts x }
|
277
|
+
},
|
278
|
+
single_arg_expected
|
279
|
+
],
|
280
|
+
__LINE__ => [
|
281
|
+
proc do |arg|
|
282
|
+
%w{a b}.map do |x| puts x end
|
283
|
+
end,
|
284
|
+
single_arg_expected
|
285
|
+
],
|
286
|
+
__LINE__ => [
|
287
|
+
lambda { |arg|
|
288
|
+
%w{a b}.map{|x| puts x }
|
289
|
+
},
|
290
|
+
single_arg_expected
|
291
|
+
],
|
292
|
+
__LINE__ => [
|
293
|
+
Proc.new do |arg|
|
294
|
+
%w{a b}.map do |x| puts x end
|
295
|
+
end,
|
296
|
+
single_arg_expected
|
297
|
+
],
|
298
|
+
__LINE__ => [
|
299
|
+
Proc.new { |arg|
|
300
|
+
%w{a b}.map{|x| puts x }
|
301
|
+
},
|
302
|
+
single_arg_expected
|
303
|
+
],
|
304
|
+
# ////////////////////////////////////////////////////////////////////////
|
305
|
+
# >> Partial newlining (multiple args)
|
306
|
+
# ////////////////////////////////////////////////////////////////////////
|
307
|
+
__LINE__ => [
|
308
|
+
lambda do |arg1, arg2|
|
309
|
+
%w{a b}.map do |x| puts x end
|
310
|
+
end,
|
311
|
+
multiple_args_expected
|
312
|
+
],
|
313
|
+
__LINE__ => [
|
314
|
+
lambda { |arg1, arg2|
|
315
|
+
%w{a b}.map{|x| puts x }
|
316
|
+
},
|
317
|
+
multiple_args_expected
|
318
|
+
],
|
319
|
+
__LINE__ => [
|
320
|
+
proc do |arg1, arg2|
|
321
|
+
%w{a b}.map do |x| puts x end
|
322
|
+
end,
|
323
|
+
multiple_args_expected
|
324
|
+
],
|
325
|
+
__LINE__ => [
|
326
|
+
lambda { |arg1, arg2|
|
327
|
+
%w{a b}.map{|x| puts x }
|
328
|
+
},
|
329
|
+
multiple_args_expected
|
330
|
+
],
|
331
|
+
__LINE__ => [
|
332
|
+
Proc.new do |arg1, arg2|
|
333
|
+
%w{a b}.map do |x| puts x end
|
334
|
+
end,
|
335
|
+
multiple_args_expected
|
336
|
+
],
|
337
|
+
__LINE__ => [
|
338
|
+
Proc.new { |arg1, arg2|
|
339
|
+
%w{a b}.map{|x| puts x }
|
340
|
+
},
|
341
|
+
multiple_args_expected
|
342
|
+
],
|
343
|
+
# ////////////////////////////////////////////////////////////////////////
|
344
|
+
# >> Partial newlining (unlimited args)
|
345
|
+
# ////////////////////////////////////////////////////////////////////////
|
346
|
+
__LINE__ => [
|
347
|
+
lambda do |*args|
|
348
|
+
%w{a b}.map do |x| puts x end
|
349
|
+
end,
|
350
|
+
unlimited_args_expected
|
351
|
+
],
|
352
|
+
__LINE__ => [
|
353
|
+
lambda { |*args|
|
354
|
+
%w{a b}.map{|x| puts x }
|
355
|
+
},
|
356
|
+
unlimited_args_expected
|
357
|
+
],
|
358
|
+
__LINE__ => [
|
359
|
+
proc do |*args|
|
360
|
+
%w{a b}.map do |x| puts x end
|
361
|
+
end,
|
362
|
+
unlimited_args_expected
|
363
|
+
],
|
364
|
+
__LINE__ => [
|
365
|
+
lambda { |*args|
|
366
|
+
%w{a b}.map{|x| puts x }
|
367
|
+
},
|
368
|
+
unlimited_args_expected
|
369
|
+
],
|
370
|
+
__LINE__ => [
|
371
|
+
Proc.new do |*args|
|
372
|
+
%w{a b}.map do |x| puts x end
|
373
|
+
end,
|
374
|
+
unlimited_args_expected
|
375
|
+
],
|
376
|
+
__LINE__ => [
|
377
|
+
Proc.new { |*args|
|
378
|
+
%w{a b}.map{|x| puts x }
|
379
|
+
},
|
380
|
+
unlimited_args_expected
|
381
|
+
],
|
382
|
+
# ////////////////////////////////////////////////////////////////////////
|
383
|
+
# >> Partial newlining (no args)
|
384
|
+
# ////////////////////////////////////////////////////////////////////////
|
385
|
+
__LINE__ => [
|
386
|
+
lambda do
|
387
|
+
%w{a b}.map do |x| puts x end
|
388
|
+
end,
|
389
|
+
no_arg_expected
|
390
|
+
],
|
391
|
+
__LINE__ => [
|
392
|
+
lambda {
|
393
|
+
%w{a b}.map{|x| puts x }
|
394
|
+
},
|
395
|
+
no_arg_expected
|
396
|
+
],
|
397
|
+
__LINE__ => [
|
398
|
+
proc do
|
399
|
+
%w{a b}.map do |x| puts x end
|
400
|
+
end,
|
401
|
+
no_arg_expected
|
402
|
+
],
|
403
|
+
__LINE__ => [
|
404
|
+
lambda {
|
405
|
+
%w{a b}.map{|x| puts x }
|
406
|
+
},
|
407
|
+
no_arg_expected
|
408
|
+
],
|
409
|
+
__LINE__ => [
|
410
|
+
Proc.new do
|
411
|
+
%w{a b}.map do |x| puts x end
|
412
|
+
end,
|
413
|
+
no_arg_expected
|
414
|
+
],
|
415
|
+
__LINE__ => [
|
416
|
+
Proc.new {
|
417
|
+
%w{a b}.map{|x| puts x }
|
418
|
+
},
|
419
|
+
no_arg_expected
|
420
|
+
],
|
421
|
+
# ////////////////////////////////////////////////////////////////////////
|
422
|
+
# >> No newlining (single arg)
|
423
|
+
# ////////////////////////////////////////////////////////////////////////
|
424
|
+
__LINE__ => [
|
425
|
+
lambda do |arg| %w{a b}.map do |x| puts x end end,
|
426
|
+
single_arg_expected
|
427
|
+
],
|
428
|
+
__LINE__ => [
|
429
|
+
lambda { |arg| %w{a b}.map{|x| puts x } },
|
430
|
+
single_arg_expected
|
431
|
+
],
|
432
|
+
__LINE__ => [
|
433
|
+
proc do |arg| %w{a b}.map do |x| puts x end end,
|
434
|
+
single_arg_expected
|
435
|
+
],
|
436
|
+
__LINE__ => [
|
437
|
+
lambda { |arg| %w{a b}.map{|x| puts x } },
|
438
|
+
single_arg_expected
|
439
|
+
],
|
440
|
+
__LINE__ => [
|
441
|
+
Proc.new do |arg| %w{a b}.map do |x| puts x end end,
|
442
|
+
single_arg_expected
|
443
|
+
],
|
444
|
+
__LINE__ => [
|
445
|
+
Proc.new { |arg| %w{a b}.map{|x| puts x } },
|
446
|
+
single_arg_expected
|
447
|
+
],
|
448
|
+
# ////////////////////////////////////////////////////////////////////////
|
449
|
+
# >> No newlining (multiple args)
|
450
|
+
# ////////////////////////////////////////////////////////////////////////
|
451
|
+
__LINE__ => [
|
452
|
+
lambda do |arg1, arg2| %w{a b}.map do |x| puts x end end,
|
453
|
+
multiple_args_expected
|
454
|
+
],
|
455
|
+
__LINE__ => [
|
456
|
+
lambda { |arg1, arg2| %w{a b}.map{|x| puts x } },
|
457
|
+
multiple_args_expected
|
458
|
+
],
|
459
|
+
__LINE__ => [
|
460
|
+
proc do |arg1, arg2| %w{a b}.map do |x| puts x end end,
|
461
|
+
multiple_args_expected
|
462
|
+
],
|
463
|
+
__LINE__ => [
|
464
|
+
lambda { |arg1, arg2| %w{a b}.map{|x| puts x } },
|
465
|
+
multiple_args_expected
|
466
|
+
],
|
467
|
+
__LINE__ => [
|
468
|
+
Proc.new do |arg1, arg2| %w{a b}.map do |x| puts x end end,
|
469
|
+
multiple_args_expected
|
470
|
+
],
|
471
|
+
__LINE__ => [
|
472
|
+
Proc.new { |arg1, arg2| %w{a b}.map{|x| puts x } },
|
473
|
+
multiple_args_expected
|
474
|
+
],
|
475
|
+
# ////////////////////////////////////////////////////////////////////////
|
476
|
+
# >> No newlining (unlimited args)
|
477
|
+
# ////////////////////////////////////////////////////////////////////////
|
478
|
+
__LINE__ => [
|
479
|
+
lambda do |*args| %w{a b}.map do |x| puts x end end,
|
480
|
+
unlimited_args_expected
|
481
|
+
],
|
482
|
+
__LINE__ => [
|
483
|
+
lambda { |*args| %w{a b}.map{|x| puts x } },
|
484
|
+
unlimited_args_expected
|
485
|
+
],
|
486
|
+
__LINE__ => [
|
487
|
+
proc do |*args| %w{a b}.map do |x| puts x end end,
|
488
|
+
unlimited_args_expected
|
489
|
+
],
|
490
|
+
__LINE__ => [
|
491
|
+
lambda { |*args| %w{a b}.map{|x| puts x } },
|
492
|
+
unlimited_args_expected
|
493
|
+
],
|
494
|
+
__LINE__ => [
|
495
|
+
Proc.new do |*args| %w{a b}.map do |x| puts x end end,
|
496
|
+
unlimited_args_expected
|
497
|
+
],
|
498
|
+
__LINE__ => [
|
499
|
+
Proc.new { |*args| %w{a b}.map{|x| puts x } },
|
500
|
+
unlimited_args_expected
|
501
|
+
],
|
502
|
+
# ////////////////////////////////////////////////////////////////////////
|
503
|
+
# >> No newlining (no args)
|
504
|
+
# ////////////////////////////////////////////////////////////////////////
|
505
|
+
__LINE__ => [
|
506
|
+
lambda do %w{a b}.map do |x| puts x end end,
|
507
|
+
no_arg_expected
|
508
|
+
],
|
509
|
+
__LINE__ => [
|
510
|
+
lambda { %w{a b}.map{|x| puts x } },
|
511
|
+
no_arg_expected
|
512
|
+
],
|
513
|
+
__LINE__ => [
|
514
|
+
proc do %w{a b}.map do |x| puts x end end,
|
515
|
+
no_arg_expected
|
516
|
+
],
|
517
|
+
__LINE__ => [
|
518
|
+
lambda { %w{a b}.map{|x| puts x } },
|
519
|
+
no_arg_expected
|
520
|
+
],
|
521
|
+
__LINE__ => [
|
522
|
+
Proc.new do %w{a b}.map do |x| puts x end end,
|
523
|
+
no_arg_expected
|
524
|
+
],
|
525
|
+
__LINE__ => [
|
526
|
+
Proc.new { %w{a b}.map{|x| puts x } },
|
527
|
+
no_arg_expected
|
528
|
+
],
|
529
|
+
}.each do |debug, (block, expected)|
|
530
|
+
should "handle proc variable [##{debug}]" do
|
531
|
+
magic_proc = Otaku::Handler::MagicProc.new(block)
|
532
|
+
encoded = Otaku::Encoder.encode(magic_proc).gsub('|','\|')
|
533
|
+
context = Otaku::Handler.new({:processor => block}, lambda{}).context
|
534
|
+
context.code.should.equal \
|
535
|
+
'Class.new{ %s }.new' % "def processor; Encoder.decode(%|#{encoded}|).eval!; end"
|
536
|
+
should_have_expected_context(context, expected, debug.succ)
|
537
|
+
end
|
538
|
+
end
|
539
|
+
|
540
|
+
# No args
|
541
|
+
|
542
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
543
|
+
should_have_expected_context((
|
544
|
+
new_otaku_handler(1, 2) do
|
545
|
+
%w{a b}.map{|x| puts x }
|
546
|
+
end
|
547
|
+
).context, no_arg_expected, __LINE__ - 3)
|
548
|
+
end
|
549
|
+
|
550
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
551
|
+
should_have_expected_context((
|
552
|
+
new_otaku_handler do
|
553
|
+
%w{a b}.map{|x| puts x }
|
554
|
+
end
|
555
|
+
).context, no_arg_expected, __LINE__ - 3)
|
556
|
+
end
|
557
|
+
|
558
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
559
|
+
should_have_expected_context((
|
560
|
+
new_otaku_handler 1, 2 do
|
561
|
+
%w{a b}.map{|x| puts x }
|
562
|
+
end
|
563
|
+
).context, no_arg_expected, __LINE__ - 3)
|
564
|
+
end
|
565
|
+
|
566
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
567
|
+
should_have_expected_context((
|
568
|
+
new_otaku_handler(1, 2) do %w{a b}.map{|x| puts x } end
|
569
|
+
).context, no_arg_expected, __LINE__ - 1)
|
570
|
+
end
|
571
|
+
|
572
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
573
|
+
should_have_expected_context((
|
574
|
+
new_otaku_handler do %w{a b}.map{|x| puts x } end
|
575
|
+
).context, no_arg_expected, __LINE__ - 1)
|
576
|
+
end
|
577
|
+
|
578
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
579
|
+
should_have_expected_context((
|
580
|
+
new_otaku_handler 1, 2 do %w{a b}.map{|x| puts x } end
|
581
|
+
).context, no_arg_expected, __LINE__ - 1)
|
582
|
+
end
|
583
|
+
|
584
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
585
|
+
should_have_expected_context((
|
586
|
+
new_otaku_handler(1, 2) {
|
587
|
+
%w{a b}.map{|x| puts x }
|
588
|
+
}
|
589
|
+
).context, no_arg_expected, __LINE__ - 3)
|
590
|
+
end
|
591
|
+
|
592
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
593
|
+
should_have_expected_context((
|
594
|
+
new_otaku_handler {
|
595
|
+
%w{a b}.map{|x| puts x }
|
596
|
+
}
|
597
|
+
).context, no_arg_expected, __LINE__ - 3)
|
598
|
+
end
|
599
|
+
|
600
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
601
|
+
should_have_expected_context((
|
602
|
+
new_otaku_handler(1, 2) { %w{a b}.map{|x| puts x } }
|
603
|
+
).context, no_arg_expected, __LINE__ - 1)
|
604
|
+
end
|
605
|
+
|
606
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
607
|
+
should_have_expected_context((
|
608
|
+
new_otaku_handler { %w{a b}.map{|x| puts x } }
|
609
|
+
).context, no_arg_expected, __LINE__ - 1)
|
610
|
+
end
|
611
|
+
|
612
|
+
# Single arg
|
613
|
+
|
614
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
615
|
+
should_have_expected_context((
|
616
|
+
new_otaku_handler(1, 2) do |arg|
|
617
|
+
%w{a b}.map{|x| puts x }
|
618
|
+
end
|
619
|
+
).context, single_arg_expected, __LINE__ - 3)
|
620
|
+
end
|
621
|
+
|
622
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
623
|
+
should_have_expected_context((
|
624
|
+
new_otaku_handler do |arg|
|
625
|
+
%w{a b}.map{|x| puts x }
|
626
|
+
end
|
627
|
+
).context, single_arg_expected, __LINE__ - 3)
|
628
|
+
end
|
629
|
+
|
630
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
631
|
+
should_have_expected_context((
|
632
|
+
new_otaku_handler 1, 2 do |arg|
|
633
|
+
%w{a b}.map{|x| puts x }
|
634
|
+
end
|
635
|
+
).context, single_arg_expected, __LINE__ - 3)
|
636
|
+
end
|
637
|
+
|
638
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
639
|
+
should_have_expected_context((
|
640
|
+
new_otaku_handler(1, 2) do |arg| %w{a b}.map{|x| puts x } end
|
641
|
+
).context, single_arg_expected, __LINE__ - 1)
|
642
|
+
end
|
643
|
+
|
644
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
645
|
+
should_have_expected_context((
|
646
|
+
new_otaku_handler do |arg| %w{a b}.map{|x| puts x } end
|
647
|
+
).context, single_arg_expected, __LINE__ - 1)
|
648
|
+
end
|
649
|
+
|
650
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
651
|
+
should_have_expected_context((
|
652
|
+
new_otaku_handler 1, 2 do |arg| %w{a b}.map{|x| puts x } end
|
653
|
+
).context, single_arg_expected, __LINE__ - 1)
|
654
|
+
end
|
655
|
+
|
656
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
657
|
+
should_have_expected_context((
|
658
|
+
new_otaku_handler(1, 2) { |arg|
|
659
|
+
%w{a b}.map{|x| puts x }
|
660
|
+
}
|
661
|
+
).context, single_arg_expected, __LINE__ - 3)
|
662
|
+
end
|
663
|
+
|
664
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
665
|
+
should_have_expected_context((
|
666
|
+
new_otaku_handler { |arg|
|
667
|
+
%w{a b}.map{|x| puts x }
|
668
|
+
}
|
669
|
+
).context, single_arg_expected, __LINE__ - 3)
|
670
|
+
end
|
671
|
+
|
672
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
673
|
+
should_have_expected_context((
|
674
|
+
new_otaku_handler(1, 2) { |arg| %w{a b}.map{|x| puts x } }
|
675
|
+
).context, single_arg_expected, __LINE__ - 1)
|
676
|
+
end
|
677
|
+
|
678
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
679
|
+
should_have_expected_context((
|
680
|
+
new_otaku_handler { |arg| %w{a b}.map{|x| puts x } }
|
681
|
+
).context, single_arg_expected, __LINE__ - 1)
|
682
|
+
end
|
683
|
+
|
684
|
+
# Multiple args
|
685
|
+
|
686
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
687
|
+
should_have_expected_context((
|
688
|
+
new_otaku_handler(1, 2) do |arg1, arg2|
|
689
|
+
%w{a b}.map{|x| puts x }
|
690
|
+
end
|
691
|
+
).context, multiple_args_expected, __LINE__ - 3)
|
692
|
+
end
|
693
|
+
|
694
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
695
|
+
should_have_expected_context((
|
696
|
+
new_otaku_handler do |arg1, arg2|
|
697
|
+
%w{a b}.map{|x| puts x }
|
698
|
+
end
|
699
|
+
).context, multiple_args_expected, __LINE__ - 3)
|
700
|
+
end
|
701
|
+
|
702
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
703
|
+
should_have_expected_context((
|
704
|
+
new_otaku_handler 1, 2 do |arg1, arg2|
|
705
|
+
%w{a b}.map{|x| puts x }
|
706
|
+
end
|
707
|
+
).context, multiple_args_expected, __LINE__ - 3)
|
708
|
+
end
|
709
|
+
|
710
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
711
|
+
should_have_expected_context((
|
712
|
+
new_otaku_handler(1, 2) do |arg1, arg2| %w{a b}.map{|x| puts x } end
|
713
|
+
).context, multiple_args_expected, __LINE__ - 1)
|
714
|
+
end
|
715
|
+
|
716
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
717
|
+
should_have_expected_context((
|
718
|
+
new_otaku_handler do |arg1, arg2| %w{a b}.map{|x| puts x } end
|
719
|
+
).context, multiple_args_expected, __LINE__ - 1)
|
720
|
+
end
|
721
|
+
|
722
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
723
|
+
should_have_expected_context((
|
724
|
+
new_otaku_handler 1, 2 do |arg1, arg2| %w{a b}.map{|x| puts x } end
|
725
|
+
).context, multiple_args_expected, __LINE__ - 1)
|
726
|
+
end
|
727
|
+
|
728
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
729
|
+
should_have_expected_context((
|
730
|
+
new_otaku_handler(1, 2) { |arg1, arg2|
|
731
|
+
%w{a b}.map{|x| puts x }
|
732
|
+
}
|
733
|
+
).context, multiple_args_expected, __LINE__ - 3)
|
734
|
+
end
|
735
|
+
|
736
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
737
|
+
should_have_expected_context((
|
738
|
+
new_otaku_handler { |arg1, arg2|
|
739
|
+
%w{a b}.map{|x| puts x }
|
740
|
+
}
|
741
|
+
).context, multiple_args_expected, __LINE__ - 3)
|
742
|
+
end
|
743
|
+
|
744
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
745
|
+
should_have_expected_context((
|
746
|
+
new_otaku_handler(1, 2) { |arg1, arg2| %w{a b}.map{|x| puts x } }
|
747
|
+
).context, multiple_args_expected, __LINE__ - 1)
|
748
|
+
end
|
749
|
+
|
750
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
751
|
+
should_have_expected_context((
|
752
|
+
new_otaku_handler { |arg1, arg2| %w{a b}.map{|x| puts x } }
|
753
|
+
).context, multiple_args_expected, __LINE__ - 1)
|
754
|
+
end
|
755
|
+
|
756
|
+
# Unlimited args
|
757
|
+
|
758
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
759
|
+
should_have_expected_context((
|
760
|
+
new_otaku_handler(1, 2) do |*args|
|
761
|
+
%w{a b}.map{|x| puts x }
|
762
|
+
end
|
763
|
+
).context, unlimited_args_expected, __LINE__ - 3)
|
764
|
+
end
|
765
|
+
|
766
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
767
|
+
should_have_expected_context((
|
768
|
+
new_otaku_handler do |*args|
|
769
|
+
%w{a b}.map{|x| puts x }
|
770
|
+
end
|
771
|
+
).context, unlimited_args_expected, __LINE__ - 3)
|
772
|
+
end
|
773
|
+
|
774
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
775
|
+
should_have_expected_context((
|
776
|
+
new_otaku_handler 1, 2 do |*args|
|
777
|
+
%w{a b}.map{|x| puts x }
|
778
|
+
end
|
779
|
+
).context, unlimited_args_expected, __LINE__ - 3)
|
780
|
+
end
|
781
|
+
|
782
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
783
|
+
should_have_expected_context((
|
784
|
+
new_otaku_handler(1, 2) do |*args| %w{a b}.map{|x| puts x } end
|
785
|
+
).context, unlimited_args_expected, __LINE__ - 1)
|
786
|
+
end
|
787
|
+
|
788
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
789
|
+
should_have_expected_context((
|
790
|
+
new_otaku_handler do |*args| %w{a b}.map{|x| puts x } end
|
791
|
+
).context, unlimited_args_expected, __LINE__ - 1)
|
792
|
+
end
|
793
|
+
|
794
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
795
|
+
should_have_expected_context((
|
796
|
+
new_otaku_handler 1, 2 do |*args| %w{a b}.map{|x| puts x } end
|
797
|
+
).context, unlimited_args_expected, __LINE__ - 1)
|
798
|
+
end
|
799
|
+
|
800
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
801
|
+
should_have_expected_context((
|
802
|
+
new_otaku_handler(1, 2) { |*args|
|
803
|
+
%w{a b}.map{|x| puts x }
|
804
|
+
}
|
805
|
+
).context, unlimited_args_expected, __LINE__ - 3)
|
806
|
+
end
|
807
|
+
|
808
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
809
|
+
should_have_expected_context((
|
810
|
+
new_otaku_handler { |*args|
|
811
|
+
%w{a b}.map{|x| puts x }
|
812
|
+
}
|
813
|
+
).context, unlimited_args_expected, __LINE__ - 3)
|
814
|
+
end
|
815
|
+
|
816
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
817
|
+
should_have_expected_context((
|
818
|
+
new_otaku_handler(1, 2) { |*args| %w{a b}.map{|x| puts x } }
|
819
|
+
).context, unlimited_args_expected, __LINE__ - 1)
|
820
|
+
end
|
821
|
+
|
822
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
823
|
+
should_have_expected_context((
|
824
|
+
new_otaku_handler { |*args| %w{a b}.map{|x| puts x } }
|
825
|
+
).context, unlimited_args_expected, __LINE__ - 1)
|
826
|
+
end
|
827
|
+
|
828
|
+
end
|
829
|
+
|
30
830
|
end
|
31
831
|
|
32
|
-
describe '>> initializing
|
832
|
+
describe '>> initializing @processor' do
|
33
833
|
|
34
834
|
expected = "lambda { |watever| [\"a\", \"b\"].map { |x| puts(x) } }"
|
35
835
|
|
@@ -135,7 +935,7 @@ describe "Otaku Service Handler" do
|
|
135
935
|
),
|
136
936
|
}.each do |debug, block|
|
137
937
|
should "handle proc as variable [##{debug}]" do
|
138
|
-
Otaku::Handler.new({}, block).
|
938
|
+
Otaku::Handler.new({}, block).processor.code.should.equal(expected)
|
139
939
|
end
|
140
940
|
end
|
141
941
|
|
@@ -144,7 +944,7 @@ describe "Otaku Service Handler" do
|
|
144
944
|
%w{a b}.map do |x|
|
145
945
|
puts x
|
146
946
|
end
|
147
|
-
end.
|
947
|
+
end.processor.code.should.equal(expected)
|
148
948
|
end
|
149
949
|
|
150
950
|
should "handle block using do ... end [##{__LINE__}]" do
|
@@ -152,29 +952,29 @@ describe "Otaku Service Handler" do
|
|
152
952
|
%w{a b}.map do |x|
|
153
953
|
puts x
|
154
954
|
end
|
155
|
-
end.
|
955
|
+
end.processor.code.should.equal(expected)
|
156
956
|
end
|
157
957
|
|
158
958
|
should "handle block using do ... end [##{__LINE__}]" do
|
159
959
|
Otaku.start({}) do |watever|
|
160
960
|
%w{a b}.map do |x| puts x end
|
161
|
-
end.
|
961
|
+
end.processor.code.should.equal(expected)
|
162
962
|
end
|
163
963
|
|
164
964
|
should "handle block using do ... end [##{__LINE__}]" do
|
165
965
|
Otaku.start do |watever|
|
166
966
|
%w{a b}.map do |x| puts x end
|
167
|
-
end.
|
967
|
+
end.processor.code.should.equal(expected)
|
168
968
|
end
|
169
969
|
|
170
970
|
should "handle block using do ... end [##{__LINE__}]" do
|
171
971
|
Otaku.start({}) do |watever| %w{a b}.map do |x| puts x end end.
|
172
|
-
|
972
|
+
processor.code.should.equal(expected)
|
173
973
|
end
|
174
974
|
|
175
975
|
should "handle block using do ... end [##{__LINE__}]" do
|
176
976
|
Otaku.start do |watever| %w{a b}.map do |x| puts x end end.
|
177
|
-
|
977
|
+
processor.code.should.equal(expected)
|
178
978
|
end
|
179
979
|
|
180
980
|
should "handle block using { ... } [##{__LINE__}]" do
|
@@ -182,7 +982,7 @@ describe "Otaku Service Handler" do
|
|
182
982
|
%w{a b}.map do |x|
|
183
983
|
puts x
|
184
984
|
end
|
185
|
-
}.
|
985
|
+
}.processor.code.should.equal(expected)
|
186
986
|
end
|
187
987
|
|
188
988
|
should "handle block using { ... } [##{__LINE__}]" do
|
@@ -190,39 +990,111 @@ describe "Otaku Service Handler" do
|
|
190
990
|
%w{a b}.map do |x|
|
191
991
|
puts x
|
192
992
|
end
|
193
|
-
}.
|
993
|
+
}.processor.code.should.equal(expected)
|
194
994
|
end
|
195
995
|
|
196
996
|
should "handle block using { ... } [##{__LINE__}]" do
|
197
997
|
Otaku.start({}) { |watever|
|
198
998
|
%w{a b}.map { |x| puts x }
|
199
|
-
}.
|
999
|
+
}.processor.code.should.equal(expected)
|
200
1000
|
end
|
201
1001
|
|
202
1002
|
should "handle block using { ... } [##{__LINE__}]" do
|
203
1003
|
Otaku.start { |watever|
|
204
1004
|
%w{a b}.map { |x| puts x }
|
205
|
-
}.
|
1005
|
+
}.processor.code.should.equal(expected)
|
206
1006
|
end
|
207
1007
|
|
208
1008
|
should "handle block using { ... } [##{__LINE__}]" do
|
209
|
-
Otaku.start({}) { |watever| %w{a b}.map { |x| puts x } }.
|
1009
|
+
Otaku.start({}) { |watever| %w{a b}.map { |x| puts x } }.processor.code.should.equal(expected)
|
210
1010
|
end
|
211
1011
|
|
212
1012
|
should "handle block using { ... } [##{__LINE__}]" do
|
213
|
-
Otaku.start { |watever| %w{a b}.map { |x| puts x } }.
|
1013
|
+
Otaku.start { |watever| %w{a b}.map { |x| puts x } }.processor.code.should.equal(expected)
|
214
1014
|
end
|
215
1015
|
|
216
1016
|
should "leave __FILE__ as __FILE__ [##{__LINE__}]" do
|
217
|
-
Otaku.start { |watever| __FILE__ }.
|
1017
|
+
Otaku.start { |watever| __FILE__ }.processor.code.should.
|
218
1018
|
equal("lambda { |watever| __FILE__ }" % File.expand_path('spec/handler_spec.rb'))
|
219
1019
|
end
|
220
1020
|
|
221
1021
|
should "leave __LINE__ as __LINE__ [##{__LINE__}]" do
|
222
|
-
Otaku.start { |watever| __LINE__ }.
|
1022
|
+
Otaku.start { |watever| __LINE__ }.processor.code.should.
|
223
1023
|
equal("lambda { |watever| __LINE__ }")
|
224
1024
|
end
|
225
1025
|
|
1026
|
+
should "handle block with context variable as proc [##{__LINE__}]" do
|
1027
|
+
Otaku.start(:processor => lambda {'dummy'}) { |watever|
|
1028
|
+
%w{a b}.map do |x|
|
1029
|
+
puts x
|
1030
|
+
end
|
1031
|
+
}.processor.code.should.equal(expected)
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
should "handle block with context variable as proc [##{__LINE__}]" do
|
1035
|
+
Otaku.start(:processor => proc {'dummy'}) { |watever|
|
1036
|
+
%w{a b}.map do |x|
|
1037
|
+
puts x
|
1038
|
+
end
|
1039
|
+
}.processor.code.should.equal(expected)
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
should "handle block with context variable as proc [##{__LINE__}]" do
|
1043
|
+
Otaku.start(:processor => Proc.new {'dummy'}) { |watever|
|
1044
|
+
%w{a b}.map do |x|
|
1045
|
+
puts x
|
1046
|
+
end
|
1047
|
+
}.processor.code.should.equal(expected)
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
should "handle block with context variable as proc [##{__LINE__}]" do
|
1051
|
+
Otaku.start(:processor => lambda {'dummy'}) do |watever|
|
1052
|
+
%w{a b}.map do |x|
|
1053
|
+
puts x
|
1054
|
+
end
|
1055
|
+
end.processor.code.should.equal(expected)
|
1056
|
+
end
|
1057
|
+
|
1058
|
+
should "handle block with context variable as proc [##{__LINE__}]" do
|
1059
|
+
Otaku.start(:processor => proc {'dummy'}) do |watever|
|
1060
|
+
%w{a b}.map do |x|
|
1061
|
+
puts x
|
1062
|
+
end
|
1063
|
+
end.processor.code.should.equal(expected)
|
1064
|
+
end
|
1065
|
+
|
1066
|
+
should "handle block with context variable as proc [##{__LINE__}]" do
|
1067
|
+
Otaku.start(:processor => proc {|arg| 'dummy'}) do |watever|
|
1068
|
+
%w{a b}.map do |x|
|
1069
|
+
puts x
|
1070
|
+
end
|
1071
|
+
end.processor.code.should.equal(expected)
|
1072
|
+
end
|
1073
|
+
|
1074
|
+
should "handle block with context variable as proc [##{__LINE__}]" do
|
1075
|
+
Otaku.start(:processor => proc {|arg1, arg2| 'dummy'}) do |watever|
|
1076
|
+
%w{a b}.map do |x|
|
1077
|
+
puts x
|
1078
|
+
end
|
1079
|
+
end.processor.code.should.equal(expected)
|
1080
|
+
end
|
1081
|
+
|
1082
|
+
should "handle block with context variable as proc [##{__LINE__}]" do
|
1083
|
+
Otaku.start(:processor => proc {|*args| 'dummy'}) do |watever|
|
1084
|
+
%w{a b}.map do |x|
|
1085
|
+
puts x
|
1086
|
+
end
|
1087
|
+
end.processor.code.should.equal(expected)
|
1088
|
+
end
|
1089
|
+
|
1090
|
+
should "handle block with context variable as proc [##{__LINE__}]" do
|
1091
|
+
Otaku.start(:processor => Proc.new {'dummy'}) do |watever|
|
1092
|
+
%w{a b}.map do |x|
|
1093
|
+
puts x
|
1094
|
+
end
|
1095
|
+
end.processor.code.should.equal(expected)
|
1096
|
+
end
|
1097
|
+
|
226
1098
|
end
|
227
1099
|
|
228
1100
|
describe '>> fetching root' do
|
@@ -231,13 +1103,23 @@ describe "Otaku Service Handler" do
|
|
231
1103
|
end
|
232
1104
|
end
|
233
1105
|
|
234
|
-
describe '>> processing
|
1106
|
+
describe '>> processing magic variables' do
|
1107
|
+
|
1108
|
+
should "reflect __FILE__ captured when the proc was 1st defined [##{__LINE__}]" do
|
1109
|
+
Otaku.start(:processor => lambda { __FILE__ }) { |watever| processor.call }.
|
1110
|
+
process(:fake_data).should.equal(File.expand_path(__FILE__))
|
1111
|
+
end
|
235
1112
|
|
236
|
-
should
|
1113
|
+
should "reflect __FILE__ captured when the proc was 1st defined [##{__LINE__}]" do
|
237
1114
|
Otaku.start{ |watever| __FILE__ }.process(:fake_data).should.equal(File.expand_path(__FILE__))
|
238
1115
|
end
|
239
1116
|
|
240
|
-
should
|
1117
|
+
should "reflect __LINE__ captured when the proc was 1st defined [##{__LINE__}]" do
|
1118
|
+
Otaku.start(:processor => lambda { __LINE__ }) { |watever| processor.call }.
|
1119
|
+
process(:fake_data).should.equal(__LINE__.pred)
|
1120
|
+
end
|
1121
|
+
|
1122
|
+
should "reflect __LINE__ captured when the proc was 1st defined [##{__LINE__}]" do
|
241
1123
|
Otaku.start{ |watever| __LINE__ }.process(:fake_data).should.equal(__LINE__)
|
242
1124
|
end
|
243
1125
|
|