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
@@ -132,7 +132,8 @@ module Sourcify
|
|
132
132
|
sqm . sqs20 | sqm . sqs21 | sqm . sqs22 | sqm . sqs23 | sqm . sqs24 |
|
133
133
|
sqm . sqs25 | sqm . sqs26 | sqm . sqs27 | sqm . sqs28
|
134
134
|
) => {
|
135
|
-
push(:sstring, ts, te)
|
135
|
+
push(:sstring, ts, te);
|
136
|
+
fgoto main;
|
136
137
|
};
|
137
138
|
|
138
139
|
## == Double quote strings
|
@@ -441,16 +442,26 @@ module Sourcify
|
|
441
442
|
fgoto heredoc;
|
442
443
|
};
|
443
444
|
|
444
|
-
('"' | "'" | '`' | '
|
445
|
+
('"' | "'" | '`' | '%') => {
|
445
446
|
fhold; fgoto string;
|
446
447
|
};
|
447
448
|
|
449
|
+
'/' => {
|
450
|
+
if preceded_with?(:char, :digit, :var, :const, :symbol, :dstring, :sstring, ')', ']', '}')
|
451
|
+
push(:op, ts, te)
|
452
|
+
else
|
453
|
+
fhold; fgoto string;
|
454
|
+
end
|
455
|
+
};
|
456
|
+
|
448
457
|
## == Misc
|
449
458
|
|
450
459
|
var => { push(:var, ts, te) };
|
451
460
|
const => { push(:const, ts, te) };
|
452
461
|
symbol => { push(:symbol, ts, te) };
|
453
462
|
mspaces => { push(:space, ts, te) };
|
463
|
+
[0-9] => { push(:digit, ts, te) };
|
464
|
+
lower => { push(:char, ts, te) };
|
454
465
|
any => { push(:any, ts, te) };
|
455
466
|
|
456
467
|
*|;
|
@@ -9,9 +9,11 @@ module Sourcify
|
|
9
9
|
|
10
10
|
class Escape < Exception; end
|
11
11
|
|
12
|
-
def process(data,
|
12
|
+
def process(data, opts={})
|
13
13
|
begin
|
14
|
-
@
|
14
|
+
@start_pattern = opts[:start_pattern] || /.*/
|
15
|
+
@body_matcher = opts[:body_matcher] || lambda{|_| true }
|
16
|
+
@stop_on_newline = opts[:stop_on_newline]
|
15
17
|
@results, @data = [], data.unpack("c*")
|
16
18
|
reset_attributes
|
17
19
|
execute!
|
@@ -69,15 +71,28 @@ module Sourcify
|
|
69
71
|
@tokens << [:assoc, '=>']
|
70
72
|
end
|
71
73
|
|
74
|
+
def preceded_with?(*args)
|
75
|
+
begin
|
76
|
+
prev_token = @tokens[-1][0] == :space ? @tokens[-2] : @tokens[-1]
|
77
|
+
!([args].flatten & prev_token).empty?
|
78
|
+
rescue
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
72
82
|
def increment_lineno
|
73
83
|
@lineno += 1
|
74
|
-
|
84
|
+
if @stop_on_newline || !@results.empty? || (@results.empty? && @rejecting_block)
|
85
|
+
raise Escape
|
86
|
+
end
|
75
87
|
end
|
76
88
|
|
77
89
|
def increment_counter(key, count = 1)
|
78
90
|
return if other_counter(key).started?
|
79
|
-
counter = this_counter(key)
|
80
|
-
|
91
|
+
unless (counter = this_counter(key)).started?
|
92
|
+
return if (@rejecting_block = codified_tokens !~ @start_pattern)
|
93
|
+
@false_start_backup = @tokens.dup if key == :brace
|
94
|
+
offset_attributes
|
95
|
+
end
|
81
96
|
counter.increment(count)
|
82
97
|
end
|
83
98
|
|
@@ -88,7 +103,9 @@ module Sourcify
|
|
88
103
|
end
|
89
104
|
|
90
105
|
def fix_counter_false_start(key)
|
91
|
-
|
106
|
+
return unless this_counter(key).just_started?
|
107
|
+
reset_attributes
|
108
|
+
@tokens, @false_start_backup = @false_start_backup.dup, nil if @false_start_backup
|
92
109
|
end
|
93
110
|
|
94
111
|
def other_counter(type)
|
@@ -101,22 +118,29 @@ module Sourcify
|
|
101
118
|
|
102
119
|
def construct_result_code
|
103
120
|
begin
|
104
|
-
code = 'proc ' +
|
121
|
+
code = 'proc ' + codified_tokens
|
105
122
|
eval(code) # TODO: any better way to check for completeness of proc code ??
|
106
|
-
@
|
107
|
-
|
108
|
-
|
123
|
+
if @body_matcher.call(code)
|
124
|
+
@results << code
|
125
|
+
raise Escape if @stop_on_newline or @lineno != 1
|
126
|
+
reset_attributes
|
127
|
+
end
|
109
128
|
rescue Exception
|
110
129
|
raise if $!.is_a?(Escape)
|
111
130
|
end
|
112
131
|
end
|
113
132
|
|
133
|
+
def codified_tokens
|
134
|
+
@tokens.map(&:last).join
|
135
|
+
end
|
136
|
+
|
114
137
|
def reset_attributes
|
115
138
|
@tokens = []
|
116
139
|
@lineno = 1
|
117
140
|
@heredoc, @dstring, @comment = nil
|
118
141
|
@do_end_counter = DoEndBlockCounter.new
|
119
142
|
@brace_counter = BraceBlockCounter.new
|
143
|
+
@rejecting_block = false
|
120
144
|
end
|
121
145
|
|
122
146
|
def offset_attributes
|
data/sourcify.gemspec
CHANGED
@@ -5,14 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sourcify}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.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-10-15}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{ngty77@gmail.com}
|
15
|
-
s.extensions = ["ext/sourcify/extconf.rb"]
|
16
15
|
s.extra_rdoc_files = [
|
17
16
|
"LICENSE",
|
18
17
|
"README.rdoc"
|
@@ -20,6 +19,7 @@ Gem::Specification.new do |s|
|
|
20
19
|
s.files = [
|
21
20
|
".document",
|
22
21
|
".gitignore",
|
22
|
+
".infinity_test",
|
23
23
|
"HISTORY.txt",
|
24
24
|
"LICENSE",
|
25
25
|
"README.rdoc",
|
@@ -27,6 +27,10 @@ Gem::Specification.new do |s|
|
|
27
27
|
"VERSION",
|
28
28
|
"lib/sourcify.rb",
|
29
29
|
"lib/sourcify/proc.rb",
|
30
|
+
"lib/sourcify/proc/methods.rb",
|
31
|
+
"lib/sourcify/proc/methods/source_location.rb",
|
32
|
+
"lib/sourcify/proc/methods/to_sexp.rb",
|
33
|
+
"lib/sourcify/proc/methods/to_source.rb",
|
30
34
|
"lib/sourcify/proc/parser.rb",
|
31
35
|
"lib/sourcify/proc/scanner.rb",
|
32
36
|
"lib/sourcify/proc/scanner.rl",
|
@@ -41,7 +45,10 @@ Gem::Specification.new do |s|
|
|
41
45
|
"spec/proc/created_on_the_fly_proc_spec.rb",
|
42
46
|
"spec/proc/others_spec.rb",
|
43
47
|
"spec/proc/readme",
|
48
|
+
"spec/proc/spec_helper.rb",
|
49
|
+
"spec/proc/to_sexp_from_multi_blocks_w_specified_attached_to_spec.rb",
|
44
50
|
"spec/proc/to_sexp_variables_spec.rb",
|
51
|
+
"spec/proc/to_sexp_w_specified_strip_enclosure_spec.rb",
|
45
52
|
"spec/proc/to_sexp_within_irb_spec.rb",
|
46
53
|
"spec/proc/to_source_from_braced_block_w_nested_braced_block_spec.rb",
|
47
54
|
"spec/proc/to_source_from_braced_block_w_nested_hash_spec.rb",
|
@@ -61,10 +68,19 @@ Gem::Specification.new do |s|
|
|
61
68
|
"spec/proc/to_source_from_do_end_block_wo_nesting_complication_spec.rb",
|
62
69
|
"spec/proc/to_source_from_multi_blocks_w_many_matches_spec.rb",
|
63
70
|
"spec/proc/to_source_from_multi_blocks_w_single_match_spec.rb",
|
71
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_many_matches_spec.rb",
|
72
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_no_match_spec.rb",
|
73
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_single_match_spec.rb",
|
74
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_attached_to_spec.rb",
|
75
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.rb",
|
76
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_no_match_spec.rb",
|
77
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_single_match_spec.rb",
|
78
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_ignore_nested_spec.rb",
|
64
79
|
"spec/proc/to_source_from_multi_do_end_blocks_w_single_match_spec.rb",
|
65
80
|
"spec/proc/to_source_magic_file_var_spec.rb",
|
66
81
|
"spec/proc/to_source_magic_line_var_spec.rb",
|
67
82
|
"spec/proc/to_source_variables_spec.rb",
|
83
|
+
"spec/proc/to_source_w_specified_strip_enclosure_spec.rb",
|
68
84
|
"spec/proc/to_source_within_irb_spec.rb",
|
69
85
|
"spec/proc_scanner/block_comment_spec.rb",
|
70
86
|
"spec/proc_scanner/double_colons_spec.rb",
|
@@ -75,6 +91,7 @@ Gem::Specification.new do |s|
|
|
75
91
|
"spec/proc_scanner/kw_do_alias2_spec.rb",
|
76
92
|
"spec/proc_scanner/per_line_comment_spec.rb",
|
77
93
|
"spec/proc_scanner/single_quote_str_spec.rb",
|
94
|
+
"spec/proc_scanner/slash_operator_spec.rb",
|
78
95
|
"spec/proc_scanner/spec_helper.rb",
|
79
96
|
"spec/spec_helper.rb"
|
80
97
|
]
|
@@ -87,6 +104,7 @@ Gem::Specification.new do |s|
|
|
87
104
|
s.test_files = [
|
88
105
|
"spec/proc_scanner/kw_do_alias1_spec.rb",
|
89
106
|
"spec/proc_scanner/single_quote_str_spec.rb",
|
107
|
+
"spec/proc_scanner/slash_operator_spec.rb",
|
90
108
|
"spec/proc_scanner/kw_do_alias2_spec.rb",
|
91
109
|
"spec/proc_scanner/double_colons_spec.rb",
|
92
110
|
"spec/proc_scanner/block_comment_spec.rb",
|
@@ -96,6 +114,8 @@ Gem::Specification.new do |s|
|
|
96
114
|
"spec/proc_scanner/spec_helper.rb",
|
97
115
|
"spec/proc_scanner/double_quote_str_wo_interpolation_spec.rb",
|
98
116
|
"spec/proc/to_source_from_do_end_block_w_nested_until_spec.rb",
|
117
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_single_match_spec.rb",
|
118
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_no_match_spec.rb",
|
99
119
|
"spec/proc/to_source_from_do_end_block_w_nested_begin_spec.rb",
|
100
120
|
"spec/proc/to_source_from_braced_block_w_nested_hash_spec.rb",
|
101
121
|
"spec/proc/created_on_the_fly_proc_spec.rb",
|
@@ -107,18 +127,28 @@ Gem::Specification.new do |s|
|
|
107
127
|
"spec/proc/to_sexp_within_irb_spec.rb",
|
108
128
|
"spec/proc/to_source_from_do_end_block_w_nested_module_spec.rb",
|
109
129
|
"spec/proc/to_source_from_do_end_block_w_nested_do_end_block_spec.rb",
|
130
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_attached_to_spec.rb",
|
110
131
|
"spec/proc/to_source_from_do_end_block_w_nested_method_spec.rb",
|
111
132
|
"spec/proc/to_source_from_do_end_block_w_nested_class_spec.rb",
|
112
133
|
"spec/proc/to_source_within_irb_spec.rb",
|
113
134
|
"spec/proc/to_source_from_do_end_block_w_nested_case_spec.rb",
|
114
135
|
"spec/proc/to_source_magic_line_var_spec.rb",
|
136
|
+
"spec/proc/to_sexp_w_specified_strip_enclosure_spec.rb",
|
137
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.rb",
|
115
138
|
"spec/proc/to_source_from_do_end_block_w_nested_literal_keyword_spec.rb",
|
116
139
|
"spec/proc/to_source_from_do_end_block_w_nested_unless_spec.rb",
|
140
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_no_match_spec.rb",
|
117
141
|
"spec/proc/others_spec.rb",
|
118
142
|
"spec/proc/19x_extras.rb",
|
143
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_many_matches_spec.rb",
|
119
144
|
"spec/proc/to_source_from_braced_block_w_nested_braced_block_spec.rb",
|
120
145
|
"spec/proc/to_source_from_do_end_block_wo_nesting_complication_spec.rb",
|
121
146
|
"spec/proc/to_source_variables_spec.rb",
|
147
|
+
"spec/proc/to_source_w_specified_strip_enclosure_spec.rb",
|
148
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_single_match_spec.rb",
|
149
|
+
"spec/proc/to_sexp_from_multi_blocks_w_specified_attached_to_spec.rb",
|
150
|
+
"spec/proc/to_source_from_multi_blocks_w_specified_ignore_nested_spec.rb",
|
151
|
+
"spec/proc/spec_helper.rb",
|
122
152
|
"spec/proc/to_sexp_variables_spec.rb",
|
123
153
|
"spec/proc/to_source_magic_file_var_spec.rb",
|
124
154
|
"spec/proc/to_source_from_do_end_block_w_nested_if_spec.rb",
|
@@ -133,17 +163,17 @@ Gem::Specification.new do |s|
|
|
133
163
|
|
134
164
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
135
165
|
s.add_runtime_dependency(%q<ruby2ruby>, [">= 1.2.5"])
|
166
|
+
s.add_runtime_dependency(%q<sexp_processor>, [">= 3.0.5"])
|
136
167
|
s.add_development_dependency(%q<bacon>, [">= 0"])
|
137
|
-
s.add_development_dependency(%q<otaku>, [">= 0.4.0"])
|
138
168
|
else
|
139
169
|
s.add_dependency(%q<ruby2ruby>, [">= 1.2.5"])
|
170
|
+
s.add_dependency(%q<sexp_processor>, [">= 3.0.5"])
|
140
171
|
s.add_dependency(%q<bacon>, [">= 0"])
|
141
|
-
s.add_dependency(%q<otaku>, [">= 0.4.0"])
|
142
172
|
end
|
143
173
|
else
|
144
174
|
s.add_dependency(%q<ruby2ruby>, [">= 1.2.5"])
|
175
|
+
s.add_dependency(%q<sexp_processor>, [">= 3.0.5"])
|
145
176
|
s.add_dependency(%q<bacon>, [">= 0"])
|
146
|
-
s.add_dependency(%q<otaku>, [">= 0.4.0"])
|
147
177
|
end
|
148
178
|
end
|
149
179
|
|
data/spec/proc/others_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
2
|
|
3
3
|
describe "Misc" do
|
4
4
|
|
@@ -12,6 +12,10 @@ describe "Misc" do
|
|
12
12
|
s_proc.should.be having_source('proc { :test }')
|
13
13
|
end
|
14
14
|
|
15
|
+
should "handle proc with '/' char" do
|
16
|
+
(lambda { @x1/2 }).should.be having_source('proc { @x1/2 }')
|
17
|
+
end
|
18
|
+
|
15
19
|
should "handle lexer bug in missing trailing chars after '=>' operator" do
|
16
20
|
# This example addresses bug @ http://redmine.ruby-lang.org/issues/show/3765
|
17
21
|
{
|
@@ -26,7 +30,7 @@ describe "Misc" do
|
|
26
30
|
}.values.last.should.be having_source('proc { :test }')
|
27
31
|
end
|
28
32
|
|
29
|
-
unless
|
33
|
+
unless has_parsetree?
|
30
34
|
should "raise Sourcify::CannotParseEvalCodeError when proc is created from eval" do
|
31
35
|
lambda { eval("proc {:test }").to_source }.should.
|
32
36
|
raise(Sourcify::CannotParseEvalCodeError)
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'spec_helper')
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'Proc#to_sexp w specified {:attached_to => ...}' do
|
4
|
+
|
5
|
+
# NOTE: We just want enough specs to show that handling of :attached_to
|
6
|
+
# works for Proc#to_sexp as well.
|
7
|
+
|
8
|
+
options = {:attached_to => /^.*?(\W|)watever(\W)/}
|
9
|
+
|
10
|
+
should 'handle no nesting on same line' do
|
11
|
+
b1 = lambda {|a| @x1+1 }; b2 = watever { @x1+2 }; b3 = lambda { @x1+3 }
|
12
|
+
b2.should.be having_sexp(
|
13
|
+
s(:iter,
|
14
|
+
s(:call, nil, :proc, s(:arglist)),
|
15
|
+
nil,
|
16
|
+
s(:call, s(:ivar, :@x1), :+, s(:arglist, s(:lit, 2)))),
|
17
|
+
options
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
should 'handle single level nesting on same line' do
|
22
|
+
b1 = lambda {|a| @x2+1 }; b2 = watever { lambda { @x2+2 } }
|
23
|
+
b2.should.be having_sexp(
|
24
|
+
s(:iter,
|
25
|
+
s(:call, nil, :proc, s(:arglist)),
|
26
|
+
nil,
|
27
|
+
s(:iter,
|
28
|
+
s(:call, nil, :lambda, s(:arglist)),
|
29
|
+
nil,
|
30
|
+
s(:call, s(:ivar, :@x2), :+, s(:arglist, s(:lit, 2))))),
|
31
|
+
options
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
should 'handle multi level nesting on same line' do
|
36
|
+
b2 = (lambda {|a| watever { lambda { @x3 } } }).call(1)
|
37
|
+
b2.should.be having_sexp(
|
38
|
+
s(:iter,
|
39
|
+
s(:call, nil, :proc, s(:arglist)),
|
40
|
+
nil,
|
41
|
+
s(:iter, s(:call, nil, :lambda, s(:arglist)), nil, s(:ivar, :@x3))),
|
42
|
+
options
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'Proc#to_sexp w specified {:strip_enclosure => ...}' do
|
4
|
+
|
5
|
+
describe '>> w true' do
|
6
|
+
|
7
|
+
options = {:strip_enclosure => true}
|
8
|
+
|
9
|
+
should 'strip enclosing proc wo arg' do
|
10
|
+
lambda { a+b }.should.be having_sexp(
|
11
|
+
s(:call,
|
12
|
+
s(:call, nil, :a, s(:arglist)),
|
13
|
+
:+,
|
14
|
+
s(:arglist, s(:call, nil, :b, s(:arglist)))),
|
15
|
+
options
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
should 'strip enclosing proc w arg' do
|
20
|
+
lambda {|a| a+b }.should.be having_sexp(
|
21
|
+
s(:call,
|
22
|
+
s(:lvar, :a),
|
23
|
+
:+,
|
24
|
+
s(:arglist, s(:call, nil, :b, s(:arglist)))),
|
25
|
+
options
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '>> w false' do
|
32
|
+
|
33
|
+
options = {:strip_enclosure => false}
|
34
|
+
|
35
|
+
should 'not strip enclosing proc wo arg' do
|
36
|
+
lambda { a+b }.should.be having_sexp(
|
37
|
+
s(:iter,
|
38
|
+
s(:call, nil, :proc, s(:arglist)),
|
39
|
+
nil,
|
40
|
+
s(:call,
|
41
|
+
s(:call, nil, :a, s(:arglist)),
|
42
|
+
:+,
|
43
|
+
s(:arglist, s(:call, nil, :b, s(:arglist))))),
|
44
|
+
options
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'not strip enclosing proc w arg' do
|
49
|
+
lambda {|a| a+b }.should.be having_sexp(
|
50
|
+
s(:iter,
|
51
|
+
s(:call, nil, :proc, s(:arglist)),
|
52
|
+
s(:lasgn, :a),
|
53
|
+
s(:call, s(:lvar, :a), :+, s(:arglist, s(:call, nil, :b, s(:arglist))))),
|
54
|
+
options
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -1,4 +1,4 @@
|
|
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 { ... } block (w nested hash)" do
|
4
4
|
|
@@ -27,7 +27,7 @@ describe "Proc#to_source from { ... } block (w nested hash)" do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if RUBY_VERSION.include?('1.9.')
|
30
|
-
require File.join(File.dirname(__FILE__), '19x_extras')
|
30
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '19x_extras')
|
31
31
|
behaves_like 'Proc#to_source from { ... } block (1.9.*)'
|
32
32
|
end
|
33
33
|
|