sourcify 0.5.0 → 0.6.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/HISTORY.txt +5 -0
- data/README.rdoc +86 -3
- data/Rakefile +47 -15
- data/lib/sourcify.rb +13 -0
- data/lib/sourcify/common/parser/converter.rb +29 -0
- data/lib/sourcify/common/parser/raw_scanner/comment.rb +23 -0
- data/lib/sourcify/common/parser/raw_scanner/counter.rb +43 -0
- data/lib/sourcify/common/parser/raw_scanner/dstring.rb +60 -0
- data/lib/sourcify/common/parser/raw_scanner/extensions.rb +121 -0
- data/lib/sourcify/common/parser/raw_scanner/heredoc.rb +26 -0
- data/lib/sourcify/common/parser/source_code.rb +33 -0
- data/lib/sourcify/common/ragel/common.rl +5 -0
- data/lib/sourcify/common/ragel/expressions.rl +38 -0
- data/lib/sourcify/{proc/scanner.rl → common/ragel/machines.rl} +10 -178
- data/lib/sourcify/errors.rb +4 -0
- data/lib/sourcify/method.rb +134 -0
- data/lib/sourcify/method/methods.rb +3 -0
- data/lib/sourcify/method/methods/to_raw_source.rb +30 -0
- data/lib/sourcify/method/methods/to_sexp.rb +30 -0
- data/lib/sourcify/method/methods/to_source.rb +30 -0
- data/lib/sourcify/method/parser.rb +104 -0
- data/lib/sourcify/method/parser/converter.rb +8 -0
- data/lib/sourcify/method/parser/raw_scanner.rb +2494 -0
- data/lib/sourcify/method/parser/raw_scanner.rl +144 -0
- data/lib/sourcify/method/parser/raw_scanner_extensions.rb +64 -0
- data/lib/sourcify/method/parser/scanner.rb +48 -0
- data/lib/sourcify/method/parser/source_code.rb +8 -0
- data/lib/sourcify/proc.rb +0 -2
- data/lib/sourcify/proc/parser.rb +2 -5
- data/lib/sourcify/proc/parser/converter.rb +2 -23
- data/lib/sourcify/proc/{scanner.rb → parser/raw_scanner.rb} +808 -806
- data/lib/sourcify/proc/parser/raw_scanner.rl +149 -0
- data/lib/sourcify/proc/parser/raw_scanner_extensions.rb +72 -0
- data/lib/sourcify/proc/parser/{code_scanner.rb → scanner.rb} +9 -5
- data/lib/sourcify/proc/parser/source_code.rb +2 -27
- data/lib/sourcify/version.rb +1 -1
- data/spec/method/others_from_def_end_block_spec.rb +49 -0
- data/spec/method/others_from_define_method_spec.rb +62 -0
- data/spec/method/raw_scanner/block_comment_spec.rb +8 -0
- data/spec/method/raw_scanner/double_colons_spec.rb +8 -0
- data/spec/method/raw_scanner/double_quote_str_w_interpolation_spec.rb +8 -0
- data/spec/method/raw_scanner/double_quote_str_wo_interpolation_spec.rb +8 -0
- data/spec/method/raw_scanner/heredoc_w_indent_spec.rb +8 -0
- data/spec/method/raw_scanner/heredoc_wo_indent_spec.rb +8 -0
- data/spec/method/raw_scanner/kw_block_start_alias1_spec.rb +20 -0
- data/spec/method/raw_scanner/kw_block_start_alias2_spec.rb +20 -0
- data/spec/method/raw_scanner/per_line_comment_spec.rb +8 -0
- data/spec/method/raw_scanner/single_quote_str_spec.rb +8 -0
- data/spec/method/raw_scanner/slash_operator_spec.rb +8 -0
- data/spec/method/raw_scanner/spec_helper.rb +80 -0
- data/spec/method/spec_helper.rb +1 -0
- data/spec/method/to_raw_source_spec.rb +31 -0
- data/spec/method/to_raw_source_w_specified_strip_enclosure_spec.rb +148 -0
- data/spec/method/to_sexp_from_def_end_block_w_variables_spec.rb +46 -0
- data/spec/method/to_sexp_from_def_end_block_within_irb_spec.rb +38 -0
- data/spec/method/to_sexp_from_define_method_w_multi_blocks_and_specified_attached_to_spec.rb +56 -0
- data/spec/method/to_sexp_from_define_method_w_variables_spec.rb +52 -0
- data/spec/method/to_sexp_from_define_method_within_irb_spec.rb +42 -0
- data/spec/method/to_sexp_w_specified_strip_enclosure_spec.rb +74 -0
- data/spec/method/to_source_from_def_end_block_w_19_extras_spec.rb +23 -0
- data/spec/method/to_source_from_def_end_block_w_nested_begin_spec.rb +35 -0
- data/spec/method/to_source_from_def_end_block_w_nested_case_spec.rb +35 -0
- data/spec/method/to_source_from_def_end_block_w_nested_class_spec.rb +51 -0
- data/spec/method/to_source_from_def_end_block_w_nested_do_end_block_spec.rb +33 -0
- data/spec/method/to_source_from_def_end_block_w_nested_for_spec.rb +126 -0
- data/spec/method/to_source_from_def_end_block_w_nested_if_spec.rb +82 -0
- data/spec/method/to_source_from_def_end_block_w_nested_literal_keyword_spec.rb +141 -0
- data/spec/method/to_source_from_def_end_block_w_nested_method_spec.rb +33 -0
- data/spec/method/to_source_from_def_end_block_w_nested_module_spec.rb +59 -0
- data/spec/method/to_source_from_def_end_block_w_nested_unless_spec.rb +82 -0
- data/spec/method/to_source_from_def_end_block_w_nested_until_spec.rb +179 -0
- data/spec/method/to_source_from_def_end_block_w_nested_while_spec.rb +179 -0
- data/spec/method/to_source_from_def_end_block_w_singleton_method_spec.rb +19 -0
- data/spec/method/to_source_from_def_end_block_within_irb_spec.rb +30 -0
- data/spec/method/to_source_from_def_end_w_multi_blocks_and_many_matches_spec.rb +30 -0
- data/spec/method/to_source_from_def_end_w_multi_blocks_and_single_match_spec.rb +36 -0
- data/spec/method/to_source_from_define_method_w_braced_block_spec.rb +113 -0
- data/spec/method/to_source_from_define_method_w_do_end_block_spec.rb +145 -0
- data/spec/method/to_source_from_define_method_w_multi_blocks_and_many_matches_spec.rb +56 -0
- data/spec/method/to_source_from_define_method_w_multi_blocks_and_single_match_spec.rb +73 -0
- data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_many_matches_spec.rb +36 -0
- data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_no_match_spec.rb +36 -0
- data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_single_match_spec.rb +28 -0
- data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_spec.rb +103 -0
- data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_many_matches_spec.rb +36 -0
- data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_no_match_spec.rb +36 -0
- data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_single_match_spec.rb +28 -0
- data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_ignore_nested_spec.rb +36 -0
- data/spec/method/to_source_from_define_method_within_irb_spec.rb +32 -0
- data/spec/method/to_source_magic_file_var_spec.rb +176 -0
- data/spec/method/to_source_magic_line_var_spec.rb +298 -0
- data/spec/method/to_source_w_specified_strip_enclosure_spec.rb +39 -0
- data/spec/no_method/unsupported_platform_spec.rb +26 -0
- data/spec/proc/raw_scanner/block_comment_spec.rb +8 -0
- data/spec/proc/raw_scanner/double_colons_spec.rb +8 -0
- data/spec/proc/raw_scanner/double_quote_str_w_interpolation_spec.rb +8 -0
- data/spec/proc/raw_scanner/double_quote_str_wo_interpolation_spec.rb +8 -0
- data/spec/proc/raw_scanner/heredoc_w_indent_spec.rb +8 -0
- data/spec/proc/raw_scanner/heredoc_wo_indent_spec.rb +8 -0
- data/spec/proc/raw_scanner/kw_block_start_alias1_spec.rb +20 -0
- data/spec/proc/raw_scanner/kw_block_start_alias2_spec.rb +20 -0
- data/spec/proc/raw_scanner/per_line_comment_spec.rb +8 -0
- data/spec/proc/raw_scanner/single_quote_str_spec.rb +8 -0
- data/spec/proc/raw_scanner/slash_operator_spec.rb +8 -0
- data/spec/proc/raw_scanner/spec_helper.rb +63 -0
- data/spec/{proc_scanner/block_comment_spec.rb → raw_scanner/block_comment_shared_spec.rb} +1 -5
- data/spec/{proc_scanner/double_colons_spec.rb → raw_scanner/double_colons_shared_spec.rb} +1 -5
- data/spec/{proc_scanner/double_quote_str_w_interpolation_spec.rb → raw_scanner/double_quote_str_w_interpolation_shared_spec.rb} +1 -5
- data/spec/{proc_scanner/double_quote_str_wo_interpolation_spec.rb → raw_scanner/double_quote_str_wo_interpolation_shared_spec.rb} +1 -5
- data/spec/raw_scanner/heredoc_w_indent_shared_spec.rb +69 -0
- data/spec/raw_scanner/heredoc_wo_indent_shared_spec.rb +70 -0
- data/spec/{proc_scanner/kw_do_alias1_spec.rb → raw_scanner/kw_block_start_alias1_shared_spec.rb} +10 -26
- data/spec/{proc_scanner/kw_do_alias2_spec.rb → raw_scanner/kw_block_start_alias2_shared_spec.rb} +10 -25
- data/spec/{proc_scanner/per_line_comment_spec.rb → raw_scanner/per_line_comment_shared_spec.rb} +1 -5
- data/spec/raw_scanner/shared_specs.rb +3 -0
- data/spec/{proc_scanner/single_quote_str_spec.rb → raw_scanner/single_quote_str_shared_spec.rb} +1 -5
- data/spec/{proc_scanner/slash_operator_spec.rb → raw_scanner/slash_operator_shared_spec.rb} +1 -5
- data/spec/run_spec.sh +7 -1
- data/spec/spec_helper.rb +8 -25
- metadata +204 -47
- data/.rvmrc +0 -1
- data/VERSION +0 -1
- data/lib/sourcify/proc/scanner/comment.rb +0 -21
- data/lib/sourcify/proc/scanner/counter.rb +0 -44
- data/lib/sourcify/proc/scanner/dstring.rb +0 -59
- data/lib/sourcify/proc/scanner/extensions.rb +0 -171
- data/lib/sourcify/proc/scanner/heredoc.rb +0 -24
- data/spec/proc_scanner/heredoc_spec.rb +0 -144
- data/spec/proc_scanner/spec_helper.rb +0 -33
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'Method#to_sexp (from define_method)' do
|
4
|
+
describe 'variables' do
|
5
|
+
|
6
|
+
before { @thing = Object.new }
|
7
|
+
|
8
|
+
should 'handle non var' do
|
9
|
+
blk = lambda { x }
|
10
|
+
@thing.class.send(:define_method, :m1, &blk)
|
11
|
+
@thing.method(:m1).should.be having_sexp(
|
12
|
+
s(:defn, :m1, s(:args), s(:scope, s(:block, s(:call, nil, :x, s(:arglist)))))
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'not handle local var' do
|
17
|
+
# NOTE: This can be a potential bug, cos we purposely ignore the local
|
18
|
+
# var captured in the proc's binding ... anyway, we see how things go
|
19
|
+
# (eg. maybe nobody would ever care abt it)
|
20
|
+
x, blk = 'lx', lambda { x }
|
21
|
+
@thing.class.send(:define_method, :m2, &blk)
|
22
|
+
@thing.method(:m2).should.be having_sexp(
|
23
|
+
s(:defn, :m2, s(:args), s(:scope, s(:block, s(:call, nil, :x, s(:arglist)))))
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
should 'handle instance var' do
|
28
|
+
@x, blk = 'ix', lambda { @x }
|
29
|
+
@thing.class.send(:define_method, :m3, &blk)
|
30
|
+
method(:m3).should.be having_sexp(
|
31
|
+
s(:defn, :m3, s(:args), s(:scope, s(:block, s(:ivar, :@x))))
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
should 'handle class var' do
|
36
|
+
@@x, blk = 'cx', lambda { @@x }
|
37
|
+
@thing.class.send(:define_method, :m4, &blk)
|
38
|
+
method(:m4).should.be having_sexp(
|
39
|
+
s(:defn, :m4, s(:args), s(:scope, s(:block, s(:cvar, :@@x))))
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
should 'handle global var' do
|
44
|
+
$x, blk = 'gx', lambda { $x }
|
45
|
+
@thing.class.send(:define_method, :m5, &blk)
|
46
|
+
method(:m5).should.be having_sexp(
|
47
|
+
s(:defn, :m5, s(:args), s(:scope, s(:block, s(:gvar, :$x))))
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'Method#to_sexp (from define_method)' do
|
4
|
+
describe 'within IRB' do
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def irb_eval(string)
|
9
|
+
irb_exec(string)[-1]
|
10
|
+
end
|
11
|
+
|
12
|
+
def equal_to(expected)
|
13
|
+
lambda {|found| found == expected }
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
should 'handle non var' do
|
19
|
+
irb_eval(%\
|
20
|
+
thing = Object.new
|
21
|
+
blk = lambda { x }
|
22
|
+
thing.class.send(:define_method, :m1, &blk)
|
23
|
+
thing.method(:m1).to_sexp
|
24
|
+
\).should.be equal_to(
|
25
|
+
s(:defn, :m1, s(:args), s(:scope, s(:block, s(:call, nil, :x, s(:arglist)))))
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'not handle local var' do
|
30
|
+
irb_eval(%\
|
31
|
+
thing = Object.new
|
32
|
+
x = :lx
|
33
|
+
blk = lambda { x }
|
34
|
+
thing.class.send(:define_method, :m2, &blk)
|
35
|
+
thing.method(:m2).to_sexp
|
36
|
+
\).should.be equal_to(
|
37
|
+
s(:defn, :m2, s(:args), s(:scope, s(:block, s(:call, nil, :x, s(:arglist)))))
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'Method#to_sexp' do
|
4
|
+
describe 'w specified {:strip_enclosure => ...}' do
|
5
|
+
|
6
|
+
describe '>> w true' do
|
7
|
+
|
8
|
+
options = {:strip_enclosure => true}
|
9
|
+
|
10
|
+
should 'strip enclosing proc wo arg' do
|
11
|
+
def m1; a+b; end
|
12
|
+
method(:m1).should.be having_sexp(
|
13
|
+
s(:scope,
|
14
|
+
s(:block,
|
15
|
+
s(:call,
|
16
|
+
s(:call, nil, :a, s(:arglist)),
|
17
|
+
:+,
|
18
|
+
s(:arglist, s(:call, nil, :b, s(:arglist)))))),
|
19
|
+
options
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
should 'strip enclosing proc w arg' do
|
24
|
+
def m2(a); a+b; end
|
25
|
+
method(:m2).should.be having_sexp(
|
26
|
+
s(:scope,
|
27
|
+
s(:block,
|
28
|
+
s(:call,
|
29
|
+
s(:lvar, :a),
|
30
|
+
:+,
|
31
|
+
s(:arglist, s(:call, nil, :b, s(:arglist)))))),
|
32
|
+
options
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '>> w false' do
|
39
|
+
|
40
|
+
options = {:strip_enclosure => false}
|
41
|
+
|
42
|
+
should 'not strip enclosing proc wo arg' do
|
43
|
+
def m3; a+b; end
|
44
|
+
method(:m3).should.be having_sexp(
|
45
|
+
s(:defn,
|
46
|
+
:m3,
|
47
|
+
s(:args),
|
48
|
+
s(:scope,
|
49
|
+
s(:block,
|
50
|
+
s(:call,
|
51
|
+
s(:call, nil, :a, s(:arglist)),
|
52
|
+
:+,
|
53
|
+
s(:arglist, s(:call, nil, :b, s(:arglist))))))),
|
54
|
+
options
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'not strip enclosing proc w arg' do
|
59
|
+
def m4(a); a+b; end
|
60
|
+
method(:m4).should.be having_sexp(
|
61
|
+
s(:defn,
|
62
|
+
:m4,
|
63
|
+
s(:args, :a),
|
64
|
+
s(:scope,
|
65
|
+
s(:block,
|
66
|
+
s(:call, s(:lvar, :a), :+, s(:arglist, s(:call, nil, :b, s(:arglist))))))),
|
67
|
+
options
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe "Method#to_source (from def ... end block)" do
|
4
|
+
describe "w 19 extras" do
|
5
|
+
if RUBY_VERSION.include?('1.9.')
|
6
|
+
|
7
|
+
should 'handle simple (w label keys)' do
|
8
|
+
def m1; {a: 1, b: 2}; end
|
9
|
+
method(:m1).should.be having_source(%(
|
10
|
+
def m1; {:a => 1, :b => 2}; end
|
11
|
+
))
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'handle nested (w label keys)' do
|
15
|
+
def m2; {a: 1, b: {c: 3}}; end
|
16
|
+
method(:m2).should.be having_source(%(
|
17
|
+
def m2; {:a => 1, :b => {:c => 3}}; end
|
18
|
+
))
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'Method#to_source (from def ... end block)' do
|
4
|
+
describe 'w nested begin' do
|
5
|
+
|
6
|
+
should 'handle simple' do
|
7
|
+
def m1
|
8
|
+
begin @x1 = 1 end
|
9
|
+
end
|
10
|
+
method(:m1).should.be having_source(%(
|
11
|
+
def m1
|
12
|
+
begin @x1 = 1 end
|
13
|
+
end
|
14
|
+
))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'handle nested' do
|
18
|
+
def m2
|
19
|
+
begin
|
20
|
+
@x1 = 1
|
21
|
+
begin @x2 = 2 end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
method(:m2).should.be having_source(%(
|
25
|
+
def m2
|
26
|
+
begin
|
27
|
+
@x1 = 1
|
28
|
+
begin @x2 = 2 end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
))
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe "Method#to_source (from def ... end block)" do
|
4
|
+
describe "w nested case" do
|
5
|
+
|
6
|
+
should 'handle simple' do
|
7
|
+
def m1
|
8
|
+
case @x1 when true then false end
|
9
|
+
end
|
10
|
+
method(:m1).should.be having_source(%(
|
11
|
+
def m1
|
12
|
+
case @x1 when true then false end
|
13
|
+
end
|
14
|
+
))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'handle nested' do
|
18
|
+
def m2
|
19
|
+
case @x1
|
20
|
+
when true
|
21
|
+
case @x2 when false then true end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
method(:m2).should.be having_source(%(
|
25
|
+
def m2
|
26
|
+
case @x1
|
27
|
+
when true
|
28
|
+
case @x2 when false then true end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
))
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe "Method#to_source (from def ... end block)" do
|
4
|
+
describe "w nested class" do
|
5
|
+
|
6
|
+
class AA; end
|
7
|
+
|
8
|
+
should 'handle singleton' do
|
9
|
+
def m1
|
10
|
+
class << AA
|
11
|
+
def aa
|
12
|
+
@x1 = 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
method(:m1).should.be having_source(%(
|
17
|
+
def m1
|
18
|
+
class << AA
|
19
|
+
def aa
|
20
|
+
@x1 = 1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
))
|
25
|
+
end
|
26
|
+
|
27
|
+
should 'handle nested' do
|
28
|
+
def m2
|
29
|
+
class << AA
|
30
|
+
class BB
|
31
|
+
def bb
|
32
|
+
@x1 = 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
method(:m2).should.be having_source(%(
|
38
|
+
def m2
|
39
|
+
class << AA
|
40
|
+
class BB
|
41
|
+
def bb
|
42
|
+
@x1 = 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
))
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe "Method#to_source (from def ... end block)" do
|
4
|
+
describe "w nested do ... end block" do
|
5
|
+
|
6
|
+
should 'handle simple' do
|
7
|
+
def m1
|
8
|
+
lambda do @x1 = 1 end
|
9
|
+
end
|
10
|
+
method(:m1).should.be having_source(%(
|
11
|
+
def m1
|
12
|
+
lambda { @x1 = 1 }
|
13
|
+
end
|
14
|
+
))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'handle nested' do
|
18
|
+
def m2
|
19
|
+
lambda do
|
20
|
+
lambda do @x1 = 1 end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
method(:m2).should.be having_source(%(
|
24
|
+
def m2
|
25
|
+
lambda do
|
26
|
+
lambda { @x1 = 1 }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
))
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe "Method#to_source (from def ... end block)" do
|
4
|
+
describe "w nested for block" do
|
5
|
+
|
6
|
+
should 'handle w do' do
|
7
|
+
def m1
|
8
|
+
for x1 in [1,2] do x1 end
|
9
|
+
end
|
10
|
+
method(:m1).should.be having_source(%(
|
11
|
+
def m1
|
12
|
+
for x1 in [1,2] do x1 end
|
13
|
+
end
|
14
|
+
))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'handle w \ do' do
|
18
|
+
def m2
|
19
|
+
for x2 in [1,2] \
|
20
|
+
do x2 end
|
21
|
+
end
|
22
|
+
method(:m2).should.be having_source(%(
|
23
|
+
def m2
|
24
|
+
for x2 in [1,2] do x2 end
|
25
|
+
end
|
26
|
+
))
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'handle wo do (w newline)' do
|
30
|
+
def m3
|
31
|
+
for x3 in [1,2]
|
32
|
+
x3
|
33
|
+
end
|
34
|
+
end
|
35
|
+
method(:m3).should.be having_source(%(
|
36
|
+
def m3
|
37
|
+
for x3 in [1,2]
|
38
|
+
x3
|
39
|
+
end
|
40
|
+
end
|
41
|
+
))
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'handle wo do (w semicolon)' do
|
45
|
+
def m4
|
46
|
+
for x4 in [1,2]; x4; end
|
47
|
+
end
|
48
|
+
method(:m4).should.be having_source(%(
|
49
|
+
def m4
|
50
|
+
for x4 in [1,2]
|
51
|
+
x4
|
52
|
+
end
|
53
|
+
end
|
54
|
+
))
|
55
|
+
end
|
56
|
+
|
57
|
+
should 'handle nested wo do within w do' do
|
58
|
+
def m5
|
59
|
+
for x1 in [1,2] do
|
60
|
+
for x2 in [1,2]
|
61
|
+
x2
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
method(:m5).should.be having_source(%(
|
66
|
+
def m5
|
67
|
+
for x1 in [1,2] do
|
68
|
+
for x2 in [1,2]
|
69
|
+
x2
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
))
|
74
|
+
end
|
75
|
+
|
76
|
+
should 'handle nested wo do within wo do' do
|
77
|
+
def m6
|
78
|
+
for x1 in [2,3]
|
79
|
+
for x2 in [2,3]
|
80
|
+
x2
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
method(:m6).should.be having_source(%(
|
85
|
+
def m6
|
86
|
+
for x1 in [2,3] do
|
87
|
+
for x2 in [2,3]
|
88
|
+
x2
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
))
|
93
|
+
end
|
94
|
+
|
95
|
+
should 'handle nested w do within wo do' do
|
96
|
+
def m7
|
97
|
+
for x1 in [3,4]
|
98
|
+
for x2 in [3,4] do x2 end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
method(:m7).should.be having_source(%(
|
102
|
+
def m7
|
103
|
+
for x1 in [3,4]
|
104
|
+
for x2 in [3,4] do x2 end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
))
|
108
|
+
end
|
109
|
+
|
110
|
+
should 'handle nested w do within w do' do
|
111
|
+
def m8
|
112
|
+
for x1 in [4,5] \
|
113
|
+
do for x2 in [4,5] do x2 end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
method(:m8).should.be having_source(%(
|
117
|
+
def m8
|
118
|
+
for x1 in [4,5]
|
119
|
+
for x2 in [4,5] do x2 end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
))
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|