* test/indent/ruby.rb: Move a now-successful example.
[emacs.git] / test / indent / ruby.rb
blob5e3db5afb71adc08d246922e1a9e429ae9507a1f
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 # Or inside comments.
20 x = # "tot %q/to"; =
21   y = 2 / 3
23 # Regexp after whitelisted method.
24 "abc".sub /b/, 'd'
26 # Don't mis-match "sub" at the end of words.
27 a = asub / aslb + bsub / bslb;
29 # Highlight the regexp after "if".
30 x = toto / foo if /do bar/ =~ "dobar"
32 bar(class: XXX) do              # ruby-indent-keyword-label
33   foo
34 end
35 bar
37 foo = [1,                       # ruby-deep-indent
38        2]
40 foo = {                         # ruby-deep-indent-disabled
41   a: b
44 foo = { a: b,
45         a1: b1
46       }
48 foo({
49      a: b,
50      c: d
51    })
53 foo = [                         # ruby-deep-indent-disabled
54   1
57 foo(                            # ruby-deep-indent-disabled
58   a
61 # Multiline regexp.
62 /bars
63  tees # toots
64  nfoos/
66 def test1(arg)
67   puts "hello"
68 end
70 def test2 (arg)
71   a = "apple"
73   if a == 2
74     puts "hello"
75   else
76     puts "there"
77   end
79   if a == 2 then
80     puts "hello"
81   elsif a == 3
82     puts "hello3"
83   elsif a == 3 then
84     puts "hello3"
85   else
86     puts "there"
87   end
89   case a
90   when "a"
91     6
92   # Support for this syntax was removed in Ruby 1.9, so we
93   # probably don't need to handle it either.
94   # when "b" :
95   #   7
96   # when "c" : 2
97   when "d"  then 4
98   else 5
99   end
102 # Some Cucumber code:
103 Given /toto/ do
104   print "hello"
107 # Bug#15208
108 if something == :==
109   do_something
112 # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
113 d = 4 + 5 +      # no '\' needed
114     6 + 7
116 # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
117 e = 8 + 9   \
118     + 10         # '\' needed
120 begin
121   foo
122 ensure
123   bar
126 # Bug#15369
127 MSG = 'Separate every 3 digits in the integer portion of a number' \
128       'with underscores(_).'
130 class C
131   def foo
132     self.end
133     D.new.class
134   end
137 a = foo(j, k) -
138     bar_tee
140 while a < b do # "do" is optional
141   foo
144 desc "foo foo" \
145      "bar bar"
147 foo.
148   bar
150 # https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206
152   .bar
154 z = {
155   foo: {
156     a: "aaa",
157     b: "bbb"
158   }
161 foo if
162   bar
164 if foo?
165   bar
168 method arg1,                   # bug#15594
169        method2 arg2,
170                arg3
172 method? arg1,
173         arg2
175 method! arg1,
176         arg2
178 method !arg1,
179        arg2
181 method [],
182        arg2
184 method :foo,
185        :bar
187 method (a + b),
188        c, :d => :e,
189        f: g
191 it "is a method call with block" do |asd|
192   foo
195 it("is too!") {
196   bar
199 and_this_one(has) { |block, parameters|
200   tee
203 if foo &&
204    bar
207 foo +
208   bar
210 foo_bar_tee(1, 2, 3)
211   .qux
212   .bar
214 foo do
215   bar
216     .tee
219 def bar
220   foo
221     .baz
224 # http://stackoverflow.com/questions/17786563/emacs-ruby-mode-if-expressions-indentation
225 tee = if foo
226         bar
227       end
229 a = b {
230   c
233 aa = bb do
234   cc
237 foo :bar do
238   qux
241 # Examples below still fail with `ruby-use-smie' on:
243 foo = [1, 2, 3].map do |i|
244   i + 1
247 bar.foo do # "." is parent to "do"; it shouldn't be.
248   bar