* lisp/progmodes/ruby-mode.el (ruby-smie--implicit-semi-p):
[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({
49 a: b,
50 c: d
51 })
52
53 foo = [ # ruby-deep-indent-disabled
54 1
55 ]
56
57 foo( # ruby-deep-indent-disabled
58 a
59 )
60
61 # Multiline regexp.
62 /bars
63 tees # toots
64 nfoos/
65
66 def test1(arg)
67 puts "hello"
68 end
69
70 def test2 (arg)
71 a = "apple"
72
73 if a == 2
74 puts "hello"
75 else
76 puts "there"
77 end
78
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
88
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
100 end
101
102 # Some Cucumber code:
103 Given /toto/ do
104 print "hello"
105 end
106
107 # Bug#15208
108 if something == :==
109 do_something
110 end
111
112 # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
113 d = 4 + 5 + # no '\' needed
114 6 + 7
115
116 # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
117 e = 8 + 9 \
118 + 10 # '\' needed
119
120 foo = obj.bar { |m| tee(m) } +
121 obj.qux { |m| hum(m) }
122
123 begin
124 foo
125 ensure
126 bar
127 end
128
129 # Bug#15369
130 MSG = 'Separate every 3 digits in the integer portion of a number' \
131 'with underscores(_).'
132
133 class C
134 def foo
135 self.end
136 D.new.class
137 end
138 end
139
140 a = foo(j, k) -
141 bar_tee
142
143 while a < b do # "do" is optional
144 foo
145 end
146
147 desc "foo foo" \
148 "bar bar"
149
150 foo.
151 bar
152
153 # https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206
154 foo
155 .bar
156
157 z = {
158 foo: {
159 a: "aaa",
160 b: "bbb"
161 }
162 }
163
164 foo if
165 bar
166
167 if foo?
168 bar
169 end
170
171 method arg1, # bug#15594
172 method2 arg2,
173 arg3
174
175 method? arg1,
176 arg2
177
178 method! arg1,
179 arg2
180
181 method !arg1,
182 arg2
183
184 method [],
185 arg2
186
187 method :foo,
188 :bar
189
190 method (a + b),
191 c, :d => :e,
192 f: g
193
194 it "is a method call with block" do |asd|
195 foo
196 end
197
198 it("is too!") {
199 bar
200 }
201
202 and_this_one(has) { |block, parameters|
203 tee
204 }
205
206 if foo &&
207 bar
208 end
209
210 foo +
211 bar
212
213 foo and
214 bar
215
216 foo > bar &&
217 tee < qux
218
219 zux do
220 foo == bar and
221 tee == qux
222 end
223
224 foo ^
225 bar
226
227 foo_bar_tee(1, 2, 3)
228 .qux
229 .bar
230
231 foo do
232 bar
233 .tee
234 end
235
236 def bar
237 foo
238 .baz
239 end
240
241 # http://stackoverflow.com/questions/17786563/emacs-ruby-mode-if-expressions-indentation
242 tee = if foo
243 bar
244 end
245
246 a = b {
247 c
248 }
249
250 aa = bb do
251 cc
252 end
253
254 foo :bar do
255 qux
256 end
257
258 foo do |*args|
259 tee
260 end
261
262 bar do |&block|
263 tee
264 end
265
266 foo = [1, 2, 3].map do |i|
267 i + 1
268 end
269
270 bar.foo do
271 bar
272 end
273
274 bar.foo(tee) do
275 bar
276 end
277
278 bar.foo(tee) {
279 bar
280 }
281
282 bar 1 do
283 foo 2 do
284 tee
285 end
286 end
287
288 foo ||
289 begin
290 bar
291 end
292
293 def qux
294 foo ||= begin
295 bar
296 tee
297 end
298 end