* configure.ac (EMACS_CHECK_MODULES): Fix typo in previous change.
[bpt/emacs.git] / test / indent / ruby.rb
1 if something_wrong? # ruby-move-to-block-skips-heredoc
2 ActiveSupport::Deprecation.warn(<<-eowarn)
3 boo hoo
4 end
5 eowarn
6 foo
7 end
8
9 # Percent literals.
10 b = %Q{This is a "string"}
11 c = %w!foo
12 bar
13 baz!
14 d = %(hello (nested) world)
15
16 # Don't propertize percent literals inside strings.
17 "(%s, %s)" % [123, 456]
18
19 # Or inside comments.
20 x = # "tot %q/to"; =
21 y = 2 / 3
22
23 # Regexp after whitelisted method.
24 "abc".sub /b/, 'd'
25
26 # Don't mis-match "sub" at the end of words.
27 a = asub / aslb + bsub / bslb;
28
29 # Highlight the regexp after "if".
30 x = toto / foo if /do bar/ =~ "dobar"
31
32 # Regexp options are highlighted.
33
34 /foo/xi != %r{bar}mo.tee
35
36 bar(class: XXX) do # ruby-indent-keyword-label
37 foo
38 end
39 bar
40
41 foo = [1, # ruby-deep-indent
42 2]
43
44 foo = { # ruby-deep-indent-disabled
45 a: b
46 }
47
48 foo = { a: b,
49 a1: b1
50 }
51
52 foo({ # bug#16118
53 a: b,
54 c: d
55 })
56
57 bar = foo(
58 a, [
59 1,
60 ],
61 :qux => [
62 3
63 ])
64
65 foo(
66 [
67 {
68 a: b
69 },
70 ],
71 {
72 c: d
73 }
74 )
75
76 foo([{
77 a: 2
78 },
79 {
80 b: 3
81 },
82 4
83 ])
84
85 foo = [ # ruby-deep-indent-disabled
86 1
87 ]
88
89 foo( # ruby-deep-indent-disabled
90 a
91 )
92
93 # Multiline regexp.
94 /bars
95 tees # toots
96 nfoos/
97
98 def test1(arg)
99 puts "hello"
100 end
101
102 def test2 (arg)
103 a = "apple"
104
105 if a == 2
106 puts "hello"
107 else
108 puts "there"
109 end
110
111 if a == 2 then
112 puts "hello"
113 elsif a == 3
114 puts "hello3"
115 elsif a == 3 then
116 puts "hello3"
117 else
118 puts "there"
119 end
120
121 b = case a
122 when "a"
123 6
124 # Support for this syntax was removed in Ruby 1.9, so we
125 # probably don't need to handle it either.
126 # when "b" :
127 # 7
128 # when "c" : 2
129 when "d" then 4
130 else 5
131 end
132 end
133
134 # Some Cucumber code:
135 Given /toto/ do
136 print "hello"
137 end
138
139 # Bug#15208
140 if something == :==
141 do_something
142
143 return false unless method == :+
144 x = y + z # Bug#16609
145
146 a = 1 ? 2 :(
147 2 + 3
148 )
149 end
150
151 # Bug#17097
152 if x == :!=
153 something
154 end
155
156 # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
157 d = 4 + 5 + # no '\' needed
158 6 + 7
159
160 # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
161 e = 8 + 9 \
162 + 10 # '\' needed
163
164 foo = obj.bar { |m| tee(m) } +
165 obj.qux { |m| hum(m) }
166
167 begin
168 foo
169 ensure
170 bar
171 end
172
173 # Bug#15369
174 MSG = 'Separate every 3 digits in the integer portion of a number' \
175 'with underscores(_).'
176
177 class C
178 def foo
179 self.end
180 D.new.class
181 end
182 end
183
184 a = foo(j, k) -
185 bar_tee
186
187 while a < b do # "do" is optional
188 foo
189 end
190
191 desc "foo foo" \
192 "bar bar"
193
194 foo.
195 bar
196
197 # https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206
198 foo
199 .bar
200
201 z = {
202 foo: {
203 a: "aaa",
204 b: "bbb"
205 }
206 }
207
208 foo if
209 bar
210
211 if foo?
212 bar
213 end
214
215 method arg1, # bug#15594
216 method2 arg2,
217 arg3
218
219 method? arg1,
220 arg2
221
222 method! arg1,
223 arg2
224
225 method !arg1,
226 arg2
227
228 method [],
229 arg2
230
231 method :foo,
232 :bar
233
234 method (a + b),
235 c, :d => :e,
236 f: g
237
238 desc "abc",
239 defg
240
241 it "is a method call with block" do |asd|
242 foo
243 end
244
245 it("is too!") {
246 bar
247 .qux
248 }
249
250 and_this_one(has) { |block, parameters|
251 tee
252 }
253
254 if foo &&
255 bar
256 end
257
258 foo +
259 bar
260
261 foo and
262 bar
263
264 foo > bar &&
265 tee < qux
266
267 zux do
268 foo == bar and
269 tee == qux
270 end
271
272 foo ^
273 bar
274
275 foo_bar_tee(1, 2, 3)
276 .qux.bar
277 .tee
278
279 foo do
280 bar
281 .tee
282 end
283
284 def bar
285 foo
286 .baz
287 end
288
289 # http://stackoverflow.com/questions/17786563/emacs-ruby-mode-if-expressions-indentation
290 tee = if foo
291 bar
292 else
293 tee
294 end
295
296 a = b {
297 c
298 }
299
300 aa = bb do
301 cc
302 end
303
304 foo :bar do
305 qux
306 end
307
308 foo do |*args|
309 tee
310 end
311
312 bar do |&block|
313 tee
314 end
315
316 foo = [1, 2, 3].map do |i|
317 i + 1
318 end
319
320 bar.foo do
321 bar
322 end
323
324 bar.foo(tee) do
325 bar
326 end
327
328 bar.foo(tee) {
329 bar
330 }
331
332 bar 1 do
333 foo 2 do
334 tee
335 end
336 end
337
338 foo |
339 bar
340
341 def qux
342 foo ||= begin
343 bar
344 tee
345 rescue
346 oomph
347 end
348 end
349
350 private def foo
351 bar
352 end
353
354 %^abc^
355 ddd
356
357 qux = foo.fee ?
358 bar :
359 tee
360
361 zoo.keep.bar!(
362 {x: y,
363 z: t})
364
365 zoo
366 .lose(
367 q, p)
368
369 a.records().map(&:b).zip(
370 foo)
371
372 # FIXME: This is not consistent with the example below it, but this
373 # offset only happens if the colon is at eol, which wouldn't be often.
374 # Tokenizing `bar:' as `:bar =>' would be better, but it's hard to
375 # distinguish from a variable reference inside a ternary operator.
376 foo(bar:
377 tee)
378
379 foo(:bar =>
380 tee)
381
382 {'a' => {
383 'b' => 'c',
384 'd' => %w(e f)
385 }
386 }
387
388 # Bug#17050
389
390 return render json: {
391 errors: { base: [message] },
392 copying: copying
393 },
394 status: 400
395
396 top test(
397 some,
398 top,
399 test)
400
401 foo bar, {
402 tee: qux
403 }