sourcify 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.infinity_test +32 -0
- data/HISTORY.txt +12 -0
- data/README.rdoc +69 -30
- data/Rakefile +2 -3
- data/VERSION +1 -1
- data/lib/sourcify.rb +2 -2
- data/lib/sourcify/proc.rb +144 -65
- data/lib/sourcify/proc/methods.rb +3 -0
- data/lib/sourcify/proc/methods/source_location.rb +61 -0
- data/lib/sourcify/proc/methods/to_sexp.rb +40 -0
- data/lib/sourcify/proc/methods/to_source.rb +48 -0
- data/lib/sourcify/proc/parser.rb +36 -17
- data/lib/sourcify/proc/scanner.rb +317 -271
- data/lib/sourcify/proc/scanner.rl +13 -2
- data/lib/sourcify/proc/scanner/extensions.rb +34 -10
- data/sourcify.gemspec +36 -6
- data/spec/proc/created_on_the_fly_proc_spec.rb +1 -1
- data/spec/proc/others_spec.rb +6 -2
- data/spec/proc/spec_helper.rb +1 -0
- data/spec/proc/to_sexp_from_multi_blocks_w_specified_attached_to_spec.rb +46 -0
- data/spec/proc/to_sexp_variables_spec.rb +1 -1
- data/spec/proc/to_sexp_w_specified_strip_enclosure_spec.rb +60 -0
- data/spec/proc/to_sexp_within_irb_spec.rb +1 -1
- data/spec/proc/to_source_from_braced_block_w_nested_braced_block_spec.rb +1 -1
- data/spec/proc/to_source_from_braced_block_w_nested_hash_spec.rb +2 -2
- data/spec/proc/to_source_from_braced_block_wo_nesting_complication_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_w_nested_begin_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_w_nested_case_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_w_nested_class_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_w_nested_do_end_block_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_w_nested_for_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_w_nested_if_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_w_nested_literal_keyword_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_w_nested_method_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_w_nested_module_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_w_nested_unless_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_w_nested_until_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_w_nested_while_spec.rb +1 -1
- data/spec/proc/to_source_from_do_end_block_wo_nesting_complication_spec.rb +1 -1
- data/spec/proc/to_source_from_multi_blocks_w_many_matches_spec.rb +20 -126
- data/spec/proc/to_source_from_multi_blocks_w_single_match_spec.rb +10 -89
- data/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_many_matches_spec.rb +45 -0
- data/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_no_match_spec.rb +45 -0
- data/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_single_match_spec.rb +22 -0
- data/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_spec.rb +83 -0
- data/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.rb +45 -0
- data/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_no_match_spec.rb +45 -0
- data/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_single_match_spec.rb +22 -0
- data/spec/proc/to_source_from_multi_blocks_w_specified_ignore_nested_spec.rb +43 -0
- data/spec/proc/to_source_from_multi_do_end_blocks_w_single_match_spec.rb +1 -1
- data/spec/proc/to_source_magic_file_var_spec.rb +1 -1
- data/spec/proc/to_source_magic_line_var_spec.rb +1 -1
- data/spec/proc/to_source_variables_spec.rb +1 -1
- data/spec/proc/to_source_w_specified_strip_enclosure_spec.rb +33 -0
- data/spec/proc/to_source_within_irb_spec.rb +1 -1
- data/spec/proc_scanner/block_comment_spec.rb +1 -1
- data/spec/proc_scanner/double_colons_spec.rb +1 -1
- data/spec/proc_scanner/double_quote_str_w_interpolation_spec.rb +9 -9
- data/spec/proc_scanner/double_quote_str_wo_interpolation_spec.rb +13 -13
- data/spec/proc_scanner/heredoc_spec.rb +1 -1
- data/spec/proc_scanner/kw_do_alias1_spec.rb +1 -1
- data/spec/proc_scanner/kw_do_alias2_spec.rb +1 -1
- data/spec/proc_scanner/per_line_comment_spec.rb +1 -1
- data/spec/proc_scanner/single_quote_str_spec.rb +1 -1
- data/spec/proc_scanner/slash_operator_spec.rb +75 -0
- data/spec/proc_scanner/spec_helper.rb +1 -1
- data/spec/spec_helper.rb +53 -45
- metadata +46 -16
- data/ext/sourcify/extconf.rb +0 -2
@@ -1,147 +1,41 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
2
|
|
3
3
|
describe 'Proc#to_source from multi blocks w many matches' do
|
4
4
|
|
5
5
|
if has_parsetree?
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
(
|
11
|
-
b1 = lambda do |a| @x1 end; b2 = lambda do @x1 end; b3 = lambda do @x10 end; b2
|
12
|
-
).should.be having_source(expected%1)
|
13
|
-
end
|
14
|
-
|
15
|
-
should 'skip non-matching (all {...} blocks)' do
|
16
|
-
(
|
17
|
-
b1 = lambda {|a| @x2 }; b2 = lambda { @x2 }; b3 = lambda { @x20 }; b2
|
18
|
-
).should.be having_source(expected%2)
|
7
|
+
should "handle w no nesting on same line" do
|
8
|
+
b1 = lambda {|a| @x1+1 }; b2 = lambda { @x1+2 }; b3 = lambda { @x1+3 }
|
9
|
+
b2.should.be having_source('proc { @x1+2 }')
|
19
10
|
end
|
20
11
|
|
21
|
-
should
|
22
|
-
|
23
|
-
|
24
|
-
).should.be having_source(expected%3)
|
12
|
+
should "handle w single level nesting on same line" do
|
13
|
+
b1 = lambda {|a| @x2+1 }; b2 = lambda { lambda { @x2+2 } }
|
14
|
+
b2.should.be having_source('proc { lambda { @x2+2 } }')
|
25
15
|
end
|
26
16
|
|
27
|
-
should
|
28
|
-
(
|
29
|
-
|
30
|
-
).should.be having_source(expected%4)
|
17
|
+
should "handle w multi level nesting on same line" do
|
18
|
+
b2 = (lambda {|a| lambda { lambda { @x3 } } }).call(1)
|
19
|
+
b2.should.be having_source('proc { lambda { @x3 } }')
|
31
20
|
end
|
32
21
|
|
33
22
|
else
|
34
23
|
|
35
|
-
|
36
|
-
|
37
|
-
should 'raise Sourcify::MultipleMatchingProcsPerLineError (all do...end blocks)' do
|
38
|
-
lambda {
|
39
|
-
(
|
40
|
-
b1 = lambda do |a| @x1 end; b2 = lambda do @x1 end; b3 = lambda do @x1 end ; b2
|
41
|
-
).to_source
|
42
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
43
|
-
end
|
44
|
-
|
45
|
-
should 'raise Sourcify::MultipleMatchingProcsPerLineError (all {...} blocks)' do
|
46
|
-
lambda {
|
47
|
-
(
|
48
|
-
b1 = lambda {|a| @x2 }; b2 = lambda { @x2 }; b3 = lambda { @x2 } ; b2
|
49
|
-
).to_source
|
50
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
51
|
-
end
|
52
|
-
|
53
|
-
should 'raise Sourcify::MultipleMatchingProcsPerLineError (mixed {...} w do...end blocks)' do
|
54
|
-
lambda {
|
55
|
-
(
|
56
|
-
b1 = lambda {|a| @x3 }; b2 = lambda do @x3 end; b3 = lambda { @x4 } ; b2
|
57
|
-
).to_source
|
58
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
59
|
-
end
|
60
|
-
|
61
|
-
should 'raise Sourcify::MultipleMatchingProcsPerLineError (mixed do...end w {...} blocks)' do
|
62
|
-
lambda {
|
63
|
-
(
|
64
|
-
b1 = lambda do |a| @x4 end; b2 = lambda { @x4 }; b3 = lambda do @x4 end ; b2
|
65
|
-
).to_source
|
66
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
67
|
-
end
|
24
|
+
error = Sourcify::MultipleMatchingProcsPerLineError
|
68
25
|
|
26
|
+
should "raise #{error} w no nesting on same line" do
|
27
|
+
b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x }
|
28
|
+
lambda { b2.to_source }.should.raise(error)
|
69
29
|
end
|
70
30
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
lambda {
|
75
|
-
(
|
76
|
-
b1 = lambda do |a| @x1 end; b2 = lambda do lambda do @x1 end end; b2
|
77
|
-
).to_source
|
78
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
79
|
-
end
|
80
|
-
|
81
|
-
should 'raise Sourcify::MultipleMatchingProcsPerLineError (all {...} blocks)' do
|
82
|
-
lambda {
|
83
|
-
(
|
84
|
-
b1 = lambda {|a| @x2 }; b2 = lambda { lambda { @x2 } }; b2
|
85
|
-
).to_source
|
86
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
87
|
-
end
|
88
|
-
|
89
|
-
should 'raise Sourcify::MultipleMatchingProcsPerLineError (mixed {...} w do...end blocks)' do
|
90
|
-
lambda {
|
91
|
-
(
|
92
|
-
b1 = lambda {|a| @x3 }; b2 = lambda do lambda { @x4 } end; b2
|
93
|
-
).to_source
|
94
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
95
|
-
end
|
96
|
-
|
97
|
-
should 'raise Sourcify::MultipleMatchingProcsPerLineError (mixed do...end w {...} blocks)' do
|
98
|
-
lambda {
|
99
|
-
(
|
100
|
-
b1 = lambda do |a| @x4 end; b2 = lambda { lambda do @x4 end }; b2
|
101
|
-
).to_source
|
102
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
103
|
-
end
|
104
|
-
|
31
|
+
should "raise #{error} w single level nesting on same line" do
|
32
|
+
b1 = lambda {|a| @x }; b2 = lambda { lambda { @x } }
|
33
|
+
lambda { b2.to_source }.should.raise(error)
|
105
34
|
end
|
106
35
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
lambda {
|
111
|
-
(
|
112
|
-
b1 = lambda do |a| lambda do lambda do @x1 end end end
|
113
|
-
b2 = b1.call(1)
|
114
|
-
).to_source
|
115
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
116
|
-
end
|
117
|
-
|
118
|
-
should 'raise Sourcify::MultipleMatchingProcsPerLineError (all {...} blocks)' do
|
119
|
-
lambda {
|
120
|
-
(
|
121
|
-
b1 = lambda {|a| lambda { lambda { @x2 } } }
|
122
|
-
b2 = b1.call(1)
|
123
|
-
).to_source
|
124
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
125
|
-
end
|
126
|
-
|
127
|
-
should 'raise Sourcify::MultipleMatchingProcsPerLineError (mixed {...} w do...end blocks)' do
|
128
|
-
lambda {
|
129
|
-
(
|
130
|
-
b1 = lambda {|a| lambda do lambda { @x4 } end }
|
131
|
-
b2 = b1.call(1)
|
132
|
-
).to_source
|
133
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
134
|
-
end
|
135
|
-
|
136
|
-
should 'raise Sourcify::MultipleMatchingProcsPerLineError (mixed do...end w {...} blocks)' do
|
137
|
-
lambda {
|
138
|
-
(
|
139
|
-
b1 = lambda do |a| lambda { lambda do @x4 end } end
|
140
|
-
b2 = b1.call(1)
|
141
|
-
).to_source
|
142
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
143
|
-
end
|
144
|
-
|
36
|
+
should "raise #{error} w multi level nesting on same line" do
|
37
|
+
b2 = (lambda {|a| lambda { lambda { @x } } }).call(1)
|
38
|
+
lambda { b2.to_source }.should.raise(error)
|
145
39
|
end
|
146
40
|
|
147
41
|
end
|
@@ -1,99 +1,20 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
2
|
|
3
3
|
describe 'Proc#to_source from multi blocks w single match' do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
should 'skip non-matching (all do...end blocks)' do
|
10
|
-
(
|
11
|
-
b1 = lambda do |a| @x1 end; b2 = lambda do @x1 end; b2
|
12
|
-
).should.be having_source(expected%1)
|
13
|
-
end
|
14
|
-
|
15
|
-
should 'skip non-matching (all {...} blocks)' do
|
16
|
-
(
|
17
|
-
b1 = lambda {|a| @x2 }; b2 = lambda { @x2 }; b2
|
18
|
-
).should.be having_source(expected%2)
|
19
|
-
end
|
20
|
-
|
21
|
-
should 'skip non-matching (mixed {...} with do...end blocks)' do
|
22
|
-
(
|
23
|
-
b1 = lambda {|a| @x3 }; b2 = lambda do @x3 end; b2
|
24
|
-
).should.be having_source(expected%3)
|
25
|
-
end
|
26
|
-
|
27
|
-
should 'skip non-matching (mixed do...end with {...} blocks)' do
|
28
|
-
(
|
29
|
-
b1 = lambda do |a| @x4 end; b2 = lambda { @x4 }; b2
|
30
|
-
).should.be having_source(expected%4)
|
31
|
-
end
|
32
|
-
|
5
|
+
should 'skip non-matching w no nesting on same line' do
|
6
|
+
b1 = lambda do |a| @x1 end; b2 = lambda do @x1 end
|
7
|
+
b2.should.be having_source('proc { @x1 }')
|
33
8
|
end
|
34
9
|
|
35
|
-
|
36
|
-
|
37
|
-
should '
|
38
|
-
(
|
39
|
-
b1 = lambda do |a| lambda do @x1 end end
|
40
|
-
b2 = b1.call(1) # returns the inner proc
|
41
|
-
).should.be having_source(expected%1)
|
42
|
-
end
|
43
|
-
|
44
|
-
should 'skip non-matching (all {...} blocks)' do
|
45
|
-
(
|
46
|
-
b1 = lambda {|a| lambda { @x2 } }
|
47
|
-
b2 = b1.call(1) # returns the inner proc
|
48
|
-
).should.be having_source(expected%2)
|
49
|
-
end
|
50
|
-
|
51
|
-
should 'skip non-matching (mixed {...} with do...end blocks)' do
|
52
|
-
(
|
53
|
-
b1 = lambda {|a| lambda do @x3 end }
|
54
|
-
b2 = b1.call(1) # returns the inner proc
|
55
|
-
).should.be having_source(expected%3)
|
56
|
-
end
|
57
|
-
|
58
|
-
should 'skip non-matching (mixed do...end with {...} blocks)' do
|
59
|
-
(
|
60
|
-
b1 = lambda do |a| lambda { @x4 } end
|
61
|
-
b2 = b1.call(1) # returns the inner proc
|
62
|
-
).should.be having_source(expected%4)
|
63
|
-
end
|
64
|
-
|
10
|
+
should 'skip non-matching w single level nesting on same line' do
|
11
|
+
b2 = (lambda {|a| lambda { @x2 } }).call(1)
|
12
|
+
b2.should.be having_source('proc { @x2 }')
|
65
13
|
end
|
66
14
|
|
67
|
-
|
68
|
-
|
69
|
-
should '
|
70
|
-
(
|
71
|
-
b1 = lambda do |a| lambda do |a| b2 = lambda do @x1 end end end
|
72
|
-
b2 = b1.call(1).call(1) # returns the inner-most proc
|
73
|
-
).should.be having_source(expected%1)
|
74
|
-
end
|
75
|
-
|
76
|
-
should 'skip non-matching (all {...} blocks)' do
|
77
|
-
(
|
78
|
-
b1 = lambda {|a| lambda {|a| b2 = lambda { @x2 } } }
|
79
|
-
b2 = b1.call(1).call(1) # returns the inner-most proc
|
80
|
-
).should.be having_source(expected%2)
|
81
|
-
end
|
82
|
-
|
83
|
-
should 'skip non-matching (mixed {...} with do...end blocks)' do
|
84
|
-
(
|
85
|
-
b1 = lambda {|a| lambda do |a| b2 = lambda do @x3 end end }
|
86
|
-
b2 = b1.call(1).call(1) # returns the inner-most proc
|
87
|
-
).should.be having_source(expected%3)
|
88
|
-
end
|
89
|
-
|
90
|
-
should 'skip non-matching (mixed do...end with {...} blocks)' do
|
91
|
-
(
|
92
|
-
b1 = lambda do |a| lambda do |a| lambda { @x4 } end end
|
93
|
-
b2 = b1.call(1).call(1) # returns the inner-most proc
|
94
|
-
).should.be having_source(expected%4)
|
95
|
-
end
|
96
|
-
|
15
|
+
should 'skip non-matching w multi level nesting on same line' do
|
16
|
+
b2 = (lambda {|a| lambda {|a| b2 = lambda { @x3 } } }).call(1).call(1)
|
17
|
+
b2.should.be having_source('proc { @x3 }')
|
97
18
|
end
|
98
19
|
|
99
20
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'Proc#to_source w specified {:attached_to => ...} & single match' do
|
4
|
+
|
5
|
+
options = {:attached_to => :lambda}
|
6
|
+
|
7
|
+
if has_parsetree?
|
8
|
+
|
9
|
+
should 'handle no nesting on same line' do
|
10
|
+
b1 = lambda {|a| @x1+1 }; b2 = lambda { @x1+2 }; b3 = lambda { @x1+3 }
|
11
|
+
b2.should.be having_source('proc { @x1+2 }', options)
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'handle single level nesting on same line' do
|
15
|
+
b1 = lambda {|a| @x2+1 }; b2 = lambda { lambda { @x2+2 } }
|
16
|
+
b2.should.be having_source('proc { lambda { @x2+2 } }', options)
|
17
|
+
end
|
18
|
+
|
19
|
+
should 'handle multi level nesting on same line' do
|
20
|
+
b2 = (lambda {|a| lambda { lambda { @x3 } } }).call(1)
|
21
|
+
b2.should.be having_source('proc { lambda { @x3 } }', options)
|
22
|
+
end
|
23
|
+
|
24
|
+
else
|
25
|
+
|
26
|
+
error = Sourcify::MultipleMatchingProcsPerLineError
|
27
|
+
|
28
|
+
should "raise #{error} w no nesting on same line" do
|
29
|
+
b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x }
|
30
|
+
lambda { b2.to_source(options) }.should.raise(error)
|
31
|
+
end
|
32
|
+
|
33
|
+
should "raise #{error} w single level nesting on same line" do
|
34
|
+
b1 = lambda {|a| @x }; b2 = lambda { lambda { @x } }
|
35
|
+
lambda { b2.to_source(options) }.should.raise(error)
|
36
|
+
end
|
37
|
+
|
38
|
+
should "raise #{error} w multi level nesting on same line" do
|
39
|
+
b2 = (lambda {|a| lambda { lambda { @x } } }).call(1)
|
40
|
+
lambda { b2.to_source(options) }.should.raise(error)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'Proc#to_source w specified {:attached_to => ...} & no match' do
|
4
|
+
|
5
|
+
options = {:attached_to => :forever}
|
6
|
+
|
7
|
+
if has_parsetree?
|
8
|
+
|
9
|
+
should 'handle no nesting on same line' do
|
10
|
+
b1 = lambda do |a| @x1+1 end; b2 = lambda do @x1+2 end; b3 = lambda do @x1+3 end
|
11
|
+
b2.should.be having_source('proc { @x1+2 }', options)
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'handle single level nesting on same line' do
|
15
|
+
b1 = lambda do |a| @x2+1 end; b2 = lambda do lambda do @x2+2 end end
|
16
|
+
b2.should.be having_source('proc { lambda { @x2+2 } }', options)
|
17
|
+
end
|
18
|
+
|
19
|
+
should 'handle multi level nesting on same line' do
|
20
|
+
b2 = (lambda do |a| lambda do lambda do @x3 end end end).call(1)
|
21
|
+
b2.should.be having_source('proc { lambda { @x3 } }', options)
|
22
|
+
end
|
23
|
+
|
24
|
+
else
|
25
|
+
|
26
|
+
error = Sourcify::NoMatchingProcError
|
27
|
+
|
28
|
+
should "raise #{error} w no nesting on same line" do
|
29
|
+
b1 = lambda {|a| @x }; b2 = watever { @x }; b3 = lambda { @x }
|
30
|
+
lambda { b2.to_source(options) }.should.raise(error)
|
31
|
+
end
|
32
|
+
|
33
|
+
should "raise #{error} w single level nesting on same line" do
|
34
|
+
b1 = lambda {|a| @x }; b2 = watever { lambda { @x } }
|
35
|
+
lambda { b2.to_source(options) }.should.raise(error)
|
36
|
+
end
|
37
|
+
|
38
|
+
should "raise #{error} w multi level nesting on same line" do
|
39
|
+
b2 = (lambda {|a| watever { lambda { @x } } }).call(1)
|
40
|
+
lambda { b2.to_source(options) }.should.raise(error)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|