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