* net/dbus.el (dbus-init-bus, dbus-call-method)
[emacs.git] / test / indent / ruby.rb
blob7e7787989965ee5191562ead8960d89aef26ce05
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
9 # Percent literals.
10 b = %Q{This is a "string"}
11 c = %w!foo
12  bar
13  baz!
14 d = %(hello (nested) world)
16 # Don't propertize percent literals inside strings.
17 "(%s, %s)" % [123, 456]
19 "abc/#{def}ghi"
20 "abc\#{def}ghi"
22 # Or inside comments.
23 x = # "tot %q/to"; =
24   y = 2 / 3
26 # Regexp after whitelisted method.
27 "abc".sub /b/, 'd'
29 # Don't mis-match "sub" at the end of words.
30 a = asub / aslb + bsub / bslb;
32 # Highlight the regexp after "if".
33 x = toto / foo if /do bar/ =~ "dobar"
35 # Regexp options are highlighted.
37 /foo/xi != %r{bar}mo.tee
39 bar(class: XXX) do              # ruby-indent-keyword-label
40   foo
41 end
42 bar
44 foo = [1,                       # ruby-deep-indent
45        2]
47 foo = {                         # ruby-deep-indent-disabled
48   a: b
51 foo = { a: b,
52         a1: b1
53       }
55 foo({                           # bug#16118
56       a: b,
57       c: d
58     })
60 bar = foo(
61   a, [
62     1,
63   ],
64   :qux => [
65     3
66   ])
68 foo(
69   [
70     {
71       a: b
72     },
73   ],
74   {
75     c: d
76   }
79 foo([{
80        a: 2
81      },
82      {
83        b: 3
84      },
85      4
86     ])
88 foo = [                         # ruby-deep-indent-disabled
89   1
92 foo(                            # ruby-deep-indent-disabled
93   a
96 # Multiline regexp.
97 /bars
98  tees # toots
99  nfoos/
101 def test1(arg)
102   puts "hello"
105 def test2 (arg)
106   a = "apple"
108   if a == 2
109     puts "hello"
110   else
111     puts "there"
112   end
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
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
137 # Some Cucumber code:
138 Given /toto/ do
139   print "hello"
142 # Bug#15208
143 if something == :==
144   do_something
146   return false unless method == :+
147   x = y + z # Bug#16609
149   a = 1 ? 2 :(
150     2 + 3
151   )
154 # Bug#17097
155 if x == :!=
156   something
159 # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
160 d = 4 + 5 +      # no '\' needed
161     6 + 7
163 # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
164 e = 8 + 9   \
165     + 10         # '\' needed
167 foo = obj.bar { |m| tee(m) } +
168       obj.qux { |m| hum(m) }
170 begin
171   foo
172 ensure
173   bar
176 # Bug#15369
177 MSG = 'Separate every 3 digits in the integer portion of a number' \
178       'with underscores(_).'
180 class C
181   def foo
182     self.end
183     D.new.class
184   end
187 a = foo(j, k) -
188     bar_tee
190 while a < b do # "do" is optional
191   foo
194 desc "foo foo" \
195      "bar bar"
197 foo.
198   bar
200 # https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206
202   .bar
204 z = {
205   foo: {
206     a: "aaa",
207     b: "bbb"
208   }
211 foo if
212   bar
214 if foo?
215   bar
218 method arg1,                   # bug#15594
219        method2 arg2,
220                arg3
222 method? arg1,
223         arg2
225 method! arg1,
226         arg2
228 method !arg1,
229        arg2
231 method [],
232        arg2
234 method :foo,
235        :bar
237 method (a + b),
238        c, :d => :e,
239        f: g
241 desc "abc",
242      defg
244 it "is a method call with block" do |asd|
245   foo
248 it("is too!") {
249   bar
250     .qux
253 and_this_one(has) { |block, parameters|
254   tee
257 if foo &&
258    bar
261 foo +
262   bar
264 foo and
265   bar
267 foo > bar &&
268   tee < qux
270 zux do
271   foo == bar and
272     tee == qux
275 foo ^
276   bar
278 foo_bar_tee(1, 2, 3)
279   .qux.bar
280   .tee
282 foo do
283   bar
284     .tee
287 def bar
288   foo
289     .baz
292 # http://stackoverflow.com/questions/17786563/emacs-ruby-mode-if-expressions-indentation
293 tee = if foo
294         bar
295       else
296         tee
297       end
299 a = b {
300   c
303 aa = bb do
304   cc
307 foo :bar do
308   qux
311 foo do |*args|
312   tee
315 bar do |&block|
316   tee
319 foo = [1, 2, 3].map do |i|
320   i + 1
323 bar.foo do
324   bar
327 bar.foo(tee) do
328   bar
331 bar.foo(tee) {
332   bar
335 bar 1 do
336   foo 2 do
337     tee
338   end
341 foo |
342   bar
344 def qux
345   foo ||= begin
346             bar
347             tee
348           rescue
349             oomph
350           end
353 private def foo
354   bar
357 %^abc^
360 qux = foo.fee ?
361         bar :
362         tee
364 zoo.keep.bar!(
365   {x: y,
366    z: t})
369   .lose(
370     q, p)
372 a.records().map(&:b).zip(
373   foo)
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)
382 foo(:bar =>
383     tee)
385 {'a' => {
386    'b' => 'c',
387    'd' => %w(e f)
391 # Bug#17050
393 return render json: {
394                 errors: { base: [message] },
395                 copying: copying
396               },
397               status: 400
399 top test(
400       some,
401       top,
402       test)
404 foo bar, {
405       tee: qux
406     }