Fix bug#16116
[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 bar(class: XXX) do # ruby-indent-keyword-label
33 foo
34 end
35 bar
36
37 foo = [1, # ruby-deep-indent
38 2]
39
40 foo = { # ruby-deep-indent-disabled
41 a: b
42 }
43
44 foo = { a: b,
45 a1: b1
46 }
47
48 foo({ # bug#16118
49 a: b,
50 c: d
51 })
52
53 bar = foo(
54 a, [
55 1,
56 ],
57 :qux => [
58 3
59 ])
60
61 foo(
62 [
63 {
64 a: b
65 },
66 ],
67 {
68 c: d
69 }
70 )
71
72 foo([{
73 a: 2
74 },
75 {
76 b: 3
77 },
78 4
79 ])
80
81 foo = [ # ruby-deep-indent-disabled
82 1
83 ]
84
85 foo( # ruby-deep-indent-disabled
86 a
87 )
88
89 # Multiline regexp.
90 /bars
91 tees # toots
92 nfoos/
93
94 def test1(arg)
95 puts "hello"
96 end
97
98 def 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
117 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
128 end
129
130 # Some Cucumber code:
131 Given /toto/ do
132 print "hello"
133 end
134
135 # Bug#15208
136 if something == :==
137 do_something
138 end
139
140 # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
141 d = 4 + 5 + # no '\' needed
142 6 + 7
143
144 # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
145 e = 8 + 9 \
146 + 10 # '\' needed
147
148 foo = obj.bar { |m| tee(m) } +
149 obj.qux { |m| hum(m) }
150
151 begin
152 foo
153 ensure
154 bar
155 end
156
157 # Bug#15369
158 MSG = 'Separate every 3 digits in the integer portion of a number' \
159 'with underscores(_).'
160
161 class C
162 def foo
163 self.end
164 D.new.class
165 end
166 end
167
168 a = foo(j, k) -
169 bar_tee
170
171 while a < b do # "do" is optional
172 foo
173 end
174
175 desc "foo foo" \
176 "bar bar"
177
178 foo.
179 bar
180
181 # https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206
182 foo
183 .bar
184
185 z = {
186 foo: {
187 a: "aaa",
188 b: "bbb"
189 }
190 }
191
192 foo if
193 bar
194
195 if foo?
196 bar
197 end
198
199 method arg1, # bug#15594
200 method2 arg2,
201 arg3
202
203 method? arg1,
204 arg2
205
206 method! arg1,
207 arg2
208
209 method !arg1,
210 arg2
211
212 method [],
213 arg2
214
215 method :foo,
216 :bar
217
218 method (a + b),
219 c, :d => :e,
220 f: g
221
222 it "is a method call with block" do |asd|
223 foo
224 end
225
226 it("is too!") {
227 bar
228 }
229
230 and_this_one(has) { |block, parameters|
231 tee
232 }
233
234 if foo &&
235 bar
236 end
237
238 foo +
239 bar
240
241 foo and
242 bar
243
244 foo > bar &&
245 tee < qux
246
247 zux do
248 foo == bar and
249 tee == qux
250 end
251
252 foo ^
253 bar
254
255 foo_bar_tee(1, 2, 3)
256 .qux
257 .bar
258
259 foo do
260 bar
261 .tee
262 end
263
264 def bar
265 foo
266 .baz
267 end
268
269 # http://stackoverflow.com/questions/17786563/emacs-ruby-mode-if-expressions-indentation
270 tee = if foo
271 bar
272 end
273
274 a = b {
275 c
276 }
277
278 aa = bb do
279 cc
280 end
281
282 foo :bar do
283 qux
284 end
285
286 foo do |*args|
287 tee
288 end
289
290 bar do |&block|
291 tee
292 end
293
294 foo = [1, 2, 3].map do |i|
295 i + 1
296 end
297
298 bar.foo do
299 bar
300 end
301
302 bar.foo(tee) do
303 bar
304 end
305
306 bar.foo(tee) {
307 bar
308 }
309
310 bar 1 do
311 foo 2 do
312 tee
313 end
314 end
315
316 foo |
317 bar
318
319 foo ||
320 begin
321 bar
322 end
323
324 def qux
325 foo ||= begin
326 bar
327 tee
328 end
329 end
330
331 %^abc^
332 ddd