* lisp/progmodes/ruby-mode.el (ruby-smie-grammar): Remove outdated
[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 end
7
8 # Percent literals.
9 b = %Q{This is a "string"}
10 c = %w!foo
11 bar
12 baz!
13 d = %(hello (nested) world)
14
15 # Don't propertize percent literals inside strings.
16 "(%s, %s)" % [123, 456]
17
18 # Or inside comments.
19 x = # "tot %q/to"; =
20 y = 2 / 3
21
22 # Regexp after whitelisted method.
23 "abc".sub /b/, 'd'
24
25 # Don't mis-match "sub" at the end of words.
26 a = asub / aslb + bsub / bslb;
27
28 # Highlight the regexp after "if".
29 x = toto / foo if /do bar/ =~ "dobar"
30
31 bar(class: XXX) do # ruby-indent-keyword-label
32 foo
33 end
34 bar
35
36 foo = [1, # ruby-deep-indent
37 2]
38
39 foo = { # ruby-deep-indent-disabled
40 a: b
41 }
42
43 foo({
44 a: b,
45 c: d
46 })
47
48 foo = [ # ruby-deep-indent-disabled
49 1
50 ]
51
52 foo( # ruby-deep-indent-disabled
53 a
54 )
55
56 # Multiline regexp.
57 /bars
58 tees # toots
59 nfoos/
60
61 def test1(arg)
62 puts "hello"
63 end
64
65 def test2 (arg)
66 a = "apple"
67
68 if a == 2
69 puts "hello"
70 else
71 puts "there"
72 end
73
74 if a == 2 then
75 puts "hello"
76 elsif a == 3
77 puts "hello3"
78 elsif a == 3 then
79 puts "hello3"
80 else
81 puts "there"
82 end
83
84 case a
85 when "a"
86 6
87 # Support for this syntax was removed in Ruby 1.9, so we
88 # probably don't need to handle it either.
89 # when "b" :
90 # 7
91 # when "c" : 2
92 when "d" then 4
93 else 5
94 end
95 end
96
97 # Some Cucumber code:
98 Given /toto/ do
99 print "hello"
100 end
101
102 # Bug#15208
103 if something == :==
104 do_something
105 end
106
107 # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
108 d = 4 + 5 + # no '\' needed
109 6 + 7
110
111 # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
112 e = 8 + 9 \
113 + 10 # '\' needed
114
115 begin
116 foo
117 ensure
118 bar
119 end
120
121 # Bug#15369
122 MSG = 'Separate every 3 digits in the integer portion of a number' \
123 'with underscores(_).'
124
125 class C
126 def foo
127 self.end
128 D.new.class
129 end
130 end
131
132 a = foo(j, k) -
133 bar_tee
134
135 while a < b do # "do" is optional
136 foo
137 end
138
139 desc "foo foo" \
140 "bar bar"
141
142 foo.
143 bar
144
145 # https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206
146 foo
147 .bar
148
149 z = {
150 foo: {
151 a: "aaa",
152 b: "bbb"
153 }
154 }
155
156 foo if
157 bar
158
159 if foo?
160 bar
161 end
162
163 method arg1, # bug#15594
164 method2 arg2,
165 arg3
166
167 method? arg1,
168 arg2
169
170 method! arg1,
171 arg2
172
173 it "is a method call with block" do |asd|
174 foo
175 end
176
177 it("is too!") {
178 bar
179 }
180
181 and_this_one(has) { |block, parameters|
182 tee
183 }
184
185 if foo &&
186 bar
187 end
188
189 foo +
190 bar
191
192 foo_bar_tee(1, 2, 3)
193 .qux
194 .bar
195
196 # Examples below still fail with `ruby-use-smie' on:
197
198 foo = [1, 2, 3].map do |i|
199 i + 1
200 end
201
202 method !arg1,
203 arg2
204
205 method [],
206 arg2
207
208 method :foo,
209 :bar
210
211 method (a + b),
212 c
213
214 foo do
215 bar
216 .tee
217 end
218
219 def bar
220 foo
221 .baz
222 end