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,149 @@
|
|
1
|
+
Sourcify.require_rb('proc', 'parser', 'raw_scanner_extensions')
|
2
|
+
|
3
|
+
module Sourcify
|
4
|
+
module Proc
|
5
|
+
class Parser
|
6
|
+
module RawScanner #:nodoc:all
|
7
|
+
|
8
|
+
%%{
|
9
|
+
|
10
|
+
machine scanner;
|
11
|
+
include common 'common.rl';
|
12
|
+
|
13
|
+
|
14
|
+
## MACHINE >> New statement
|
15
|
+
new_statement := |*
|
16
|
+
|
17
|
+
(kw_for | kw_while | kw_until) . ^vchar => {
|
18
|
+
push(:kw_do_alias2, ts, te)
|
19
|
+
increment_counter(:do_end, 0..1)
|
20
|
+
fgoto main;
|
21
|
+
};
|
22
|
+
|
23
|
+
(
|
24
|
+
((kw_class | kw_module | kw_def | kw_begin | kw_case | kw_if | kw_unless) . ^vchar) |
|
25
|
+
(kw_class . ospaces . '<<' . ospaces . ^newline+)
|
26
|
+
) => {
|
27
|
+
push(:kw_do_alias1, ts, te)
|
28
|
+
increment_counter(:do_end, 1)
|
29
|
+
fgoto main;
|
30
|
+
};
|
31
|
+
|
32
|
+
ospaces => { push(:space, ts, te) };
|
33
|
+
any => { fhold; fgoto main; };
|
34
|
+
|
35
|
+
*|;
|
36
|
+
|
37
|
+
|
38
|
+
## MACHINE >> Main
|
39
|
+
main := |*
|
40
|
+
|
41
|
+
## == Start/end of do..end block
|
42
|
+
|
43
|
+
kw_do => {
|
44
|
+
push(:kw_do, ts, te)
|
45
|
+
increment_counter(:do_end)
|
46
|
+
fgoto new_statement;
|
47
|
+
};
|
48
|
+
|
49
|
+
kw_end => {
|
50
|
+
push(:kw_end, ts, te)
|
51
|
+
decrement_counter(:do_end)
|
52
|
+
};
|
53
|
+
|
54
|
+
## == Start/end of {...} block
|
55
|
+
|
56
|
+
lbrace => {
|
57
|
+
push(:lbrace, ts, te)
|
58
|
+
increment_counter(:brace)
|
59
|
+
};
|
60
|
+
|
61
|
+
rbrace => {
|
62
|
+
push(:rbrace, ts, te)
|
63
|
+
decrement_counter(:brace)
|
64
|
+
};
|
65
|
+
|
66
|
+
assoc => {
|
67
|
+
push(:assoc, ts, te)
|
68
|
+
fix_counter_false_start(:brace)
|
69
|
+
};
|
70
|
+
|
71
|
+
label => {
|
72
|
+
push_label(ts, te)
|
73
|
+
fix_counter_false_start(:brace)
|
74
|
+
};
|
75
|
+
|
76
|
+
## == New statement
|
77
|
+
|
78
|
+
newline => {
|
79
|
+
push(:newline, ts, te)
|
80
|
+
increment_lineno
|
81
|
+
fgoto new_statement;
|
82
|
+
};
|
83
|
+
|
84
|
+
smcolon | lparen | assgn | kw_then | comma => {
|
85
|
+
push(:newline_alias, ts, te)
|
86
|
+
fgoto new_statement;
|
87
|
+
};
|
88
|
+
|
89
|
+
## == Comment
|
90
|
+
|
91
|
+
'#' => {
|
92
|
+
fgoto per_line_comment;
|
93
|
+
};
|
94
|
+
|
95
|
+
newline . '=begin' . ospaces . (ospaces . ^newline+)* . newline => {
|
96
|
+
push_comment(ts, te)
|
97
|
+
increment_lineno
|
98
|
+
fgoto block_comment;
|
99
|
+
};
|
100
|
+
|
101
|
+
## == Strings
|
102
|
+
|
103
|
+
('<<' | '<<-') . ["']? . (const | var) . ["']? . newline => {
|
104
|
+
push_heredoc(ts, te)
|
105
|
+
increment_lineno
|
106
|
+
fgoto heredoc;
|
107
|
+
};
|
108
|
+
|
109
|
+
('"' | "'" | '`' | '%') => {
|
110
|
+
fhold; fgoto string;
|
111
|
+
};
|
112
|
+
|
113
|
+
'/' => {
|
114
|
+
if preceded_with?(:char, :digit, :var, :const, :symbol, :dstring, :sstring, ')', ']', '}')
|
115
|
+
push(:op, ts, te)
|
116
|
+
else
|
117
|
+
fhold; fgoto string;
|
118
|
+
end
|
119
|
+
};
|
120
|
+
|
121
|
+
## == Misc
|
122
|
+
|
123
|
+
var => { push(:var, ts, te) };
|
124
|
+
bslash => { push(:bslash, ts, te) };
|
125
|
+
const => { push(:const, ts, te) };
|
126
|
+
symbol => { push(:symbol, ts, te) };
|
127
|
+
mspaces => { push(:space, ts, te) };
|
128
|
+
[0-9] => { push(:digit, ts, te) };
|
129
|
+
lower => { push(:char, ts, te) };
|
130
|
+
any => { push(:any, ts, te) };
|
131
|
+
|
132
|
+
*|;
|
133
|
+
|
134
|
+
}%%
|
135
|
+
%% write data;
|
136
|
+
|
137
|
+
extend Extensions
|
138
|
+
|
139
|
+
def self.execute!
|
140
|
+
data = @data
|
141
|
+
eof = data.length
|
142
|
+
%% write init;
|
143
|
+
%% write exec;
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
Sourcify.require_rb('common', 'parser', 'raw_scanner', 'extensions')
|
2
|
+
|
3
|
+
module Sourcify
|
4
|
+
module Proc
|
5
|
+
class Parser
|
6
|
+
module RawScanner #:nodoc:all
|
7
|
+
module Extensions
|
8
|
+
|
9
|
+
include Common::Parser::RawScanner::Extensions
|
10
|
+
class DoEndBlockCounter < Common::Parser::RawScanner::Counter; end
|
11
|
+
class BraceBlockCounter < Common::Parser::RawScanner::Counter; end
|
12
|
+
|
13
|
+
def fix_counter_false_start(key)
|
14
|
+
return unless this_counter(key).just_started?
|
15
|
+
return unless really_false_started?
|
16
|
+
reset_attributes
|
17
|
+
@tokens, @false_start_backup = @false_start_backup.dup, nil if @false_start_backup
|
18
|
+
end
|
19
|
+
|
20
|
+
def increment_counter(key, count = 1)
|
21
|
+
return if other_counter(key).started?
|
22
|
+
unless (counter = this_counter(key)).started?
|
23
|
+
return if (@rejecting_block = codified_tokens !~ @start_pattern)
|
24
|
+
@false_start_backup = @tokens.dup if key == :brace
|
25
|
+
offset_attributes
|
26
|
+
end
|
27
|
+
counter.increment(count)
|
28
|
+
end
|
29
|
+
|
30
|
+
def decrement_counter(key)
|
31
|
+
return unless (counter = this_counter(key)).started?
|
32
|
+
counter.decrement
|
33
|
+
construct_result_code if counter.balanced?
|
34
|
+
end
|
35
|
+
|
36
|
+
def other_counter(type)
|
37
|
+
{:do_end => @brace_counter, :brace => @do_end_counter}[type]
|
38
|
+
end
|
39
|
+
|
40
|
+
def this_counter(type)
|
41
|
+
{:brace => @brace_counter, :do_end => @do_end_counter}[type]
|
42
|
+
end
|
43
|
+
|
44
|
+
def construct_result_code
|
45
|
+
code = %Q(proc #{codified_tokens}).strip
|
46
|
+
|
47
|
+
begin
|
48
|
+
if valid?(code) && @body_matcher.call(code)
|
49
|
+
@results << code
|
50
|
+
raise Escape if @stop_on_newline or @lineno != 1
|
51
|
+
reset_attributes
|
52
|
+
end
|
53
|
+
rescue Exception
|
54
|
+
raise if $!.is_a?(Escape)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def really_false_started?
|
59
|
+
valid?(%Q(#{codified_tokens} 1}), :hash)
|
60
|
+
end
|
61
|
+
|
62
|
+
def reset_attributes
|
63
|
+
@do_end_counter = DoEndBlockCounter.new
|
64
|
+
@brace_counter = BraceBlockCounter.new
|
65
|
+
super
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
Sourcify.require_rb('proc', 'parser', 'raw_scanner')
|
2
|
+
|
1
3
|
module Sourcify
|
2
4
|
module Proc
|
3
5
|
class Parser #:nodoc:all
|
4
|
-
class
|
6
|
+
class Scanner
|
5
7
|
class << self
|
6
8
|
|
7
9
|
def process(source_code, opts, &matcher)
|
@@ -28,12 +30,13 @@ module Sourcify
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def rscan(str, opts)
|
31
|
-
results =
|
33
|
+
results = RawScanner.process(str, opts) || []
|
32
34
|
return results if opts[:ignore_nested]
|
33
35
|
results.map do |outer|
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
[
|
37
|
+
outer,
|
38
|
+
rscan(outer.sub(/^proc\s*(do|\{)/,''), opts.merge(:stop_on_newline => true))
|
39
|
+
]
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
@@ -41,3 +44,4 @@ module Sourcify
|
|
41
44
|
end
|
42
45
|
end
|
43
46
|
end
|
47
|
+
end
|
@@ -1,33 +1,8 @@
|
|
1
1
|
module Sourcify
|
2
2
|
module Proc
|
3
3
|
class Parser #:nodoc:all
|
4
|
-
|
5
|
-
|
6
|
-
def line
|
7
|
-
super.pred
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_s
|
11
|
-
case file
|
12
|
-
when /\(irb\)/ then from_irb_to_s
|
13
|
-
else from_file_to_s
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def from_file_to_s
|
18
|
-
File.open(file, 'r') do |fh|
|
19
|
-
fh.extend(File::Tail).forward(line)
|
20
|
-
fh.readlines.join
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def from_irb_to_s
|
25
|
-
# Really owe it to Florian Groß's solution @ http://rubyquiz.com/quiz38.html ...
|
26
|
-
# anyway, note that we use *line.succ* instead of *line* here.
|
27
|
-
IRB.CurrentContext.io.line(line.succ .. -1).join
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
4
|
+
Sourcify.require_rb('common', 'parser', 'source_code')
|
5
|
+
SourceCode = Common::Parser::SourceCode
|
31
6
|
end
|
32
7
|
end
|
33
8
|
end
|
data/lib/sourcify/version.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe "Misc (from def..end block)" do
|
4
|
+
|
5
|
+
should 'handle accessing #to_sexp after #to_source' do
|
6
|
+
def m1; x; end
|
7
|
+
(m = method(:m1)).to_source
|
8
|
+
m.should.be having_sexp(
|
9
|
+
s(:defn, :m1, s(:args), s(:scope, s(:block, s(:call, nil, :x, s(:arglist)))))
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
should 'handle accessing #to_source after #to_sexp' do
|
14
|
+
def m2; x; end
|
15
|
+
(m = method(:m2)).to_sexp
|
16
|
+
m.should.be having_source(%(
|
17
|
+
def m2; x; end
|
18
|
+
))
|
19
|
+
end
|
20
|
+
|
21
|
+
should "handle body with '/' char" do
|
22
|
+
def m3; x/2; end
|
23
|
+
method(:m3).should.be having_source(%(
|
24
|
+
def m3; x/2; end
|
25
|
+
))
|
26
|
+
end
|
27
|
+
|
28
|
+
should "handle lexer bug in missing trailing chars after '=>' operator" do
|
29
|
+
# This example addresses bug @ http://redmine.ruby-lang.org/issues/show/3765
|
30
|
+
{
|
31
|
+
__LINE__ => (def m4; x; end; method(:m4))
|
32
|
+
}.values.last.should.be having_source(%(
|
33
|
+
def m4; x; end
|
34
|
+
))
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'raise Sourcify::CannotFindSourceLocationError when Method#source_location is nil' do
|
38
|
+
lambda { 1.method(:to_s).to_source }.should.
|
39
|
+
raise(Sourcify::CannotFindSourceLocationError)
|
40
|
+
end
|
41
|
+
|
42
|
+
unless has_parsetree?
|
43
|
+
should "raise Sourcify::CannotParseEvalCodeError when method is created from eval" do
|
44
|
+
lambda { eval("def m5; x; end; method(:m5)").to_source }.should.
|
45
|
+
raise(Sourcify::CannotParseEvalCodeError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe "Misc (from define_method)" do
|
4
|
+
|
5
|
+
before { @thing = Object.new }
|
6
|
+
|
7
|
+
should 'handle accessing #to_sexp after #to_source' do
|
8
|
+
blk = lambda { x }
|
9
|
+
@thing.class.send(:define_method, :m1, &blk)
|
10
|
+
(m = @thing.method(:m1)).to_source
|
11
|
+
m.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 'handle accessing #to_source after #to_sexp' do
|
17
|
+
blk = lambda { x }
|
18
|
+
@thing.class.send(:define_method, :m2, &blk)
|
19
|
+
(m = @thing.method(:m2)).to_sexp
|
20
|
+
m.should.be having_source(%(
|
21
|
+
def m2; x; end
|
22
|
+
))
|
23
|
+
end
|
24
|
+
|
25
|
+
should "handle body with '/' char" do
|
26
|
+
blk = lambda { x / 2 }
|
27
|
+
@thing.class.send(:define_method, :m3, &blk)
|
28
|
+
@thing.method(:m3).should.be having_source(%(
|
29
|
+
def m3; x / 2; end
|
30
|
+
))
|
31
|
+
end
|
32
|
+
|
33
|
+
should "handle lexer bug in missing trailing chars after '=>' operator" do
|
34
|
+
# This example addresses bug @ http://redmine.ruby-lang.org/issues/show/3765
|
35
|
+
hash = {
|
36
|
+
:x => lambda { x }
|
37
|
+
}
|
38
|
+
@thing.class.send(:define_method, :m4, &(hash[:x]))
|
39
|
+
@thing.method(:m4).should.be having_source(%(
|
40
|
+
def m4; x; end
|
41
|
+
))
|
42
|
+
end
|
43
|
+
|
44
|
+
should "handle lexer bug in missing trailing chars after '=>' operator" do
|
45
|
+
# This example addresses bug @ http://redmine.ruby-lang.org/issues/show/3765
|
46
|
+
hash = {
|
47
|
+
:blk => lambda do x end
|
48
|
+
}
|
49
|
+
@thing.class.send(:define_method, :m5, &(hash[:blk]))
|
50
|
+
@thing.method(:m5).should.be having_source(%(
|
51
|
+
def m5; x; end
|
52
|
+
))
|
53
|
+
end
|
54
|
+
|
55
|
+
unless has_parsetree?
|
56
|
+
should "raise Sourcify::CannotParseEvalCodeError when method is created from eval" do
|
57
|
+
lambda { eval("klass = Class.new { define_method(:m6){ x }; }; klass.new.method(:m6)").to_source }.
|
58
|
+
should.raise(Sourcify::CannotParseEvalCodeError)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
unless has_parsetree?
|
4
|
+
describe "Method's raw scanner > block comment (=begin ... =end)" do
|
5
|
+
extend Sourcify::Method::Parser::RawScanner::Spec::GenericSupport
|
6
|
+
behaves_like "Block comment (=begin ... =end)"
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
unless has_parsetree?
|
4
|
+
describe "Method's raw scanner > double quote strings (w interpolation)" do
|
5
|
+
extend Sourcify::Method::Parser::RawScanner::Spec::GenericSupport
|
6
|
+
behaves_like "Double quote strings (w interpolation)"
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
unless has_parsetree?
|
4
|
+
describe "Method's raw scanner > double quote strings (wo interpolation)" do
|
5
|
+
extend Sourcify::Method::Parser::RawScanner::Spec::GenericSupport
|
6
|
+
behaves_like "Double quote strings (wo interpolation)"
|
7
|
+
end
|
8
|
+
end
|