* net/shr.el (shr-tag-a): Support zero-length <a name="foo"> elements.
[bpt/emacs.git] / test / indent / ruby.rb
CommitLineData
34d1a133
SM
1if something_wrong? # ruby-move-to-block-skips-heredoc
2 ActiveSupport::Deprecation.warn(<<-eowarn)
3 boo hoo
4 end
5 eowarn
dca01b09 6 foo
34d1a133
SM
7end
8
f063063a 9# Percent literals.
dfbd787f 10b = %Q{This is a "string"}
f063063a 11c = %w!foo
dfbd787f 12 bar
f063063a
DG
13 baz!
14d = %(hello (nested) world)
15
16# Don't propertize percent literals inside strings.
17"(%s, %s)" % [123, 456]
18
19# Or inside comments.
20x = # "tot %q/to"; =
a9e4425b 21 y = 2 / 3
f063063a
DG
22
23# Regexp after whitelisted method.
24"abc".sub /b/, 'd'
25
26# Don't mis-match "sub" at the end of words.
27a = asub / aslb + bsub / bslb;
dfbd787f 28
f063063a
DG
29# Highlight the regexp after "if".
30x = toto / foo if /do bar/ =~ "dobar"
dfbd787f 31
34d1a133
SM
32bar(class: XXX) do # ruby-indent-keyword-label
33 foo
34end
35bar
36
37foo = [1, # ruby-deep-indent
38 2]
39
40foo = { # ruby-deep-indent-disabled
5cd9cda9 41 a: b
34d1a133
SM
42}
43
369bbf71 44foo = { a: b,
03d44565
SM
45 a1: b1
46 }
47
276bc333
DG
48foo({ # bug#16118
49 a: b,
50 c: d
51 }
52 ) # bug#16116
53
54bar = foo(
55 a, [
56 1,
57 ],
58 :qux => [
59 3
60 ]
61 )
62
63foo(
64 [
65 {
66 a: b
67 },
68 ],
69 {
70 c: d
71 }
72)
73
74foo([{
75 a: 2
76 },
77 {
78 b: 3
79 },
80 4
81 ]
82 )
8c1ae481 83
34d1a133
SM
84foo = [ # ruby-deep-indent-disabled
85 1
86]
87
88foo( # ruby-deep-indent-disabled
89 a
90)
91
1a0a0a8a
DG
92# Multiline regexp.
93/bars
94 tees # toots
95 nfoos/
96
a9e4425b
SM
97def test1(arg)
98 puts "hello"
99end
100
101def test2 (arg)
102 a = "apple"
103
104 if a == 2
105 puts "hello"
106 else
107 puts "there"
108 end
109
110 if a == 2 then
111 puts "hello"
112 elsif a == 3
113 puts "hello3"
114 elsif a == 3 then
115 puts "hello3"
116 else
117 puts "there"
118 end
119
120 case a
121 when "a"
122 6
1a0a0a8a
DG
123 # Support for this syntax was removed in Ruby 1.9, so we
124 # probably don't need to handle it either.
a9e4425b
SM
125 # when "b" :
126 # 7
127 # when "c" : 2
128 when "d" then 4
129 else 5
130 end
131end
132
dfbd787f
SM
133# Some Cucumber code:
134Given /toto/ do
135 print "hello"
136end
88527bc0
DG
137
138# Bug#15208
139if something == :==
140 do_something
141end
578c21bc 142
7ccae3b1
SM
143# Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
144d = 4 + 5 + # no '\' needed
145 6 + 7
146
147# Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
148e = 8 + 9 \
149 + 10 # '\' needed
150
1f923923
DG
151foo = obj.bar { |m| tee(m) } +
152 obj.qux { |m| hum(m) }
153
5cd9cda9
DG
154begin
155 foo
156ensure
157 bar
158end
159
578c21bc 160# Bug#15369
2f84ba10 161MSG = 'Separate every 3 digits in the integer portion of a number' \
34d1a133 162 'with underscores(_).'
5cd9cda9 163
7ccae3b1
SM
164class C
165 def foo
166 self.end
167 D.new.class
168 end
169end
5cd9cda9
DG
170
171a = foo(j, k) -
7ccae3b1 172 bar_tee
5cd9cda9
DG
173
174while a < b do # "do" is optional
175 foo
176end
177
178desc "foo foo" \
7ccae3b1 179 "bar bar"
7318480c
DG
180
181foo.
182 bar
183
2f84ba10 184# https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206
7318480c
DG
185foo
186 .bar
2f84ba10
DG
187
188z = {
189 foo: {
190 a: "aaa",
191 b: "bbb"
192 }
193}
194
238150c8
DG
195foo if
196 bar
197
b68e2926
DG
198if foo?
199 bar
200end
201
1eda1d8d
DG
202method arg1, # bug#15594
203 method2 arg2,
204 arg3
205
206method? arg1,
207 arg2
208
209method! arg1,
210 arg2
211
bae91342
DG
212method !arg1,
213 arg2
214
215method [],
216 arg2
217
218method :foo,
219 :bar
220
221method (a + b),
222 c, :d => :e,
223 f: g
224
8c1ae481
DG
225it "is a method call with block" do |asd|
226 foo
227end
228
229it("is too!") {
230 bar
231}
232
233and_this_one(has) { |block, parameters|
234 tee
235}
236
c7e36328 237if foo &&
cfef16c0
DG
238 bar
239end
240
2f84ba10
DG
241foo +
242 bar
243
1d1c86da
DG
244foo and
245 bar
246
1f923923
DG
247foo > bar &&
248 tee < qux
249
250zux do
251 foo == bar and
252 tee == qux
253end
254
1d1c86da
DG
255foo ^
256 bar
257
18cacc39
DG
258foo_bar_tee(1, 2, 3)
259 .qux
260 .bar
261
a6462ef5
DG
262foo do
263 bar
264 .tee
265end
266
267def bar
268 foo
269 .baz
270end
271
c8c605ac
DG
272# http://stackoverflow.com/questions/17786563/emacs-ruby-mode-if-expressions-indentation
273tee = if foo
274 bar
275 end
276
3d42b968
DG
277a = b {
278 c
279}
280
281aa = bb do
282 cc
283end
284
41784d0b
DG
285foo :bar do
286 qux
287end
288
1f923923
DG
289foo do |*args|
290 tee
291end
292
293bar do |&block|
294 tee
295end
296
238150c8
DG
297foo = [1, 2, 3].map do |i|
298 i + 1
299end
55ee77a3 300
b420ccfc 301bar.foo do
18cacc39 302 bar
18cacc39 303end
1d1c86da 304
1f923923
DG
305bar.foo(tee) do
306 bar
307end
1d1c86da 308
1f923923 309bar.foo(tee) {
1d1c86da 310 bar
1f923923
DG
311}
312
313bar 1 do
314 foo 2 do
315 tee
316 end
1d1c86da 317end
d85783ca 318
7b08f97e
DG
319foo |
320 bar
321
d85783ca
DG
322foo ||
323 begin
324 bar
325 end
1629a329
DG
326
327def qux
328 foo ||= begin
329 bar
330 tee
331 end
332end
8212d9c0
DG
333
334%^abc^
335ddd