unparser 0.0.16 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.devtools +2 -2
- data/lib/unparser/emitter/assignment.rb +4 -1
- data/spec/unit/unparser_spec.rb +1092 -0
- data/unparser.gemspec +5 -5
- metadata +10 -10
- data/spec/integration/unparser/spike_spec.rb +0 -1091
data/unparser.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'unparser'
|
5
|
-
s.version = '0.0.
|
5
|
+
s.version = '0.0.18'
|
6
6
|
|
7
7
|
s.authors = ['Markus Schirp']
|
8
8
|
s.email = 'mbj@schir-dso.com'
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = [ 'test-unparser' ]
|
19
19
|
|
20
20
|
s.add_dependency('parser', '~> 2.0.0.pre6')
|
21
|
-
s.add_dependency('concord', '~> 0.1.1')
|
22
|
-
s.add_dependency('adamantium', '~> 0.0
|
23
|
-
s.add_dependency('equalizer', '~> 0.0.
|
24
|
-
s.add_dependency('abstract_type', '~> 0.0.
|
21
|
+
s.add_dependency('concord', '~> 0.1.1' )
|
22
|
+
s.add_dependency('adamantium', '~> 0.1.0' )
|
23
|
+
s.add_dependency('equalizer', '~> 0.0.7' )
|
24
|
+
s.add_dependency('abstract_type', '~> 0.0.6' )
|
25
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Schirp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -44,42 +44,42 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.0
|
47
|
+
version: 0.1.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.0
|
54
|
+
version: 0.1.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: equalizer
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.0.
|
61
|
+
version: 0.0.7
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.0.
|
68
|
+
version: 0.0.7
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: abstract_type
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.0.
|
75
|
+
version: 0.0.6
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.0.
|
82
|
+
version: 0.0.6
|
83
83
|
description: Generate equivalent source for parser gem AST nodes
|
84
84
|
email: mbj@schir-dso.com
|
85
85
|
executables:
|
@@ -160,7 +160,6 @@ files:
|
|
160
160
|
- lib/unparser/emitter/variable.rb
|
161
161
|
- lib/unparser/emitter/yield.rb
|
162
162
|
- lib/unparser/finalize.rb
|
163
|
-
- spec/integration/unparser/spike_spec.rb
|
164
163
|
- spec/spec_helper.rb
|
165
164
|
- spec/unit/unparser/buffer/append_spec.rb
|
166
165
|
- spec/unit/unparser/buffer/content_spec.rb
|
@@ -171,6 +170,7 @@ files:
|
|
171
170
|
- spec/unit/unparser/emitter/class_methods/handle_spec.rb
|
172
171
|
- spec/unit/unparser/emitter/class_methods/visit_spec.rb
|
173
172
|
- spec/unit/unparser/emitter/source_map/class_methods/emit_spec.rb
|
173
|
+
- spec/unit/unparser_spec.rb
|
174
174
|
- unparser.gemspec
|
175
175
|
homepage: http://github.com/mbj/unparser
|
176
176
|
licenses:
|
@@ -197,7 +197,6 @@ signing_key:
|
|
197
197
|
specification_version: 4
|
198
198
|
summary: Generate equivalent source for parser gem AST nodes
|
199
199
|
test_files:
|
200
|
-
- spec/integration/unparser/spike_spec.rb
|
201
200
|
- spec/spec_helper.rb
|
202
201
|
- spec/unit/unparser/buffer/append_spec.rb
|
203
202
|
- spec/unit/unparser/buffer/content_spec.rb
|
@@ -208,4 +207,5 @@ test_files:
|
|
208
207
|
- spec/unit/unparser/emitter/class_methods/handle_spec.rb
|
209
208
|
- spec/unit/unparser/emitter/class_methods/visit_spec.rb
|
210
209
|
- spec/unit/unparser/emitter/source_map/class_methods/emit_spec.rb
|
210
|
+
- spec/unit/unparser_spec.rb
|
211
211
|
has_rdoc:
|
@@ -1,1091 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Unparser, 'spike' do
|
4
|
-
|
5
|
-
|
6
|
-
PARSERS = IceNine.deep_freeze(
|
7
|
-
'1.8' => Parser::Ruby18,
|
8
|
-
'1.9' => Parser::Ruby19,
|
9
|
-
'2.0' => Parser::Ruby20,
|
10
|
-
'2.1' => Parser::Ruby21
|
11
|
-
)
|
12
|
-
|
13
|
-
RUBIES = PARSERS.keys.freeze
|
14
|
-
|
15
|
-
def self.parser_for_ruby_version(version)
|
16
|
-
PARSERS.fetch(version) do
|
17
|
-
raise "Unrecognized Ruby version #{version}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.with_versions(versions)
|
22
|
-
versions.each do |version|
|
23
|
-
parser = parser_for_ruby_version(version)
|
24
|
-
yield version, parser
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.strip(ruby)
|
29
|
-
lines = ruby.lines
|
30
|
-
line = lines.first
|
31
|
-
match = /\A[ ]*/.match(line)
|
32
|
-
length = match[0].length
|
33
|
-
source = lines.map do |line|
|
34
|
-
line[(length..-1)]
|
35
|
-
end.join
|
36
|
-
source.chomp
|
37
|
-
end
|
38
|
-
|
39
|
-
def assert_round_trip(input, parser)
|
40
|
-
ast = parser.parse(input)
|
41
|
-
generated = Unparser.unparse(ast)
|
42
|
-
generated.should eql(input)
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.assert_generates_one_way(ast, expected, versions = RUBIES)
|
46
|
-
with_versions(versions) do |version, parser|
|
47
|
-
it "should generate #{ast.inspect} as #{expected} under #{version}" do
|
48
|
-
if ast.kind_of?(String)
|
49
|
-
ast = parser.parse(ast)
|
50
|
-
end
|
51
|
-
generated = Unparser.unparse(ast)
|
52
|
-
generated.should eql(expected)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.assert_generates(ast, expected, versions = RUBIES)
|
58
|
-
with_versions(versions) do |version, parser|
|
59
|
-
it "should generate #{ast.inspect} as #{expected} under #{version}" do
|
60
|
-
if ast.kind_of?(String)
|
61
|
-
ast = parser.parse(ast)
|
62
|
-
end
|
63
|
-
generated = Unparser.unparse(ast)
|
64
|
-
generated.should eql(expected)
|
65
|
-
ast = parser.parse(generated)
|
66
|
-
Unparser.unparse(ast).should eql(expected)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.assert_round_trip(input, versions = RUBIES)
|
72
|
-
with_versions(versions) do |version, parser|
|
73
|
-
it "should round trip #{input.inspect} under #{version}" do
|
74
|
-
assert_round_trip(input, parser)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.assert_source(input, versions = RUBIES)
|
80
|
-
assert_round_trip(strip(input), versions)
|
81
|
-
end
|
82
|
-
|
83
|
-
context 'literal' do
|
84
|
-
context 'fixnum' do
|
85
|
-
assert_generates s(:int, 1), '1'
|
86
|
-
assert_generates s(:int, -1), '-1'
|
87
|
-
assert_source '1'
|
88
|
-
assert_generates '0x1', '1'
|
89
|
-
assert_generates '1_000', '1000'
|
90
|
-
assert_generates '1e10', '10000000000.0'
|
91
|
-
assert_generates '?c', '"c"', RUBIES - %w(1.8)
|
92
|
-
assert_generates '?c', '99', %w(1.8)
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'string' do
|
96
|
-
assert_generates %q("foo" "bar"), %q("foobar")
|
97
|
-
assert_generates %q(%Q(foo"#{@bar})), %q("foo\"#{@bar}")
|
98
|
-
assert_source %q("\"")
|
99
|
-
assert_source %q("foo#{1}bar")
|
100
|
-
assert_source %q("\"#{@a}")
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'execute string' do
|
104
|
-
assert_source '`foo`'
|
105
|
-
assert_source '`foo#{@bar}`'
|
106
|
-
assert_generates '%x(\))', '`)`'
|
107
|
-
#assert_generates '%x(`)', '`\``'
|
108
|
-
assert_source '`"`'
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'symbol' do
|
112
|
-
assert_generates s(:sym, :foo), ':foo'
|
113
|
-
assert_generates s(:sym, :"A B"), ':"A B"'
|
114
|
-
assert_source ':foo'
|
115
|
-
assert_source ':"A B"'
|
116
|
-
assert_source ':"A\"B"'
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'regexp' do
|
120
|
-
assert_source '/foo/'
|
121
|
-
assert_source %q(/[^-+',.\/:@[:alnum:]\[\]\x80-\xff]+/)
|
122
|
-
assert_source '/foo#{@bar}/'
|
123
|
-
assert_source '/foo#{@bar}/imx'
|
124
|
-
assert_source "/\n/"
|
125
|
-
assert_source '/\n/'
|
126
|
-
assert_source "/\n/x"
|
127
|
-
assert_generates '%r(/)', '/\//'
|
128
|
-
assert_generates '%r(\))', '/)/'
|
129
|
-
assert_generates '%r(#{@bar}baz)', '/#{@bar}baz/'
|
130
|
-
end
|
131
|
-
|
132
|
-
context 'dynamic string' do
|
133
|
-
assert_source %q("foo#{@bar}")
|
134
|
-
assert_source %q("fo\no#{bar}b\naz")
|
135
|
-
end
|
136
|
-
|
137
|
-
context 'dynamic symbol' do
|
138
|
-
assert_source ':"foo#{bar}baz"'
|
139
|
-
assert_source ':"fo\no#{bar}b\naz"'
|
140
|
-
assert_source ':"#{bar}foo"'
|
141
|
-
assert_source ':"foo#{bar}"'
|
142
|
-
end
|
143
|
-
|
144
|
-
context 'irange' do
|
145
|
-
assert_generates '1..2', %q(1..2)
|
146
|
-
assert_source '(0.0 / 0.0)..1'
|
147
|
-
assert_source '1..(0.0 / 0.0)'
|
148
|
-
end
|
149
|
-
|
150
|
-
context 'erange' do
|
151
|
-
assert_generates '1...2', %q(1...2)
|
152
|
-
end
|
153
|
-
|
154
|
-
context 'float' do
|
155
|
-
assert_source '-0.1'
|
156
|
-
assert_source '0.1'
|
157
|
-
assert_generates s(:float, -0.1), '-0.1'
|
158
|
-
assert_generates s(:float, 0.1), '0.1'
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'array' do
|
162
|
-
assert_source '[1, 2]'
|
163
|
-
assert_source '[1]'
|
164
|
-
assert_source '[]'
|
165
|
-
assert_source '[1, *@foo]'
|
166
|
-
assert_source '[*@foo, 1]', RUBIES - %w(1.8)
|
167
|
-
assert_source '[*@foo, *@baz]', RUBIES - %w(1.8)
|
168
|
-
assert_generates '%w(foo bar)', %q(["foo", "bar"])
|
169
|
-
end
|
170
|
-
|
171
|
-
context 'hash' do
|
172
|
-
assert_source '{}'
|
173
|
-
assert_source '{1 => 2}'
|
174
|
-
assert_source '{1 => 2, 3 => 4}'
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
context 'access' do
|
179
|
-
assert_source '@a'
|
180
|
-
assert_source '@@a'
|
181
|
-
assert_source '$a'
|
182
|
-
assert_source '$1'
|
183
|
-
assert_source '$`'
|
184
|
-
assert_source 'CONST'
|
185
|
-
assert_source 'SCOPED::CONST'
|
186
|
-
assert_source '::TOPLEVEL'
|
187
|
-
assert_source '::TOPLEVEL::CONST'
|
188
|
-
end
|
189
|
-
|
190
|
-
context 'break' do
|
191
|
-
assert_source 'break'
|
192
|
-
assert_source 'break(a)'
|
193
|
-
end
|
194
|
-
|
195
|
-
context 'next' do
|
196
|
-
assert_source 'next'
|
197
|
-
assert_source 'next(bar)'
|
198
|
-
end
|
199
|
-
|
200
|
-
context 'retry' do
|
201
|
-
assert_source 'retry'
|
202
|
-
end
|
203
|
-
|
204
|
-
context 'redo' do
|
205
|
-
assert_source 'redo'
|
206
|
-
end
|
207
|
-
|
208
|
-
context 'singletons' do
|
209
|
-
assert_source 'self'
|
210
|
-
assert_source 'true'
|
211
|
-
assert_source 'false'
|
212
|
-
assert_source 'nil'
|
213
|
-
end
|
214
|
-
|
215
|
-
context 'magic keywords' do
|
216
|
-
assert_generates '__ENCODING__', 'Encoding::UTF_8', RUBIES - %w(1.8)
|
217
|
-
assert_source '__FILE__'
|
218
|
-
assert_source '__LINE__'
|
219
|
-
end
|
220
|
-
|
221
|
-
context 'assignment' do
|
222
|
-
context 'single' do
|
223
|
-
assert_source 'a = 1'
|
224
|
-
assert_source '@a = 1'
|
225
|
-
assert_source '@@a = 1'
|
226
|
-
assert_source '$a = 1'
|
227
|
-
assert_source 'CONST = 1'
|
228
|
-
end
|
229
|
-
|
230
|
-
context 'multiple' do
|
231
|
-
assert_source 'a, b = 1, 2'
|
232
|
-
assert_source 'a, *foo = 1, 2'
|
233
|
-
assert_source 'a, * = 1, 2'
|
234
|
-
assert_source '*foo = 1, 2'
|
235
|
-
assert_source '@a, @b = 1, 2'
|
236
|
-
assert_source 'a.foo, a.bar = 1, 2'
|
237
|
-
assert_source 'a[0, 2]'
|
238
|
-
assert_source 'a[0], a[1] = 1, 2'
|
239
|
-
assert_source 'a[*foo], a[1] = 1, 2'
|
240
|
-
assert_source '@@a, @@b = 1, 2'
|
241
|
-
assert_source '$a, $b = 1, 2'
|
242
|
-
assert_source 'a, b = foo'
|
243
|
-
assert_source 'a, (b, c) = 1, [2, 3]'
|
244
|
-
assert_generates_one_way s(:mlhs, s(:lvasgn, :a), s(:lvasgn, :b)), 'a, b'
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
context 'return' do
|
249
|
-
assert_source <<-RUBY
|
250
|
-
return
|
251
|
-
RUBY
|
252
|
-
|
253
|
-
assert_source <<-RUBY
|
254
|
-
return(1)
|
255
|
-
RUBY
|
256
|
-
end
|
257
|
-
|
258
|
-
context 'send' do
|
259
|
-
assert_source 'foo'
|
260
|
-
assert_source 'self.foo'
|
261
|
-
assert_source 'a.foo'
|
262
|
-
assert_source 'A.foo'
|
263
|
-
assert_source 'foo[1]'
|
264
|
-
assert_source 'foo[*baz]'
|
265
|
-
assert_source 'foo(1)'
|
266
|
-
assert_source 'foo(bar)'
|
267
|
-
assert_source 'foo(&block)'
|
268
|
-
assert_source 'foo(*arguments)'
|
269
|
-
assert_source 'foo(*arguments)'
|
270
|
-
assert_source <<-RUBY
|
271
|
-
foo do
|
272
|
-
end
|
273
|
-
RUBY
|
274
|
-
|
275
|
-
assert_source <<-RUBY
|
276
|
-
foo(1) do
|
277
|
-
nil
|
278
|
-
end
|
279
|
-
RUBY
|
280
|
-
|
281
|
-
assert_source <<-RUBY
|
282
|
-
foo do |a, b|
|
283
|
-
nil
|
284
|
-
end
|
285
|
-
RUBY
|
286
|
-
|
287
|
-
assert_source <<-RUBY
|
288
|
-
foo do |a, *b|
|
289
|
-
nil
|
290
|
-
end
|
291
|
-
RUBY
|
292
|
-
|
293
|
-
assert_source <<-RUBY
|
294
|
-
foo do |a, *|
|
295
|
-
nil
|
296
|
-
end
|
297
|
-
RUBY
|
298
|
-
|
299
|
-
assert_source <<-RUBY
|
300
|
-
foo do
|
301
|
-
bar
|
302
|
-
end
|
303
|
-
RUBY
|
304
|
-
|
305
|
-
assert_source <<-RUBY
|
306
|
-
foo.bar(*args)
|
307
|
-
RUBY
|
308
|
-
|
309
|
-
assert_source <<-RUBY
|
310
|
-
foo.bar do |(a, b), c|
|
311
|
-
d
|
312
|
-
end
|
313
|
-
RUBY
|
314
|
-
|
315
|
-
assert_source <<-RUBY
|
316
|
-
foo.bar do |(a, b)|
|
317
|
-
d
|
318
|
-
end
|
319
|
-
RUBY
|
320
|
-
|
321
|
-
# Special cases
|
322
|
-
assert_source '(1..2).max'
|
323
|
-
|
324
|
-
assert_source 'foo.bar(*args)'
|
325
|
-
assert_source 'foo.bar(*arga, foo, *argb)', RUBIES - %w(1.8)
|
326
|
-
assert_source 'foo.bar(*args, foo)', RUBIES - %w(1.8)
|
327
|
-
assert_source 'foo.bar(foo, *args)'
|
328
|
-
assert_source 'foo.bar(foo, *args, &block)'
|
329
|
-
assert_source <<-RUBY
|
330
|
-
foo(bar, *args)
|
331
|
-
RUBY
|
332
|
-
|
333
|
-
assert_source <<-RUBY
|
334
|
-
foo(*args, &block)
|
335
|
-
RUBY
|
336
|
-
|
337
|
-
assert_source 'foo.bar(&baz)'
|
338
|
-
assert_source 'foo.bar(:baz, &baz)'
|
339
|
-
assert_source 'foo.bar=(:baz)'
|
340
|
-
assert_source 'self.foo=(:bar)'
|
341
|
-
end
|
342
|
-
|
343
|
-
context 'begin; end' do
|
344
|
-
assert_generates s(:begin), ''
|
345
|
-
|
346
|
-
assert_source <<-RUBY
|
347
|
-
foo
|
348
|
-
bar
|
349
|
-
RUBY
|
350
|
-
|
351
|
-
assert_source <<-RUBY
|
352
|
-
begin
|
353
|
-
foo
|
354
|
-
bar
|
355
|
-
end.blah
|
356
|
-
RUBY
|
357
|
-
end
|
358
|
-
|
359
|
-
context 'begin / rescue / ensure' do
|
360
|
-
assert_source <<-RUBY
|
361
|
-
begin
|
362
|
-
foo
|
363
|
-
ensure
|
364
|
-
bar
|
365
|
-
baz
|
366
|
-
end
|
367
|
-
RUBY
|
368
|
-
|
369
|
-
assert_source <<-RUBY
|
370
|
-
begin
|
371
|
-
foo
|
372
|
-
rescue
|
373
|
-
baz
|
374
|
-
end
|
375
|
-
RUBY
|
376
|
-
|
377
|
-
assert_source <<-RUBY
|
378
|
-
begin
|
379
|
-
begin
|
380
|
-
foo
|
381
|
-
bar
|
382
|
-
rescue
|
383
|
-
end
|
384
|
-
rescue
|
385
|
-
baz
|
386
|
-
bar
|
387
|
-
end
|
388
|
-
RUBY
|
389
|
-
|
390
|
-
assert_source <<-RUBY
|
391
|
-
begin
|
392
|
-
foo
|
393
|
-
bar
|
394
|
-
rescue
|
395
|
-
baz
|
396
|
-
bar
|
397
|
-
end
|
398
|
-
RUBY
|
399
|
-
|
400
|
-
assert_source <<-RUBY
|
401
|
-
begin
|
402
|
-
foo
|
403
|
-
rescue Exception
|
404
|
-
bar
|
405
|
-
end
|
406
|
-
RUBY
|
407
|
-
|
408
|
-
assert_source <<-RUBY
|
409
|
-
begin
|
410
|
-
foo
|
411
|
-
rescue => bar
|
412
|
-
bar
|
413
|
-
end
|
414
|
-
RUBY
|
415
|
-
|
416
|
-
assert_source <<-RUBY
|
417
|
-
begin
|
418
|
-
foo
|
419
|
-
rescue Exception, Other => bar
|
420
|
-
bar
|
421
|
-
end
|
422
|
-
RUBY
|
423
|
-
|
424
|
-
assert_source <<-RUBY
|
425
|
-
begin
|
426
|
-
rescue Exception => e
|
427
|
-
end
|
428
|
-
RUBY
|
429
|
-
|
430
|
-
assert_source <<-RUBY
|
431
|
-
begin
|
432
|
-
rescue
|
433
|
-
ensure
|
434
|
-
end
|
435
|
-
RUBY
|
436
|
-
|
437
|
-
assert_source <<-RUBY
|
438
|
-
begin
|
439
|
-
foo
|
440
|
-
rescue Exception => bar
|
441
|
-
bar
|
442
|
-
end
|
443
|
-
RUBY
|
444
|
-
|
445
|
-
assert_source <<-RUBY
|
446
|
-
begin
|
447
|
-
bar
|
448
|
-
rescue SomeError, *bar
|
449
|
-
baz
|
450
|
-
end
|
451
|
-
RUBY
|
452
|
-
|
453
|
-
assert_source <<-RUBY
|
454
|
-
begin
|
455
|
-
bar
|
456
|
-
rescue SomeError, *bar => exception
|
457
|
-
baz
|
458
|
-
end
|
459
|
-
RUBY
|
460
|
-
|
461
|
-
assert_source <<-RUBY
|
462
|
-
begin
|
463
|
-
bar
|
464
|
-
rescue *bar
|
465
|
-
baz
|
466
|
-
end
|
467
|
-
RUBY
|
468
|
-
|
469
|
-
assert_source <<-RUBY
|
470
|
-
begin
|
471
|
-
bar
|
472
|
-
rescue LoadError
|
473
|
-
end
|
474
|
-
RUBY
|
475
|
-
|
476
|
-
assert_source <<-RUBY
|
477
|
-
begin
|
478
|
-
bar
|
479
|
-
rescue
|
480
|
-
else
|
481
|
-
baz
|
482
|
-
end
|
483
|
-
RUBY
|
484
|
-
|
485
|
-
assert_source <<-RUBY
|
486
|
-
begin
|
487
|
-
bar
|
488
|
-
rescue *bar => exception
|
489
|
-
baz
|
490
|
-
end
|
491
|
-
RUBY
|
492
|
-
end
|
493
|
-
|
494
|
-
context 'super' do
|
495
|
-
assert_source 'super'
|
496
|
-
|
497
|
-
assert_source <<-RUBY
|
498
|
-
super do
|
499
|
-
foo
|
500
|
-
end
|
501
|
-
RUBY
|
502
|
-
|
503
|
-
assert_source 'super()'
|
504
|
-
|
505
|
-
assert_source <<-RUBY
|
506
|
-
super() do
|
507
|
-
foo
|
508
|
-
end
|
509
|
-
RUBY
|
510
|
-
|
511
|
-
assert_source 'super(a)'
|
512
|
-
|
513
|
-
assert_source <<-RUBY
|
514
|
-
super(a) do
|
515
|
-
foo
|
516
|
-
end
|
517
|
-
RUBY
|
518
|
-
|
519
|
-
assert_source 'super(a, b)'
|
520
|
-
|
521
|
-
assert_source <<-RUBY
|
522
|
-
super(a, b) do
|
523
|
-
foo
|
524
|
-
end
|
525
|
-
RUBY
|
526
|
-
|
527
|
-
assert_source 'super(&block)'
|
528
|
-
assert_source 'super(a, &block)'
|
529
|
-
end
|
530
|
-
|
531
|
-
context 'undef' do
|
532
|
-
assert_source 'undef :foo'
|
533
|
-
end
|
534
|
-
|
535
|
-
context 'BEGIN' do
|
536
|
-
assert_source <<-RUBY
|
537
|
-
BEGIN {
|
538
|
-
foo
|
539
|
-
}
|
540
|
-
RUBY
|
541
|
-
end
|
542
|
-
|
543
|
-
context 'END' do
|
544
|
-
assert_source <<-RUBY
|
545
|
-
END {
|
546
|
-
foo
|
547
|
-
}
|
548
|
-
RUBY
|
549
|
-
end
|
550
|
-
|
551
|
-
context 'alias' do
|
552
|
-
assert_source <<-RUBY
|
553
|
-
alias $foo $bar
|
554
|
-
RUBY
|
555
|
-
|
556
|
-
assert_source <<-RUBY
|
557
|
-
alias :foo :bar
|
558
|
-
RUBY
|
559
|
-
end
|
560
|
-
|
561
|
-
context 'yield' do
|
562
|
-
context 'without arguments' do
|
563
|
-
assert_source 'yield'
|
564
|
-
end
|
565
|
-
|
566
|
-
context 'with argument' do
|
567
|
-
assert_source 'yield(a)'
|
568
|
-
end
|
569
|
-
|
570
|
-
context 'with arguments' do
|
571
|
-
assert_source 'yield(a, b)'
|
572
|
-
end
|
573
|
-
end
|
574
|
-
|
575
|
-
context 'if statement' do
|
576
|
-
assert_source <<-RUBY
|
577
|
-
if /foo/
|
578
|
-
bar
|
579
|
-
end
|
580
|
-
RUBY
|
581
|
-
|
582
|
-
assert_source <<-RUBY
|
583
|
-
if 3
|
584
|
-
9
|
585
|
-
end
|
586
|
-
RUBY
|
587
|
-
|
588
|
-
assert_source <<-RUBY
|
589
|
-
if 4
|
590
|
-
5
|
591
|
-
else
|
592
|
-
6
|
593
|
-
end
|
594
|
-
RUBY
|
595
|
-
|
596
|
-
assert_source <<-RUBY
|
597
|
-
unless 3
|
598
|
-
nil
|
599
|
-
end
|
600
|
-
RUBY
|
601
|
-
|
602
|
-
assert_source <<-RUBY
|
603
|
-
unless 3
|
604
|
-
9
|
605
|
-
end
|
606
|
-
RUBY
|
607
|
-
end
|
608
|
-
|
609
|
-
context 'def' do
|
610
|
-
context 'on instance' do
|
611
|
-
|
612
|
-
assert_source <<-RUBY
|
613
|
-
def foo
|
614
|
-
end
|
615
|
-
RUBY
|
616
|
-
|
617
|
-
assert_source <<-RUBY
|
618
|
-
def foo
|
619
|
-
bar
|
620
|
-
end
|
621
|
-
RUBY
|
622
|
-
|
623
|
-
assert_source <<-RUBY
|
624
|
-
def foo
|
625
|
-
bar
|
626
|
-
ensure
|
627
|
-
baz
|
628
|
-
end
|
629
|
-
RUBY
|
630
|
-
|
631
|
-
assert_source <<-RUBY
|
632
|
-
def foo
|
633
|
-
bar
|
634
|
-
rescue
|
635
|
-
baz
|
636
|
-
end
|
637
|
-
RUBY
|
638
|
-
|
639
|
-
assert_source <<-RUBY
|
640
|
-
def foo(bar)
|
641
|
-
bar
|
642
|
-
end
|
643
|
-
RUBY
|
644
|
-
|
645
|
-
assert_source <<-RUBY
|
646
|
-
def foo(bar, baz)
|
647
|
-
bar
|
648
|
-
end
|
649
|
-
RUBY
|
650
|
-
|
651
|
-
assert_source <<-RUBY
|
652
|
-
def foo(bar = true)
|
653
|
-
bar
|
654
|
-
end
|
655
|
-
RUBY
|
656
|
-
|
657
|
-
assert_source <<-RUBY
|
658
|
-
def foo(bar, baz = true)
|
659
|
-
bar
|
660
|
-
end
|
661
|
-
RUBY
|
662
|
-
|
663
|
-
assert_source <<-RUBY, %w(1.9 2.0)
|
664
|
-
def foo(bar, baz = true, foo)
|
665
|
-
bar
|
666
|
-
end
|
667
|
-
RUBY
|
668
|
-
|
669
|
-
assert_source <<-RUBY, %w(2.1)
|
670
|
-
def foo(bar: 1)
|
671
|
-
end
|
672
|
-
RUBY
|
673
|
-
|
674
|
-
assert_source <<-RUBY, %w(2.0)
|
675
|
-
def foo(**bar)
|
676
|
-
end
|
677
|
-
RUBY
|
678
|
-
|
679
|
-
assert_source <<-RUBY
|
680
|
-
def foo(*)
|
681
|
-
bar
|
682
|
-
end
|
683
|
-
RUBY
|
684
|
-
|
685
|
-
assert_source <<-RUBY
|
686
|
-
def foo(*bar)
|
687
|
-
bar
|
688
|
-
end
|
689
|
-
RUBY
|
690
|
-
|
691
|
-
assert_source <<-RUBY
|
692
|
-
def foo(bar, *baz)
|
693
|
-
bar
|
694
|
-
end
|
695
|
-
RUBY
|
696
|
-
|
697
|
-
assert_source <<-RUBY
|
698
|
-
def foo(baz = true, *bor)
|
699
|
-
bar
|
700
|
-
end
|
701
|
-
RUBY
|
702
|
-
|
703
|
-
assert_source <<-RUBY
|
704
|
-
def foo(baz = true, *bor, &block)
|
705
|
-
bar
|
706
|
-
end
|
707
|
-
RUBY
|
708
|
-
|
709
|
-
assert_source <<-RUBY
|
710
|
-
def foo(bar, baz = true, *bor)
|
711
|
-
bar
|
712
|
-
end
|
713
|
-
RUBY
|
714
|
-
|
715
|
-
assert_source <<-RUBY
|
716
|
-
def foo(&block)
|
717
|
-
bar
|
718
|
-
end
|
719
|
-
RUBY
|
720
|
-
|
721
|
-
assert_source <<-RUBY
|
722
|
-
def foo(bar, &block)
|
723
|
-
bar
|
724
|
-
end
|
725
|
-
RUBY
|
726
|
-
|
727
|
-
assert_source <<-RUBY
|
728
|
-
def foo
|
729
|
-
bar
|
730
|
-
baz
|
731
|
-
end
|
732
|
-
RUBY
|
733
|
-
end
|
734
|
-
|
735
|
-
context 'on singleton' do
|
736
|
-
assert_source <<-RUBY
|
737
|
-
def self.foo
|
738
|
-
end
|
739
|
-
RUBY
|
740
|
-
|
741
|
-
|
742
|
-
assert_source <<-RUBY
|
743
|
-
def self.foo
|
744
|
-
bar
|
745
|
-
end
|
746
|
-
RUBY
|
747
|
-
|
748
|
-
assert_source <<-RUBY
|
749
|
-
def self.foo
|
750
|
-
bar
|
751
|
-
baz
|
752
|
-
end
|
753
|
-
RUBY
|
754
|
-
|
755
|
-
assert_source <<-RUBY
|
756
|
-
def Foo.bar
|
757
|
-
bar
|
758
|
-
end
|
759
|
-
RUBY
|
760
|
-
|
761
|
-
end
|
762
|
-
|
763
|
-
context 'class' do
|
764
|
-
assert_source <<-RUBY
|
765
|
-
class TestClass
|
766
|
-
end
|
767
|
-
RUBY
|
768
|
-
|
769
|
-
assert_source <<-RUBY
|
770
|
-
class << some_object
|
771
|
-
end
|
772
|
-
RUBY
|
773
|
-
|
774
|
-
assert_source <<-RUBY
|
775
|
-
class << some_object
|
776
|
-
the_body
|
777
|
-
end
|
778
|
-
RUBY
|
779
|
-
|
780
|
-
assert_source <<-RUBY
|
781
|
-
class SomeNameSpace::TestClass
|
782
|
-
end
|
783
|
-
RUBY
|
784
|
-
|
785
|
-
assert_source <<-RUBY
|
786
|
-
class Some::Name::Space::TestClass
|
787
|
-
end
|
788
|
-
RUBY
|
789
|
-
|
790
|
-
assert_source <<-RUBY
|
791
|
-
class TestClass < Object
|
792
|
-
end
|
793
|
-
RUBY
|
794
|
-
|
795
|
-
assert_source <<-RUBY
|
796
|
-
class TestClass < SomeNameSpace::Object
|
797
|
-
end
|
798
|
-
RUBY
|
799
|
-
|
800
|
-
assert_source <<-RUBY
|
801
|
-
class TestClass
|
802
|
-
def foo
|
803
|
-
:bar
|
804
|
-
end
|
805
|
-
end
|
806
|
-
RUBY
|
807
|
-
|
808
|
-
assert_source <<-RUBY
|
809
|
-
class ::TestClass
|
810
|
-
end
|
811
|
-
RUBY
|
812
|
-
end
|
813
|
-
|
814
|
-
context 'module' do
|
815
|
-
|
816
|
-
assert_source <<-RUBY
|
817
|
-
module TestModule
|
818
|
-
end
|
819
|
-
RUBY
|
820
|
-
|
821
|
-
assert_source <<-RUBY
|
822
|
-
module SomeNameSpace::TestModule
|
823
|
-
end
|
824
|
-
RUBY
|
825
|
-
|
826
|
-
assert_source <<-RUBY
|
827
|
-
module Some::Name::Space::TestModule
|
828
|
-
end
|
829
|
-
RUBY
|
830
|
-
|
831
|
-
assert_source <<-RUBY
|
832
|
-
module TestModule
|
833
|
-
def foo
|
834
|
-
:bar
|
835
|
-
end
|
836
|
-
end
|
837
|
-
RUBY
|
838
|
-
|
839
|
-
end
|
840
|
-
|
841
|
-
context 'op assign' do
|
842
|
-
%w(|= ||= &= &&= += -= *= /= **= %=).each do |op|
|
843
|
-
assert_source "self.foo #{op} bar"
|
844
|
-
assert_source "foo[key] #{op} bar"
|
845
|
-
end
|
846
|
-
end
|
847
|
-
|
848
|
-
context 'element assignment' do
|
849
|
-
assert_source 'array[index] = value'
|
850
|
-
assert_source 'array[*index] = value'
|
851
|
-
|
852
|
-
%w(+ - * / % & | || &&).each do |operator|
|
853
|
-
context "with #{operator}" do
|
854
|
-
assert_source "array[index] #{operator}= 2"
|
855
|
-
assert_source "array[] #{operator}= 2"
|
856
|
-
end
|
857
|
-
end
|
858
|
-
end
|
859
|
-
|
860
|
-
context 'defined?' do
|
861
|
-
assert_source <<-RUBY
|
862
|
-
defined?(@foo)
|
863
|
-
RUBY
|
864
|
-
|
865
|
-
assert_source <<-RUBY
|
866
|
-
defined?(Foo)
|
867
|
-
RUBY
|
868
|
-
end
|
869
|
-
end
|
870
|
-
|
871
|
-
context 'lambda' do
|
872
|
-
assert_source <<-RUBY
|
873
|
-
lambda do
|
874
|
-
end
|
875
|
-
RUBY
|
876
|
-
|
877
|
-
assert_source <<-RUBY
|
878
|
-
lambda do |a, b|
|
879
|
-
a
|
880
|
-
end
|
881
|
-
RUBY
|
882
|
-
end
|
883
|
-
|
884
|
-
context 'match operators' do
|
885
|
-
assert_source <<-RUBY
|
886
|
-
/bar/ =~ foo
|
887
|
-
RUBY
|
888
|
-
|
889
|
-
assert_source <<-RUBY
|
890
|
-
foo =~ /bar/
|
891
|
-
RUBY
|
892
|
-
end
|
893
|
-
|
894
|
-
context 'binary operator methods' do
|
895
|
-
%w(+ - * / & | << >> == === != <= < <=> > >= =~ !~ ^ **).each do |operator|
|
896
|
-
rubies = RUBIES - (%w(!= !~).include?(operator) ? %w(1.8) : [])
|
897
|
-
assert_source "1 #{operator} 2", rubies
|
898
|
-
assert_source "left.#{operator}(*foo)", rubies
|
899
|
-
assert_source "left.#{operator}(a, b)", rubies
|
900
|
-
assert_source "self #{operator} b", rubies
|
901
|
-
assert_source "a #{operator} b", rubies
|
902
|
-
assert_source "(a #{operator} b).foo", rubies
|
903
|
-
end
|
904
|
-
end
|
905
|
-
|
906
|
-
context 'nested binary operators' do
|
907
|
-
assert_source '(a + b) / (c - d)'
|
908
|
-
assert_source '(a + b) / (c.-(e, f))'
|
909
|
-
assert_source '(a + b) / (c.-(*f))'
|
910
|
-
end
|
911
|
-
|
912
|
-
context 'binary operator' do
|
913
|
-
assert_source '((a) || (break(foo)))'
|
914
|
-
assert_source '((break(foo)) || (a))'
|
915
|
-
assert_source '((a) || (b)).foo'
|
916
|
-
assert_source '((a) || (((b) || (c))))'
|
917
|
-
end
|
918
|
-
|
919
|
-
{ :or => :'||', :and => :'&&' }.each do |word, symbol|
|
920
|
-
assert_generates "a #{word} break foo", "((a) #{symbol} (break(foo)))"
|
921
|
-
end
|
922
|
-
|
923
|
-
context 'expansion of shortcuts' do
|
924
|
-
assert_source 'a += 2'
|
925
|
-
assert_source 'a -= 2'
|
926
|
-
assert_source 'a **= 2'
|
927
|
-
assert_source 'a *= 2'
|
928
|
-
assert_source 'a /= 2'
|
929
|
-
end
|
930
|
-
|
931
|
-
context 'shortcuts' do
|
932
|
-
assert_source 'a &&= b'
|
933
|
-
assert_source 'a ||= 2'
|
934
|
-
assert_source '(a ||= 2).bar'
|
935
|
-
end
|
936
|
-
|
937
|
-
context 'flip flops' do
|
938
|
-
context 'inclusive' do
|
939
|
-
assert_source <<-RUBY
|
940
|
-
if (i == 4)..(i == 4)
|
941
|
-
foo
|
942
|
-
end
|
943
|
-
RUBY
|
944
|
-
end
|
945
|
-
|
946
|
-
context 'exclusive' do
|
947
|
-
assert_source <<-RUBY
|
948
|
-
if (i == 4)...(i == 4)
|
949
|
-
foo
|
950
|
-
end
|
951
|
-
RUBY
|
952
|
-
end
|
953
|
-
end
|
954
|
-
|
955
|
-
context 'case statement' do
|
956
|
-
assert_source <<-RUBY
|
957
|
-
case
|
958
|
-
when bar
|
959
|
-
baz
|
960
|
-
when baz
|
961
|
-
bar
|
962
|
-
end
|
963
|
-
RUBY
|
964
|
-
|
965
|
-
assert_source <<-RUBY
|
966
|
-
case foo
|
967
|
-
when bar
|
968
|
-
when baz
|
969
|
-
bar
|
970
|
-
end
|
971
|
-
RUBY
|
972
|
-
|
973
|
-
|
974
|
-
assert_source <<-RUBY
|
975
|
-
case foo
|
976
|
-
when bar
|
977
|
-
baz
|
978
|
-
when baz
|
979
|
-
bar
|
980
|
-
end
|
981
|
-
RUBY
|
982
|
-
|
983
|
-
assert_source <<-RUBY
|
984
|
-
case foo
|
985
|
-
when bar, baz
|
986
|
-
:other
|
987
|
-
end
|
988
|
-
RUBY
|
989
|
-
|
990
|
-
assert_source <<-RUBY
|
991
|
-
case foo
|
992
|
-
when *bar
|
993
|
-
:value
|
994
|
-
end
|
995
|
-
RUBY
|
996
|
-
|
997
|
-
assert_source <<-RUBY
|
998
|
-
case foo
|
999
|
-
when bar
|
1000
|
-
baz
|
1001
|
-
else
|
1002
|
-
:foo
|
1003
|
-
end
|
1004
|
-
RUBY
|
1005
|
-
end
|
1006
|
-
|
1007
|
-
context 'for' do
|
1008
|
-
assert_source <<-RUBY
|
1009
|
-
for a in bar do
|
1010
|
-
baz
|
1011
|
-
end
|
1012
|
-
RUBY
|
1013
|
-
|
1014
|
-
assert_source <<-RUBY
|
1015
|
-
for a, *b in bar do
|
1016
|
-
baz
|
1017
|
-
end
|
1018
|
-
RUBY
|
1019
|
-
|
1020
|
-
assert_source <<-RUBY
|
1021
|
-
for a, b in bar do
|
1022
|
-
baz
|
1023
|
-
end
|
1024
|
-
RUBY
|
1025
|
-
end
|
1026
|
-
|
1027
|
-
context 'unary operators' do
|
1028
|
-
assert_source '!1'
|
1029
|
-
assert_source '!!1'
|
1030
|
-
assert_source '~a'
|
1031
|
-
assert_source '-a'
|
1032
|
-
assert_source '+a'
|
1033
|
-
end
|
1034
|
-
|
1035
|
-
context 'loop' do
|
1036
|
-
assert_source <<-RUBY
|
1037
|
-
loop do
|
1038
|
-
foo
|
1039
|
-
end
|
1040
|
-
RUBY
|
1041
|
-
end
|
1042
|
-
|
1043
|
-
context 'post conditions' do
|
1044
|
-
assert_source <<-RUBY
|
1045
|
-
begin
|
1046
|
-
foo
|
1047
|
-
end while baz
|
1048
|
-
RUBY
|
1049
|
-
|
1050
|
-
assert_source <<-RUBY
|
1051
|
-
begin
|
1052
|
-
foo
|
1053
|
-
bar
|
1054
|
-
end until baz
|
1055
|
-
RUBY
|
1056
|
-
|
1057
|
-
assert_source <<-RUBY
|
1058
|
-
begin
|
1059
|
-
foo
|
1060
|
-
bar
|
1061
|
-
end while baz
|
1062
|
-
RUBY
|
1063
|
-
end
|
1064
|
-
|
1065
|
-
context 'while' do
|
1066
|
-
assert_source <<-RUBY
|
1067
|
-
while false
|
1068
|
-
end
|
1069
|
-
RUBY
|
1070
|
-
|
1071
|
-
assert_source <<-RUBY
|
1072
|
-
while false
|
1073
|
-
3
|
1074
|
-
end
|
1075
|
-
RUBY
|
1076
|
-
end
|
1077
|
-
|
1078
|
-
context 'until' do
|
1079
|
-
assert_source <<-RUBY
|
1080
|
-
until false
|
1081
|
-
end
|
1082
|
-
RUBY
|
1083
|
-
|
1084
|
-
assert_source <<-RUBY
|
1085
|
-
until false
|
1086
|
-
3
|
1087
|
-
end
|
1088
|
-
RUBY
|
1089
|
-
end
|
1090
|
-
|
1091
|
-
end
|