rcodetools 0.4.0.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/CHANGES +18 -0
- data/README +34 -0
- data/README.emacs +54 -0
- data/README.method_analysis +13 -0
- data/README.vim +84 -0
- data/README.xmpfilter +202 -0
- data/Rakefile +123 -0
- data/Rakefile.method_analysis +30 -0
- data/THANKS +6 -0
- data/bin/rct-complete +37 -0
- data/bin/rct-doc +50 -0
- data/bin/rct-meth-args +392 -0
- data/bin/xmpfilter +75 -0
- data/icicles-rcodetools.el +31 -0
- data/lib/method_analyzer.rb +107 -0
- data/lib/rcodetools/completion.rb +282 -0
- data/lib/rcodetools/doc.rb +176 -0
- data/lib/rcodetools/options.rb +83 -0
- data/lib/rcodetools/xmpfilter.rb +208 -0
- data/lib/rcodetools/xmptestunitfilter.rb +197 -0
- data/rcodetools.el +162 -0
- data/rcodetools.vim +118 -0
- data/setup.rb +1585 -0
- data/test/data/add_markers-input.rb +2 -0
- data/test/data/add_markers-output.rb +2 -0
- data/test/data/bindings-input.rb +26 -0
- data/test/data/bindings-output.rb +31 -0
- data/test/data/completion-input.rb +1 -0
- data/test/data/completion-output.rb +2 -0
- data/test/data/completion_emacs-input.rb +1 -0
- data/test/data/completion_emacs-output.rb +5 -0
- data/test/data/completion_emacs_icicles-input.rb +1 -0
- data/test/data/completion_emacs_icicles-output.rb +5 -0
- data/test/data/doc-input.rb +1 -0
- data/test/data/doc-output.rb +1 -0
- data/test/data/method_analyzer-data.rb +33 -0
- data/test/data/method_args.data.rb +106 -0
- data/test/data/no_warnings-input.rb +3 -0
- data/test/data/no_warnings-output.rb +4 -0
- data/test/data/refe-input.rb +1 -0
- data/test/data/refe-output.rb +1 -0
- data/test/data/ri-input.rb +1 -0
- data/test/data/ri-output.rb +1 -0
- data/test/data/ri_emacs-input.rb +1 -0
- data/test/data/ri_emacs-output.rb +1 -0
- data/test/data/ri_vim-input.rb +1 -0
- data/test/data/ri_vim-output.rb +1 -0
- data/test/data/rspec-input.rb +48 -0
- data/test/data/rspec-output.rb +52 -0
- data/test/data/rspec_poetry-input.rb +48 -0
- data/test/data/rspec_poetry-output.rb +52 -0
- data/test/data/simple_annotation-input.rb +8 -0
- data/test/data/simple_annotation-output.rb +8 -0
- data/test/data/unit_test-input.rb +50 -0
- data/test/data/unit_test-output.rb +52 -0
- data/test/data/unit_test_poetry-input.rb +50 -0
- data/test/data/unit_test_poetry-output.rb +52 -0
- data/test/test_completion.rb +467 -0
- data/test/test_doc.rb +403 -0
- data/test/test_functional.rb +18 -0
- data/test/test_method_analyzer.rb +99 -0
- data/test/test_method_args.rb +134 -0
- data/test/test_run.rb +41 -0
- data/test/test_xmpfilter.rb +36 -0
- data/test/test_xmptestunitfilter.rb +84 -0
- metadata +139 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
class X
|
3
|
+
Y = Struct.new(:a)
|
4
|
+
def foo(b); b ? Y.new(2) : 2 end
|
5
|
+
def bar; raise "No good" end
|
6
|
+
def baz; nil end
|
7
|
+
def fubar(x); x ** 2.0 + 1 end
|
8
|
+
def babar; [1,2] end
|
9
|
+
A = 1
|
10
|
+
A = 1
|
11
|
+
def difftype() [1, "s"] end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
require 'test/unit'
|
16
|
+
class Test_X < Test::Unit::TestCase
|
17
|
+
def setup
|
18
|
+
@o = X.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_foo
|
22
|
+
@o.foo(true) # =>
|
23
|
+
@o.foo(true).a # =>
|
24
|
+
@o.foo(false) # =>
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_bar
|
28
|
+
@o.bar # =>
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_baz
|
32
|
+
@o.baz # =>
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_babar
|
36
|
+
@o.babar # =>
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_fubar
|
40
|
+
@o.fubar(10) # =>
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_difftype
|
44
|
+
for x in @o.difftype
|
45
|
+
x # =>
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
class X
|
3
|
+
Y = Struct.new(:a)
|
4
|
+
def foo(b); b ? Y.new(2) : 2 end
|
5
|
+
def bar; raise "No good" end
|
6
|
+
def baz; nil end
|
7
|
+
def fubar(x); x ** 2.0 + 1 end
|
8
|
+
def babar; [1,2] end
|
9
|
+
A = 1
|
10
|
+
A = 1 # !> already initialized constant A
|
11
|
+
def difftype() [1, "s"] end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
require 'test/unit'
|
16
|
+
class Test_X < Test::Unit::TestCase
|
17
|
+
def setup
|
18
|
+
@o = X.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_foo
|
22
|
+
assert_kind_of(X::Y, @o.foo(true))
|
23
|
+
assert_equal("#<struct X::Y a=2>", @o.foo(true).inspect)
|
24
|
+
assert_equal(2, @o.foo(true).a)
|
25
|
+
assert_equal(2, @o.foo(false))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_bar
|
29
|
+
assert_raise(RuntimeError){@o.bar}
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_baz
|
33
|
+
assert_nil(@o.baz)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_babar
|
37
|
+
assert_equal([1, 2], @o.babar)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_fubar
|
41
|
+
assert_in_delta(101.0, @o.fubar(10), 0.0001)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_difftype
|
45
|
+
for x in @o.difftype
|
46
|
+
#xmpfilter: WARNING!! extra values ignored
|
47
|
+
assert_equal(1, x)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
class X
|
3
|
+
Y = Struct.new(:a)
|
4
|
+
def foo(b); b ? Y.new(2) : 2 end
|
5
|
+
def bar; raise "No good" end
|
6
|
+
def baz; nil end
|
7
|
+
def fubar(x); x ** 2.0 + 1 end
|
8
|
+
def babar; [1,2] end
|
9
|
+
A = 1
|
10
|
+
A = 1
|
11
|
+
def difftype() [1, "s"] end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
require 'test/unit'
|
16
|
+
class Test_X < Test::Unit::TestCase
|
17
|
+
def setup
|
18
|
+
@o = X.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_foo
|
22
|
+
@o.foo(true) # =>
|
23
|
+
@o.foo(true).a # =>
|
24
|
+
@o.foo(false) # =>
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_bar
|
28
|
+
@o.bar # =>
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_baz
|
32
|
+
@o.baz # =>
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_babar
|
36
|
+
@o.babar # =>
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_fubar
|
40
|
+
@o.fubar(10) # =>
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_difftype
|
44
|
+
for x in @o.difftype
|
45
|
+
x # =>
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
class X
|
3
|
+
Y = Struct.new(:a)
|
4
|
+
def foo(b); b ? Y.new(2) : 2 end
|
5
|
+
def bar; raise "No good" end
|
6
|
+
def baz; nil end
|
7
|
+
def fubar(x); x ** 2.0 + 1 end
|
8
|
+
def babar; [1,2] end
|
9
|
+
A = 1
|
10
|
+
A = 1 # !> already initialized constant A
|
11
|
+
def difftype() [1, "s"] end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
require 'test/unit'
|
16
|
+
class Test_X < Test::Unit::TestCase
|
17
|
+
def setup
|
18
|
+
@o = X.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_foo
|
22
|
+
assert_kind_of X::Y, @o.foo(true)
|
23
|
+
assert_equal "#<struct X::Y a=2>", @o.foo(true).inspect
|
24
|
+
assert_equal 2, @o.foo(true).a
|
25
|
+
assert_equal 2, @o.foo(false)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_bar
|
29
|
+
assert_raise(RuntimeError){@o.bar}
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_baz
|
33
|
+
assert_nil @o.baz
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_babar
|
37
|
+
assert_equal [1, 2], @o.babar
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_fubar
|
41
|
+
assert_in_delta 101.0, @o.fubar(10), 0.0001
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_difftype
|
45
|
+
for x in @o.difftype
|
46
|
+
#xmpfilter: WARNING!! extra values ignored
|
47
|
+
assert_equal 1, x
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,467 @@
|
|
1
|
+
$: << ".." << "../lib"
|
2
|
+
require 'rcodetools/completion'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestXMPCompletionFilter < Test::Unit::TestCase
|
6
|
+
def doit(code, lineno, column=nil, options={})
|
7
|
+
xmp = XMPCompletionFilter.new options
|
8
|
+
xmp.candidates(code, lineno, column).sort
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_complete_method__simple
|
12
|
+
assert_equal(["length"], doit('"a".lengt', 1))
|
13
|
+
assert_equal(["length"], doit('`echo a`.lengt', 1))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_complete_method__in_arg
|
17
|
+
assert_equal(["length"], doit('print("a".lengt)', 1, 15))
|
18
|
+
assert_equal(["length"], doit("print('a'.lengt)", 1, 15))
|
19
|
+
assert_equal(["length"], doit("((a, b = 1 + 'a'.lengt))", 1, 22))
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_complete_method__in_method
|
23
|
+
assert_equal(["length"], doit(<<EOC, 2))
|
24
|
+
def hoge
|
25
|
+
"a".lengt
|
26
|
+
end
|
27
|
+
hoge
|
28
|
+
EOC
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_complete_method__in_not_passing_method
|
32
|
+
## FIXME I do not know how to handle not-passing method!!
|
33
|
+
assert_equal([], doit(<<EOC, 2))
|
34
|
+
def hoge
|
35
|
+
"a".lengt
|
36
|
+
end
|
37
|
+
EOC
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_complete_singleton_method
|
41
|
+
assert_equal(["aaaaa", "aaaab"], doit(<<EOC, 6))
|
42
|
+
a = 'a'
|
43
|
+
def a.aaaaa
|
44
|
+
end
|
45
|
+
def a.aaaab
|
46
|
+
end
|
47
|
+
a.aa
|
48
|
+
EOC
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_complete_global_variable
|
52
|
+
assert_equal(["$hoge"], doit(<<EOC, 2))
|
53
|
+
$hoge = 100
|
54
|
+
$ho
|
55
|
+
EOC
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_complete_global_variable__with_class
|
59
|
+
assert_equal(["open"], doit(<<EOC, 2))
|
60
|
+
$hoge = File
|
61
|
+
$hoge.op
|
62
|
+
EOC
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def test_complete_instance_variable
|
67
|
+
assert_equal(["@hoge"], doit(<<EOC, 2))
|
68
|
+
@hoge = 100
|
69
|
+
@ho
|
70
|
+
EOC
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_complete_class_variable_module
|
74
|
+
assert_equal(["@@hoge"], doit(<<EOC, 3))
|
75
|
+
module X
|
76
|
+
@@hoge = 100
|
77
|
+
@@ho
|
78
|
+
end
|
79
|
+
EOC
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_complete_class_variable__in_class
|
83
|
+
assert_equal(["@@hoge"], doit(<<EOC, 3))
|
84
|
+
class X
|
85
|
+
@@hoge = 100
|
86
|
+
@@ho
|
87
|
+
end
|
88
|
+
EOC
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_complete_class_variable__toplevel
|
92
|
+
assert_equal(["@@hoge"], doit(<<EOC, 2))
|
93
|
+
@@hoge = 100
|
94
|
+
@@ho
|
95
|
+
EOC
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_complete_class_variable__in_method
|
99
|
+
assert_equal(["@@hoge"], doit(<<EOC, 4))
|
100
|
+
class Foo
|
101
|
+
def foo
|
102
|
+
@@hoge = 100
|
103
|
+
@@ho
|
104
|
+
end
|
105
|
+
end
|
106
|
+
Foo.new.foo
|
107
|
+
EOC
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_complete_constant__nested
|
111
|
+
assert_equal(["Stat"], doit('File::Sta',1))
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_complete_class_method
|
115
|
+
assert_equal(["popen"], doit('File::pop',1))
|
116
|
+
assert_equal(["popen"], doit('::File::pop',1))
|
117
|
+
|
118
|
+
assert_equal(["popen"], doit('File.pop',1))
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def test_complete_constant__in_class
|
123
|
+
assert_equal(["Fixclass", "Fixnum"], doit(<<EOC, 3))
|
124
|
+
class Fixclass
|
125
|
+
class Bar
|
126
|
+
Fix
|
127
|
+
end
|
128
|
+
end
|
129
|
+
EOC
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
def test_complete_toplevel_constant
|
134
|
+
assert_equal(["Fixnum"], doit(<<EOC,3))
|
135
|
+
class Foo
|
136
|
+
class Fixnum
|
137
|
+
::Fixn
|
138
|
+
end
|
139
|
+
end
|
140
|
+
EOC
|
141
|
+
|
142
|
+
assert_equal(["Fixnum"], doit(<<EOC,3))
|
143
|
+
class Foo
|
144
|
+
class Fixnum
|
145
|
+
::Foo::Fixn
|
146
|
+
end
|
147
|
+
end
|
148
|
+
EOC
|
149
|
+
|
150
|
+
assert_equal(["Bar"], doit(<<EOC,5))
|
151
|
+
class Foo
|
152
|
+
class Bar
|
153
|
+
end
|
154
|
+
end
|
155
|
+
::Foo::B
|
156
|
+
EOC
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_bare_word__local_variable
|
160
|
+
assert_equal(["aaaaaxx"], doit(<<EOC,2))
|
161
|
+
aaaaaxx = 1
|
162
|
+
aaaa
|
163
|
+
EOC
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_bare_word__method
|
167
|
+
assert_equal(["trace_var"], doit("trace",1))
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_bare_word__constant
|
171
|
+
assert_equal(["Fixnum"], doit("Fixn",1))
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_bare_word__method_in_class
|
175
|
+
assert_equal(["attr_accessor"], doit(<<EOC,2))
|
176
|
+
class X
|
177
|
+
attr_acc
|
178
|
+
end
|
179
|
+
EOC
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_bare_word__public_method
|
183
|
+
assert_equal(["hoge"], doit(<<EOC,4))
|
184
|
+
class X
|
185
|
+
def hoge() end
|
186
|
+
def boke
|
187
|
+
hog
|
188
|
+
end
|
189
|
+
new.boke
|
190
|
+
end
|
191
|
+
EOC
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_bare_word__private_method
|
195
|
+
assert_equal(["hoge"], doit(<<EOC,5))
|
196
|
+
class X
|
197
|
+
def hoge() end
|
198
|
+
private :hoge
|
199
|
+
def boke
|
200
|
+
hog
|
201
|
+
end
|
202
|
+
new.boke
|
203
|
+
end
|
204
|
+
EOC
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_complete_symbol
|
208
|
+
assert_equal([":vccaex"], doit(<<EOC,2))
|
209
|
+
a = :vccaex
|
210
|
+
:vcca
|
211
|
+
EOC
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
#### tricky testcases
|
216
|
+
def test_two_pass
|
217
|
+
assert_equal(["inspect"], doit(<<EOC,2))
|
218
|
+
[1, "a"].each do |x|
|
219
|
+
x.inspec
|
220
|
+
end
|
221
|
+
EOC
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_string
|
225
|
+
assert_equal(["inspect"], doit('"()".inspe',1))
|
226
|
+
assert_equal(["inspect"], doit('`echo ()`.inspe',1))
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_not_last_line
|
230
|
+
assert_equal(["inspect"], doit(<<EOC,1))
|
231
|
+
"".inspe
|
232
|
+
1
|
233
|
+
EOC
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_column
|
237
|
+
assert_equal(["length"], doit('print("a".lengt + "b".size)', 1, 15))
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_method_chain__String
|
241
|
+
assert_equal(["length"], doit('"a".upcase.capitalize.leng', 1))
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_method_chain__Fixnum
|
245
|
+
assert_equal(["length"], doit('1.to_s.upcase.leng', 1))
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_multi_line__do
|
249
|
+
assert_equal(["each_with_index"], doit(<<EOC, 1, 16))
|
250
|
+
[].each_with_ind do |x|
|
251
|
+
end
|
252
|
+
EOC
|
253
|
+
assert_equal(["each_with_index"], doit(<<EOC, 1, 16))
|
254
|
+
[].each_with_ind()do |x|
|
255
|
+
end
|
256
|
+
EOC
|
257
|
+
assert_equal(["each_with_index"], doit(<<EOC, 1, 16))
|
258
|
+
[].each_with_ind do |x,y| end
|
259
|
+
EOC
|
260
|
+
assert_equal(["each_with_index"], doit(<<EOC, 1, 16))
|
261
|
+
[1].each_with_index do |x,y| [].each do end end
|
262
|
+
EOC
|
263
|
+
assert_equal(["each_with_index"], doit(<<EOC, 1, 16))
|
264
|
+
[].each_with_ind ; do-do
|
265
|
+
EOC
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_multi_line__braces
|
269
|
+
assert_equal(["each_with_index"], doit(<<EOC, 1, 16))
|
270
|
+
[].each_with_ind { |x|
|
271
|
+
}
|
272
|
+
EOC
|
273
|
+
assert_equal(["each_with_index"], doit(<<EOC, 1, 16))
|
274
|
+
[].each_with_ind(){ |x|
|
275
|
+
}
|
276
|
+
EOC
|
277
|
+
assert_equal(["each_with_index"], doit(<<EOC, 1, 16))
|
278
|
+
[].each_with_ind {|x,y| }
|
279
|
+
EOC
|
280
|
+
assert_equal(["each_with_index"], doit(<<EOC, 1, 16))
|
281
|
+
[1].each_with_in {|x,y| [].each { }}
|
282
|
+
EOC
|
283
|
+
assert_equal(["each_with_index"], doit(<<EOC, 1, 20))
|
284
|
+
{ [1].each_with_inde {|x,y| [].each { }},1}
|
285
|
+
|
286
|
+
EOC
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_multi_line__brackets
|
290
|
+
assert_equal(["each_with_index"], doit(<<EOC, 1, 20))
|
291
|
+
[ [1].each_with_inde {|x,y| [].each { }},
|
292
|
+
1]
|
293
|
+
EOC
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_multi_line__parentheses
|
297
|
+
assert_equal(["each_with_index"], doit(<<EOC, 1, 23))
|
298
|
+
foo( [1].each_with_inde {|x,y| [].each { }},
|
299
|
+
1)
|
300
|
+
EOC
|
301
|
+
=begin FIXME
|
302
|
+
assert_equal(["each_with_index"], doit(<<EOC, 2, 23))
|
303
|
+
foo( 1,
|
304
|
+
[1].each_with_inde {|x,y| [].each { }})
|
305
|
+
EOC
|
306
|
+
=end
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_multi_line__control_structures__if
|
310
|
+
assert_equal(["length"], doit(<<EOC, 1))
|
311
|
+
if "a".leng
|
312
|
+
end
|
313
|
+
EOC
|
314
|
+
assert_equal(["length"], doit(<<EOC, 1, 8))
|
315
|
+
"a".leng if true
|
316
|
+
EOC
|
317
|
+
assert_equal(["length"], doit(<<EOC, 1, 8))
|
318
|
+
"a".leng ; if true
|
319
|
+
1
|
320
|
+
end
|
321
|
+
EOC
|
322
|
+
assert_equal(["length"], doit(<<EOC, 1, 8))
|
323
|
+
"a".leng ;if true
|
324
|
+
1
|
325
|
+
end
|
326
|
+
EOC
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_multi_line__control_structures__if_in_string
|
330
|
+
assert_equal(["length"], doit(<<EOC, 1))
|
331
|
+
"if a".leng
|
332
|
+
EOC
|
333
|
+
assert_equal(["length"], doit(<<EOC, 1))
|
334
|
+
'if a'.leng
|
335
|
+
EOC
|
336
|
+
assert_equal(["length"], doit(<<EOC, 1))
|
337
|
+
`if a`.leng
|
338
|
+
EOC
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_multi_line__control_structures__other_keywords
|
342
|
+
assert_equal(["length"], doit(<<EOC, 1))
|
343
|
+
unless "a".leng
|
344
|
+
end
|
345
|
+
EOC
|
346
|
+
assert_equal(["length"], doit(<<EOC, 1))
|
347
|
+
while "a".leng
|
348
|
+
end
|
349
|
+
EOC
|
350
|
+
assert_equal(["length"], doit(<<EOC, 1))
|
351
|
+
until "a".leng
|
352
|
+
end
|
353
|
+
EOC
|
354
|
+
assert_equal(["split"], doit(<<EOC, 1))
|
355
|
+
for a in "a".spli
|
356
|
+
end
|
357
|
+
EOC
|
358
|
+
end
|
359
|
+
|
360
|
+
def test_phrase
|
361
|
+
assert_equal(["uniq", "uniq!"], doit('Array.new(3).uni',1))
|
362
|
+
assert_equal(["uniq", "uniq!"], doit('Array.new(3).to_a.uni',1))
|
363
|
+
assert_equal(["uniq", "uniq!"], doit('Array.new(3).map{|x| x.to_i}.uni',1))
|
364
|
+
assert_equal(["uniq", "uniq!"], doit('[][0,(1+1)].uni',1))
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_percent__String
|
368
|
+
assert_equal(["length"], doit('%!foo!.leng',1))
|
369
|
+
assert_equal(["length"], doit('%q!foo!.leng',1))
|
370
|
+
assert_equal(["length"], doit('%Q!foo!.leng',1))
|
371
|
+
assert_equal(["length"], doit('%x!foo!.leng',1))
|
372
|
+
|
373
|
+
assert_equal(["length"], doit('%{foo}.leng',1))
|
374
|
+
assert_equal(["length"], doit('%q{foo}.leng',1))
|
375
|
+
assert_equal(["length"], doit('%q!(!.leng',1))
|
376
|
+
assert_equal(["length"], doit('%Q!(!.leng',1))
|
377
|
+
assert_equal(["length"], doit('%x!(!.leng',1))
|
378
|
+
assert_equal(["length"], doit('%x{(}.leng',1))
|
379
|
+
|
380
|
+
assert_equal(["length"], doit('%{f(o)o}.leng',1))
|
381
|
+
assert_equal(["length"], doit('%{f{o}o}.leng',1))
|
382
|
+
assert_equal(["length"], doit('(%{f{o}o}+%!}x!).leng',1))
|
383
|
+
end
|
384
|
+
|
385
|
+
def test_percent__Array
|
386
|
+
assert_equal(["length"], doit('%w!foo!.leng',1))
|
387
|
+
assert_equal(["length"], doit('%W!foo!.leng',1))
|
388
|
+
|
389
|
+
assert_equal(["length"], doit('%w{foo}.leng',1))
|
390
|
+
assert_equal(["length"], doit('%W{foo}.leng',1))
|
391
|
+
assert_equal(["length"], doit('%w!(!.leng',1))
|
392
|
+
assert_equal(["length"], doit('%W!(!.leng',1))
|
393
|
+
assert_equal(["length"], doit('%w{(}.leng',1))
|
394
|
+
|
395
|
+
assert_equal(["length"], doit('%w{f(o)o}.leng',1))
|
396
|
+
assert_equal(["length"], doit('%w{f{o}o}.leng',1))
|
397
|
+
assert_equal(["length"], doit('(%W{f{o}o}+%w!}x!).leng',1))
|
398
|
+
end
|
399
|
+
|
400
|
+
def test_percent__Regexp
|
401
|
+
assert_equal(["kcode"], doit('%r!foo!.kcod',1))
|
402
|
+
assert_equal(["kcode"], doit('%r{foo}.kcod',1))
|
403
|
+
assert_equal(["kcode"], doit('%r!(!.kcod',1))
|
404
|
+
assert_equal(["kcode"], doit('%r{(}.kcod',1))
|
405
|
+
assert_equal(["kcode"], doit('%r{f(o)o}.kcod',1))
|
406
|
+
end
|
407
|
+
|
408
|
+
def test_percent__Symbol
|
409
|
+
assert_equal(["id2name"], doit('%s!foo!.id2nam',1))
|
410
|
+
assert_equal(["id2name"], doit('%s{foo}.id2nam',1))
|
411
|
+
assert_equal(["id2name"], doit('%s!(!.id2nam',1))
|
412
|
+
assert_equal(["id2name"], doit('%s{(}.id2nam',1))
|
413
|
+
assert_equal(["id2name"], doit('%s{f(o)o}.id2nam',1))
|
414
|
+
end
|
415
|
+
|
416
|
+
def test_complete_method__with_NoMethodError
|
417
|
+
assert_equal(["module_function"], doit(<<EOC, 3, nil, :ignore_NoMethodError=>true))
|
418
|
+
module X
|
419
|
+
xx # normally NoMethodError
|
420
|
+
module_funct
|
421
|
+
end
|
422
|
+
EOC
|
423
|
+
end
|
424
|
+
|
425
|
+
# drawback of ignore_NoMethodError
|
426
|
+
def test_with_or_without_ignore_NoMethodError
|
427
|
+
code = <<EOC
|
428
|
+
a=[1]
|
429
|
+
x = a[1][0] rescue "aaa"
|
430
|
+
x.lengt
|
431
|
+
EOC
|
432
|
+
assert_equal(["length"], doit(code, 3))
|
433
|
+
assert_equal([], doit(code, 3, nil, :ignore_NoMethodError=>true))
|
434
|
+
end
|
435
|
+
|
436
|
+
def test__syntax_error
|
437
|
+
assert_raise(ProcessParticularLine::NewCodeError) do
|
438
|
+
doit(<<EOC, 5)
|
439
|
+
end
|
440
|
+
module X
|
441
|
+
def x
|
442
|
+
end
|
443
|
+
module_function
|
444
|
+
end
|
445
|
+
EOC
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
def test__runtime_error
|
450
|
+
assert_raise(ProcessParticularLine::NewCodeError) do
|
451
|
+
doit(<<EOC, 5)
|
452
|
+
__undefined_method__
|
453
|
+
module X
|
454
|
+
def x
|
455
|
+
end
|
456
|
+
module_function
|
457
|
+
end
|
458
|
+
EOC
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
|
463
|
+
# This is a caveat!! You should use dabbrev for this case.
|
464
|
+
def XXtest_oneline
|
465
|
+
assert_equal(["aaa"], doit('aaa=1; aa', 1))
|
466
|
+
end
|
467
|
+
end
|