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