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