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