ruby2ruby 2.3.1 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.txt +10 -0
- data/Rakefile +1 -1
- data/lib/ruby2ruby.rb +14 -9
- data/test/test_ruby2ruby.rb +173 -74
- metadata +4 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14e891234e3089376394e56c1a06d97198a44294
|
4
|
+
data.tar.gz: aa54d78c6ddefd682cf2dfce42c2b30a30882325
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1498c9b51e93f477b02d8114bbd1718bfbdce2f588681d1e8162d70297ce6ceeba34c5f2ced5bc689ecccc6ce0bbb058dc2695a6380c753af96ae15db35166ff
|
7
|
+
data.tar.gz: 9ecce60ed4b40ac244f786f3e3f6dbfaa4d111ce221328f66efbb0dcd4208c4e2b3752c920279012b4771333e9afb690198f141ae9c4b129dc146a1841f73811
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 2.3.2 / 2016-11-30
|
2
|
+
|
3
|
+
* 5 bug fixes:
|
4
|
+
|
5
|
+
* FINALLY fixed a problem with escaping in dstrs. (nex3)
|
6
|
+
* Fix using match3 on LHS of call. (eqv)
|
7
|
+
* Fixed handling defn that starts w/ begin+rescue+other stuff. (eqv)
|
8
|
+
* Fixed return expressions with complex RHS. (eqv)
|
9
|
+
* Tweaked sexp_processor dependency to ~> 4.6 to sync them better
|
10
|
+
|
1
11
|
=== 2.3.1 / 2016-10-09
|
2
12
|
|
3
13
|
* 1 minor enhancement:
|
data/Rakefile
CHANGED
data/lib/ruby2ruby.rb
CHANGED
@@ -31,7 +31,7 @@ end
|
|
31
31
|
# Generate ruby code from a sexp.
|
32
32
|
|
33
33
|
class Ruby2Ruby < SexpProcessor
|
34
|
-
VERSION = "2.3.
|
34
|
+
VERSION = "2.3.2" # :nodoc:
|
35
35
|
|
36
36
|
# cutoff for one-liners
|
37
37
|
LINE_LENGTH = 78
|
@@ -50,6 +50,7 @@ class Ruby2Ruby < SexpProcessor
|
|
50
50
|
:flip3,
|
51
51
|
:lasgn,
|
52
52
|
:masgn,
|
53
|
+
:match3,
|
53
54
|
:attrasgn,
|
54
55
|
:op_asgn1,
|
55
56
|
:op_asgn2,
|
@@ -407,11 +408,13 @@ class Ruby2Ruby < SexpProcessor
|
|
407
408
|
body << process(exp.shift)
|
408
409
|
end
|
409
410
|
|
411
|
+
simple = body.size <= 1
|
412
|
+
|
410
413
|
body << "# do nothing" if body.empty?
|
411
414
|
body = body.join("\n")
|
412
415
|
body = body.lines.to_a[1..-2].join("\n") if
|
413
|
-
body =~ /^\Abegin/ && body =~ /^end\z/
|
414
|
-
body = indent(body) unless body =~ /(^|\n)rescue/
|
416
|
+
simple && body =~ /^\Abegin/ && body =~ /^end\z/
|
417
|
+
body = indent(body) unless simple && body =~ /(^|\n)rescue/
|
415
418
|
|
416
419
|
return "#{comm}def #{name}#{args}\n#{body}\nend".gsub(/\n\s*\n+/, "\n")
|
417
420
|
end
|
@@ -839,12 +842,14 @@ class Ruby2Ruby < SexpProcessor
|
|
839
842
|
end
|
840
843
|
|
841
844
|
def process_return(exp) # :nodoc:
|
842
|
-
# HACK return "return" + (exp.empty? ? "" : " #{process exp.shift}")
|
843
|
-
|
844
845
|
if exp.empty? then
|
845
|
-
|
846
|
+
"return"
|
846
847
|
else
|
847
|
-
|
848
|
+
rhs = exp.shift
|
849
|
+
rhs_type = rhs.sexp_type
|
850
|
+
rhs = process rhs
|
851
|
+
rhs = "(#{rhs})" if ASSIGN_NODES.include? rhs_type
|
852
|
+
"return #{rhs}"
|
848
853
|
end
|
849
854
|
end
|
850
855
|
|
@@ -1066,12 +1071,12 @@ class Ruby2Ruby < SexpProcessor
|
|
1066
1071
|
# Utility method to escape something interpolated.
|
1067
1072
|
|
1068
1073
|
def dthing_escape type, lit
|
1069
|
-
|
1074
|
+
# TODO: this needs more testing
|
1070
1075
|
case type
|
1071
1076
|
when :dregx then
|
1072
1077
|
lit.gsub(/(\A|[^\\])\//, '\1\/')
|
1073
1078
|
when :dstr, :dsym then
|
1074
|
-
lit.
|
1079
|
+
lit.dump[1..-2]
|
1075
1080
|
when :dxstr then
|
1076
1081
|
lit.gsub(/`/, '\`')
|
1077
1082
|
else
|
data/test/test_ruby2ruby.rb
CHANGED
@@ -83,56 +83,56 @@ class TestRuby2Ruby < R2RTestCase
|
|
83
83
|
def test_hash_parens_str
|
84
84
|
inn = s(:hash, s(:lit, :k), s(:str, "banana"))
|
85
85
|
out = '{ :k => "banana" }'
|
86
|
-
|
86
|
+
assert_parse inn, out
|
87
87
|
end
|
88
88
|
|
89
89
|
def test_hash_parens_lit
|
90
90
|
inn = s(:hash, s(:lit, :k), s(:lit, 0.07))
|
91
91
|
out = "{ :k => 0.07 }"
|
92
|
-
|
92
|
+
assert_parse inn, out
|
93
93
|
end
|
94
94
|
|
95
95
|
def test_hash_parens_bool
|
96
96
|
inn = s(:hash, s(:lit, :k), s(:true))
|
97
97
|
out = "{ :k => true }"
|
98
|
-
|
98
|
+
assert_parse inn, out
|
99
99
|
end
|
100
100
|
|
101
101
|
def test_hash_parens_nil
|
102
102
|
inn = s(:hash, s(:lit, :k), s(:nil))
|
103
103
|
out = "{ :k => nil }"
|
104
|
-
|
104
|
+
assert_parse inn, out
|
105
105
|
end
|
106
106
|
|
107
107
|
def test_hash_parens_lvar
|
108
108
|
inn = s(:hash, s(:lit, :k), s(:lvar, :x))
|
109
109
|
out = "{ :k => x }"
|
110
|
-
|
110
|
+
assert_parse inn, out
|
111
111
|
end
|
112
112
|
|
113
113
|
def test_hash_parens_call
|
114
114
|
inn = s(:hash, s(:lit, :k), s(:call, nil, :foo, s(:lit, :bar)))
|
115
115
|
out = "{ :k => foo(:bar) }"
|
116
|
-
|
116
|
+
assert_parse inn, out
|
117
117
|
end
|
118
118
|
|
119
119
|
def test_hash_parens_iter
|
120
120
|
iter = s(:iter, s(:call, nil, :foo), 0, s(:str, "bar"))
|
121
121
|
inn = s(:hash, s(:lit, :k), iter)
|
122
122
|
out = '{ :k => (foo { "bar" }) }'
|
123
|
-
|
123
|
+
assert_parse inn, out
|
124
124
|
end
|
125
125
|
|
126
126
|
def test_and_alias
|
127
127
|
inn = s(:and, s(:true), s(:alias, s(:lit, :a), s(:lit, :b)))
|
128
128
|
out = "true and (alias :a :b)"
|
129
|
-
|
129
|
+
assert_parse inn, out
|
130
130
|
end
|
131
131
|
|
132
132
|
def test_attr_reader_diff
|
133
133
|
inn = s(:defn, :same, s(:args), s(:ivar, :@diff))
|
134
134
|
out = "def same\n @diff\nend"
|
135
|
-
|
135
|
+
assert_parse inn, out
|
136
136
|
end
|
137
137
|
|
138
138
|
def test_attr_reader_same
|
@@ -140,13 +140,13 @@ class TestRuby2Ruby < R2RTestCase
|
|
140
140
|
|
141
141
|
inn = s(:defn, :same, s(:args), s(:ivar, :@same))
|
142
142
|
out = "attr_reader :same"
|
143
|
-
|
143
|
+
assert_parse inn, out
|
144
144
|
end
|
145
145
|
|
146
146
|
def test_attr_reader_double
|
147
147
|
inn = s(:defn, :same, s(:args), s(:ivar, :@same), s(:ivar, :@diff))
|
148
148
|
out = "def same\n @same\n @diff\nend"
|
149
|
-
|
149
|
+
assert_parse inn, out
|
150
150
|
end
|
151
151
|
|
152
152
|
def test_attr_reader_same_name_diff_body
|
@@ -154,26 +154,126 @@ class TestRuby2Ruby < R2RTestCase
|
|
154
154
|
|
155
155
|
inn = s(:defn, :same, s(:args), s(:not, s(:ivar, :@same)))
|
156
156
|
out = "def same\n (not @same)\nend"
|
157
|
-
|
157
|
+
assert_parse inn, out
|
158
158
|
end
|
159
159
|
|
160
160
|
def test_attr_writer_diff
|
161
161
|
inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@diff, s(:lvar, :o)))
|
162
162
|
out = "def same=(o)\n @diff = o\nend"
|
163
|
-
|
163
|
+
assert_parse inn, out
|
164
|
+
end
|
165
|
+
|
166
|
+
def assert_str exp, src
|
167
|
+
assert_equal s(:str, exp), RubyParser.new.process(src)
|
168
|
+
end
|
169
|
+
|
170
|
+
def assert_dstr exp, int, src
|
171
|
+
assert_equal s(:dstr, exp, s(:evstr, int).compact), RubyParser.new.process(src)
|
172
|
+
end
|
173
|
+
|
174
|
+
def assert_r2r exp, sexp
|
175
|
+
assert_equal exp, Ruby2Ruby.new.process(sexp)
|
176
|
+
end
|
177
|
+
|
178
|
+
def assert_rt src, exp=src.dup
|
179
|
+
assert_equal exp, Ruby2Ruby.new.process(RubyParser.new.parse(src))
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_bug_033
|
183
|
+
# gentle reminder to keep some sanity
|
184
|
+
#
|
185
|
+
# Use %q("...") for raw input strings
|
186
|
+
# Use %q(...) for raw output to avoid double-\'s
|
187
|
+
# Use %(...) for output strings
|
188
|
+
#
|
189
|
+
# don't use '...' at all
|
190
|
+
# only use "..." within sexps
|
191
|
+
|
192
|
+
# "\t"
|
193
|
+
assert_str %(\t), %q("\t")
|
194
|
+
assert_r2r %q("\\t"), s(:str, "\t")
|
195
|
+
assert_rt %q("\t")
|
196
|
+
|
197
|
+
# "\\t"
|
198
|
+
assert_str %(\t), %q("\\t")
|
199
|
+
assert_r2r %q("\\t"), s(:str, "\t")
|
200
|
+
assert_rt %q("\\t")
|
201
|
+
|
202
|
+
# "\\\\t"
|
203
|
+
assert_str %(\\t), %q("\\\\t")
|
204
|
+
assert_r2r %q("\\\\t"), s(:str, "\\t")
|
205
|
+
assert_rt %q("\\\\t")
|
206
|
+
|
207
|
+
# "\t#{}"
|
208
|
+
assert_dstr %(\t), nil, %q("\t#{}")
|
209
|
+
assert_r2r %q("\t#{}"), s(:dstr, "\t", s(:evstr))
|
210
|
+
assert_rt %q("\t#{}")
|
211
|
+
|
212
|
+
# "\\t#{}"
|
213
|
+
assert_dstr %(\t), nil, %q("\\t#{}")
|
214
|
+
assert_r2r %q("\\t#{}"), s(:dstr, "\t", s(:evstr))
|
215
|
+
assert_rt %q("\\t#{}")
|
216
|
+
|
217
|
+
# "\\\\t#{}"
|
218
|
+
assert_dstr %(\\t), nil, %q("\\\\t#{}")
|
219
|
+
assert_r2r %q("\\\\t#{}"), s(:dstr, "\\t", s(:evstr))
|
220
|
+
assert_rt %q("\\\\t#{}")
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_bug_043
|
224
|
+
inn = s(:defn, :check, s(:args),
|
225
|
+
s(:rescue,
|
226
|
+
s(:call, nil, :foo),
|
227
|
+
s(:resbody, s(:array), s(:call, nil, :bar), s(:call, nil, :bar))),
|
228
|
+
s(:call, nil, :bar),
|
229
|
+
s(:if,
|
230
|
+
s(:call, nil, :foo),
|
231
|
+
s(:return, s(:call, nil, :bar)),
|
232
|
+
s(:call, nil, :bar)))
|
233
|
+
|
234
|
+
out = "def check\n begin\n foo\n rescue\n bar\n bar\n end\n bar\n if foo then\n return bar\n else\n bar\n end\nend"
|
235
|
+
|
236
|
+
assert_parse inn, out
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_bug_044
|
240
|
+
inn = s(:if,
|
241
|
+
s(:call,
|
242
|
+
s(:match3, s(:lit, /a/), s(:call, nil, :foo)),
|
243
|
+
:or,
|
244
|
+
s(:call, nil, :bar)),
|
245
|
+
s(:call, nil, :puts, s(:call, nil, :bar)),
|
246
|
+
nil)
|
247
|
+
out = "puts(bar) if (foo =~ /a/).or(bar)"
|
248
|
+
|
249
|
+
assert_parse inn, out
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_bug_045
|
253
|
+
# return foo.baaaaaaar ? ::B.newsss(true) : ::B.newadsfasdfasdfasdfasdsssss(false)
|
254
|
+
|
255
|
+
inn = s(:return,
|
256
|
+
s(:if,
|
257
|
+
s(:call, s(:call, nil, :foo), :baaaaaaar),
|
258
|
+
s(:call, s(:colon3, :B), :newsss, s(:true)),
|
259
|
+
s(:call, s(:colon3, :B), :newadsfasdfasdfasdfasdsssss, s(:false))))
|
260
|
+
|
261
|
+
out = "return (if foo.baaaaaaar then\n ::B.newsss(true)\nelse\n ::B.newadsfasdfasdfasdfasdsssss(false)\nend)"
|
262
|
+
|
263
|
+
assert_parse inn, out
|
164
264
|
end
|
165
265
|
|
166
266
|
def test_attr_writer_double
|
167
267
|
inn = s(:defn, :same=, s(:args, :o),
|
168
268
|
s(:iasgn, :@same, s(:lvar, :o)), s(:iasgn, :@diff, s(:lvar, :o)))
|
169
269
|
out = "def same=(o)\n @same = o\n @diff = o\nend"
|
170
|
-
|
270
|
+
assert_parse inn, out
|
171
271
|
end
|
172
272
|
|
173
273
|
def test_attr_writer_same_name_diff_body
|
174
274
|
inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@same, s(:lit, 42)))
|
175
275
|
out = "def same=(o)\n @same = 42\nend"
|
176
|
-
|
276
|
+
assert_parse inn, out
|
177
277
|
end
|
178
278
|
|
179
279
|
def test_attr_writer_same
|
@@ -181,7 +281,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
181
281
|
|
182
282
|
inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@same , s(:lvar, :o)))
|
183
283
|
out = "attr_writer :same"
|
184
|
-
|
284
|
+
assert_parse inn, out
|
185
285
|
end
|
186
286
|
|
187
287
|
def test_dregx_slash
|
@@ -189,32 +289,32 @@ class TestRuby2Ruby < R2RTestCase
|
|
189
289
|
|
190
290
|
inn = util_thingy(:dregx)
|
191
291
|
out = '/a"b#{(1 + 1)}c"d\/e/'
|
192
|
-
|
292
|
+
assert_parse inn, out, /a"b2c"d\/e/
|
193
293
|
end
|
194
294
|
|
195
295
|
def test_dstr_quote
|
196
296
|
inn = util_thingy(:dstr)
|
197
297
|
out = '"a\"b#{(1 + 1)}c\"d/e"'
|
198
|
-
|
298
|
+
assert_parse inn, out, 'a"b2c"d/e'
|
199
299
|
end
|
200
300
|
|
201
301
|
def test_dsym_quote
|
202
302
|
inn = util_thingy(:dsym)
|
203
303
|
out = ':"a\"b#{(1 + 1)}c\"d/e"'
|
204
|
-
|
304
|
+
assert_parse inn, out, :'a"b2c"d/e'
|
205
305
|
end
|
206
306
|
|
207
307
|
def test_lit_regexp_slash
|
208
308
|
do_not_check_sexp! # dunno why on this one
|
209
309
|
|
210
|
-
|
310
|
+
assert_parse s(:lit, /blah\/blah/), '/blah\/blah/', /blah\/blah/
|
211
311
|
end
|
212
312
|
|
213
313
|
def test_call_kwsplat
|
214
314
|
inn = s(:call, nil, :test_splat, s(:hash, s(:kwsplat, s(:call, nil, :testing))))
|
215
315
|
out = "test_splat(**testing)"
|
216
316
|
|
217
|
-
|
317
|
+
assert_parse inn, out
|
218
318
|
end
|
219
319
|
|
220
320
|
def test_call_arg_assoc_kwsplat
|
@@ -223,14 +323,14 @@ class TestRuby2Ruby < R2RTestCase
|
|
223
323
|
s(:hash, s(:lit, :kw), s(:lit, 2), s(:kwsplat, s(:lit, 3))))
|
224
324
|
out = "f(1, :kw => 2, **3)"
|
225
325
|
|
226
|
-
|
326
|
+
assert_parse inn, out
|
227
327
|
end
|
228
328
|
|
229
329
|
def test_call_kwsplat_x
|
230
330
|
inn = s(:call, nil, :a, s(:hash, s(:kwsplat, s(:lit, 1))))
|
231
331
|
out = "a(**1)"
|
232
332
|
|
233
|
-
|
333
|
+
assert_parse inn, out
|
234
334
|
end
|
235
335
|
|
236
336
|
def test_defn_kwargs
|
@@ -239,7 +339,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
239
339
|
s(:nil))
|
240
340
|
out = "def initialize(arg, keyword: nil, **args)\n # do nothing\nend"
|
241
341
|
|
242
|
-
|
342
|
+
assert_parse inn, out
|
243
343
|
end
|
244
344
|
|
245
345
|
def test_defn_kwargs2
|
@@ -251,20 +351,20 @@ class TestRuby2Ruby < R2RTestCase
|
|
251
351
|
s(:nil))
|
252
352
|
out = "def initialize(arg, kw1: nil, kw2: nil, **args)\n # do nothing\nend"
|
253
353
|
|
254
|
-
|
354
|
+
assert_parse inn, out
|
255
355
|
end
|
256
356
|
|
257
357
|
def test_call_self_index
|
258
|
-
|
358
|
+
assert_parse s(:call, nil, :[], s(:lit, 42)), "self[42]"
|
259
359
|
end
|
260
360
|
|
261
361
|
def test_call_self_index_equals
|
262
|
-
|
362
|
+
assert_parse(s(:attrasgn, s(:self), :[]=, s(:lit, 42), s(:lit, 24)),
|
263
363
|
"self[42] = 24")
|
264
364
|
end
|
265
365
|
|
266
366
|
def test_call_self_index_equals_array
|
267
|
-
|
367
|
+
assert_parse(s(:attrasgn, s(:self), :[]=, s(:lit, 1), s(:lit, 2), s(:lit, 3)),
|
268
368
|
"self[1, 2] = 3")
|
269
369
|
end
|
270
370
|
|
@@ -274,7 +374,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
274
374
|
s(:call, nil, :b))
|
275
375
|
out = "method({ :a => 1 }, b)"
|
276
376
|
|
277
|
-
|
377
|
+
assert_parse inn, out
|
278
378
|
end
|
279
379
|
|
280
380
|
def test_call_arglist_hash_first_last
|
@@ -284,7 +384,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
284
384
|
s(:hash, s(:lit, :c), s(:lit, 1)))
|
285
385
|
out = "method({ :a => 1 }, b, :c => 1)"
|
286
386
|
|
287
|
-
|
387
|
+
assert_parse inn, out
|
288
388
|
end
|
289
389
|
|
290
390
|
def test_call_arglist_hash_last
|
@@ -293,7 +393,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
293
393
|
s(:hash, s(:lit, :a), s(:lit, 1)))
|
294
394
|
out = "method(b, :a => 1)"
|
295
395
|
|
296
|
-
|
396
|
+
assert_parse inn, out
|
297
397
|
end
|
298
398
|
|
299
399
|
def test_call_arglist_if
|
@@ -306,7 +406,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
306
406
|
s(:call, nil, :d)))
|
307
407
|
|
308
408
|
out = "(a + (b ? (c) : (d)))"
|
309
|
-
|
409
|
+
assert_parse inn, out
|
310
410
|
end
|
311
411
|
|
312
412
|
def test_defn_kwsplat
|
@@ -337,7 +437,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
337
437
|
s(:evstr, s(:lvar, :b))))
|
338
438
|
out = 'nil.x { |(a, b)| "#{a}=#{b}" }'
|
339
439
|
|
340
|
-
|
440
|
+
assert_parse inn, out
|
341
441
|
end
|
342
442
|
|
343
443
|
def test_masgn_wtf
|
@@ -357,7 +457,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
357
457
|
|
358
458
|
out = "k, v = *line.split(/\\=/, 2)\nself[k] = v.strip\n"
|
359
459
|
|
360
|
-
|
460
|
+
assert_parse inn, out
|
361
461
|
end
|
362
462
|
|
363
463
|
def test_masgn_splat_wtf
|
@@ -369,14 +469,14 @@ class TestRuby2Ruby < R2RTestCase
|
|
369
469
|
:split,
|
370
470
|
s(:lit, /\=/), s(:lit, 2))))
|
371
471
|
out = 'k, v = *line.split(/\\=/, 2)'
|
372
|
-
|
472
|
+
assert_parse inn, out
|
373
473
|
end
|
374
474
|
|
375
475
|
def test_match3_asgn
|
376
476
|
inn = s(:match3, s(:lit, //), s(:lasgn, :y, s(:call, nil, :x)))
|
377
477
|
out = "(y = x) =~ //"
|
378
478
|
# "y = x =~ //", which matches on x and assigns to y (not what sexp says).
|
379
|
-
|
479
|
+
assert_parse inn, out
|
380
480
|
end
|
381
481
|
|
382
482
|
def test_safe_attrasgn
|
@@ -387,7 +487,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
387
487
|
|
388
488
|
out = "x&.y = 1"
|
389
489
|
|
390
|
-
|
490
|
+
assert_parse inn, out
|
391
491
|
end
|
392
492
|
|
393
493
|
def test_safe_call
|
@@ -399,7 +499,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
399
499
|
s(:lit, 1))
|
400
500
|
|
401
501
|
out ="x&.y&.z(1)"
|
402
|
-
|
502
|
+
assert_parse inn, out
|
403
503
|
end
|
404
504
|
|
405
505
|
def test_safe_call_binary
|
@@ -409,7 +509,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
409
509
|
s(:lit, 1))
|
410
510
|
|
411
511
|
out = "x&.>(1)"
|
412
|
-
|
512
|
+
assert_parse inn, out
|
413
513
|
end
|
414
514
|
|
415
515
|
def test_safe_op_asgn
|
@@ -420,7 +520,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
420
520
|
:+)
|
421
521
|
|
422
522
|
out = "x&.y += z(1)"
|
423
|
-
|
523
|
+
assert_parse inn, out
|
424
524
|
end
|
425
525
|
|
426
526
|
def test_safe_op_asgn2
|
@@ -431,7 +531,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
431
531
|
s(:lit, 1))
|
432
532
|
|
433
533
|
out = "x&.y ||= 1"
|
434
|
-
|
534
|
+
assert_parse inn, out
|
435
535
|
end
|
436
536
|
|
437
537
|
def test_splat_call
|
@@ -443,7 +543,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
443
543
|
s(:lit, /\=/), s(:lit, 2))))
|
444
544
|
|
445
545
|
out = 'x(*line.split(/\=/, 2))'
|
446
|
-
|
546
|
+
assert_parse inn, out
|
447
547
|
end
|
448
548
|
|
449
549
|
def test_resbody_block
|
@@ -455,7 +555,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
455
555
|
s(:call, nil, :x3)))
|
456
556
|
|
457
557
|
out = "begin\n x1\nrescue\n x2\n x3\nend"
|
458
|
-
|
558
|
+
assert_parse inn, out
|
459
559
|
end
|
460
560
|
|
461
561
|
def test_resbody_short_with_begin_end
|
@@ -464,7 +564,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
464
564
|
s(:call, nil, :blah),
|
465
565
|
s(:resbody, s(:array), s(:array)))
|
466
566
|
out = "blah rescue []"
|
467
|
-
|
567
|
+
assert_parse inn, out
|
468
568
|
end
|
469
569
|
|
470
570
|
def test_resbody_short_with_begin_end_multiple
|
@@ -475,7 +575,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
475
575
|
s(:call, nil, :log),
|
476
576
|
s(:call, nil, :raise)))
|
477
577
|
out = "begin\n blah\nrescue\n log\n raise\nend"
|
478
|
-
|
578
|
+
assert_parse inn, out
|
479
579
|
end
|
480
580
|
|
481
581
|
def test_resbody_short_with_defn_multiple
|
@@ -489,7 +589,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
489
589
|
s(:call, nil, :log),
|
490
590
|
s(:call, nil, :raise))))
|
491
591
|
out = "def foo\n a = 1\nrescue\n log\n raise\nend"
|
492
|
-
|
592
|
+
assert_parse inn, out
|
493
593
|
end
|
494
594
|
|
495
595
|
def test_regexp_options
|
@@ -501,7 +601,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
501
601
|
4),
|
502
602
|
s(:str, "a"))
|
503
603
|
out = '"a" =~ /abc#{x}def/m'
|
504
|
-
|
604
|
+
assert_parse inn, out
|
505
605
|
end
|
506
606
|
|
507
607
|
def test_resbody_short_with_rescue_args
|
@@ -509,7 +609,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
509
609
|
s(:call, nil, :blah),
|
510
610
|
s(:resbody, s(:array, s(:const, :A), s(:const, :B)), s(:array)))
|
511
611
|
out = "begin\n blah\nrescue A, B\n []\nend"
|
512
|
-
|
612
|
+
assert_parse inn, out
|
513
613
|
end
|
514
614
|
|
515
615
|
def test_call_binary_call_with_hash_arg
|
@@ -525,7 +625,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
525
625
|
|
526
626
|
out = "(args << { :key => 24 }) if 42"
|
527
627
|
|
528
|
-
|
628
|
+
assert_parse inn, out
|
529
629
|
end
|
530
630
|
|
531
631
|
def test_binary_operators
|
@@ -533,7 +633,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
533
633
|
Ruby2Ruby::BINARY.each do |op|
|
534
634
|
inn = s(:call, s(:lit, 1), op, s(:lit, 2))
|
535
635
|
out = "(1 #{op} 2)"
|
536
|
-
|
636
|
+
assert_parse inn, out
|
537
637
|
end
|
538
638
|
end
|
539
639
|
|
@@ -541,20 +641,20 @@ class TestRuby2Ruby < R2RTestCase
|
|
541
641
|
Ruby2Ruby::BINARY.each do |op|
|
542
642
|
inn = s(:call, s(:lvar, :x), op, s(:lit, 2), s(:lit, 3))
|
543
643
|
out = "x.#{op}(2, 3)"
|
544
|
-
|
644
|
+
assert_parse inn, out
|
545
645
|
end
|
546
646
|
end
|
547
647
|
|
548
648
|
def test_call_empty_hash
|
549
649
|
inn = s(:call, nil, :foo, s(:hash))
|
550
650
|
out = "foo({})"
|
551
|
-
|
651
|
+
assert_parse inn, out
|
552
652
|
end
|
553
653
|
|
554
654
|
def test_if_empty
|
555
655
|
inn = s(:if, s(:call, nil, :x), nil, nil)
|
556
656
|
out = "if x then\n # do nothing\nend"
|
557
|
-
|
657
|
+
assert_parse inn, out
|
558
658
|
end
|
559
659
|
|
560
660
|
def test_interpolation_and_escapes
|
@@ -565,60 +665,60 @@ class TestRuby2Ruby < R2RTestCase
|
|
565
665
|
s(:str, "m"),
|
566
666
|
s(:evstr, s(:call, nil, :message)),
|
567
667
|
s(:str, "\e[0m ")))
|
568
|
-
out = "log_entry = \"
|
668
|
+
out = "log_entry = \" \\e[#\{message_color}m#\{message}\\e[0m \""
|
569
669
|
|
570
|
-
|
670
|
+
assert_parse inn, out
|
571
671
|
end
|
572
672
|
|
573
673
|
def test_class_comments
|
574
674
|
inn = s(:class, :Z, nil)
|
575
675
|
inn.comments = "# x\n# y\n"
|
576
676
|
out = "# x\n# y\nclass Z\nend"
|
577
|
-
|
677
|
+
assert_parse inn, out
|
578
678
|
end
|
579
679
|
|
580
680
|
def test_module_comments
|
581
681
|
inn = s(:module, :Z)
|
582
682
|
inn.comments = "# x\n# y\n"
|
583
683
|
out = "# x\n# y\nmodule Z\nend"
|
584
|
-
|
684
|
+
assert_parse inn, out
|
585
685
|
end
|
586
686
|
|
587
687
|
def test_method_comments
|
588
688
|
inn = s(:defn, :z, s(:args), s(:nil))
|
589
689
|
inn.comments = "# x\n# y\n"
|
590
690
|
out = "# x\n# y\ndef z\n # do nothing\nend"
|
591
|
-
|
691
|
+
assert_parse inn, out
|
592
692
|
end
|
593
693
|
|
594
694
|
def test_basic_ensure
|
595
695
|
inn = s(:ensure, s(:lit, 1), s(:lit, 2))
|
596
696
|
out = "begin\n 1\nensure\n 2\nend"
|
597
|
-
|
697
|
+
assert_parse inn, out
|
598
698
|
end
|
599
699
|
|
600
700
|
def test_nested_ensure
|
601
701
|
inn = s(:ensure, s(:lit, 1), s(:ensure, s(:lit, 2), s(:lit, 3)))
|
602
702
|
out = "begin\n 1\nensure\n begin\n 2\n ensure\n 3\n end\nend"
|
603
|
-
|
703
|
+
assert_parse inn, out
|
604
704
|
end
|
605
705
|
|
606
706
|
def test_nested_rescue
|
607
707
|
inn = s(:ensure, s(:lit, 1), s(:rescue, s(:lit, 2), s(:resbody, s(:array), s(:lit, 3))))
|
608
708
|
out = "begin\n 1\nensure\n 2 rescue 3\nend"
|
609
|
-
|
709
|
+
assert_parse inn, out
|
610
710
|
end
|
611
711
|
|
612
712
|
def test_nested_rescue_exception
|
613
713
|
inn = s(:ensure, s(:lit, 1), s(:rescue, s(:lit, 2), s(:resbody, s(:array, s(:const, :Exception)), s(:lit, 3))))
|
614
714
|
out = "begin\n 1\nensure\n begin\n 2\n rescue Exception\n 3\n end\nend"
|
615
|
-
|
715
|
+
assert_parse inn, out
|
616
716
|
end
|
617
717
|
|
618
718
|
def test_nested_rescue_exception2
|
619
719
|
inn = s(:ensure, s(:rescue, s(:lit, 2), s(:resbody, s(:array, s(:const, :Exception)), s(:lit, 3))), s(:lit, 1))
|
620
720
|
out = "begin\n 2\nrescue Exception\n 3\nensure\n 1\nend"
|
621
|
-
|
721
|
+
assert_parse inn, out
|
622
722
|
end
|
623
723
|
|
624
724
|
def test_op_asgn
|
@@ -629,7 +729,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
629
729
|
:+)
|
630
730
|
|
631
731
|
out = "x.y += z(1)"
|
632
|
-
|
732
|
+
assert_parse inn, out
|
633
733
|
end
|
634
734
|
|
635
735
|
def test_rescue_block
|
@@ -639,7 +739,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
639
739
|
s(:call, nil, :beta),
|
640
740
|
s(:call, nil, :gamma)))
|
641
741
|
out = "begin\n alpha\nrescue\n beta\n gamma\nend"
|
642
|
-
|
742
|
+
assert_parse inn, out
|
643
743
|
end
|
644
744
|
|
645
745
|
def test_array_adds_parens_around_rescue
|
@@ -648,7 +748,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
648
748
|
s(:rescue, s(:call, nil, :b), s(:resbody, s(:array), s(:call, nil, :c))))
|
649
749
|
out = "[a, (b rescue c)]"
|
650
750
|
|
651
|
-
|
751
|
+
assert_parse inn, out
|
652
752
|
end
|
653
753
|
|
654
754
|
def test_call_arglist_rescue
|
@@ -659,7 +759,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
659
759
|
s(:call, nil, :a),
|
660
760
|
s(:resbody, s(:array), s(:call, nil, :b))))
|
661
761
|
out = "method((a rescue b))"
|
662
|
-
|
762
|
+
assert_parse inn, out
|
663
763
|
end
|
664
764
|
|
665
765
|
def test_unless_vs_if_not
|
@@ -667,14 +767,14 @@ class TestRuby2Ruby < R2RTestCase
|
|
667
767
|
rb2 = "a if (not b)"
|
668
768
|
rb3 = "a if ! b"
|
669
769
|
|
670
|
-
|
671
|
-
|
770
|
+
assert_parse Ruby18Parser.new.parse(rb1), rb1
|
771
|
+
assert_parse Ruby19Parser.new.parse(rb1), rb1
|
672
772
|
|
673
|
-
|
674
|
-
|
773
|
+
assert_parse Ruby18Parser.new.parse(rb2), rb1
|
774
|
+
assert_parse Ruby19Parser.new.parse(rb2), rb2
|
675
775
|
|
676
|
-
|
677
|
-
|
776
|
+
assert_parse Ruby18Parser.new.parse(rb3), rb1
|
777
|
+
assert_parse Ruby19Parser.new.parse(rb3), rb2
|
678
778
|
end
|
679
779
|
|
680
780
|
def assert_parse sexp, expected_ruby, expected_eval = nil
|
@@ -684,7 +784,6 @@ class TestRuby2Ruby < R2RTestCase
|
|
684
784
|
assert_equal expected_ruby, @processor.process(sexp), "sexp -> ruby"
|
685
785
|
assert_equal expected_eval, eval(expected_ruby) if expected_eval
|
686
786
|
end
|
687
|
-
alias util_compare assert_parse
|
688
787
|
|
689
788
|
def util_thingy(type)
|
690
789
|
s(type,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Davis
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
E4oJcnPkJAr0rw504JGtlZtONZQblwmRJOIdXzolaE3NRGUzGVOUSptZppAKiavY
|
31
31
|
fO6tdKQc/5RfA8oQEkg8hrxA5PQSz4TOFJGLpFvIapEk6tMruQ0bHgkhr9auXg==
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2016-
|
33
|
+
date: 2016-12-01 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: sexp_processor
|
@@ -38,14 +38,14 @@ dependencies:
|
|
38
38
|
requirements:
|
39
39
|
- - ~>
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '4.
|
41
|
+
version: '4.6'
|
42
42
|
type: :runtime
|
43
43
|
prerelease: false
|
44
44
|
version_requirements: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - ~>
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '4.
|
48
|
+
version: '4.6'
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: ruby_parser
|
51
51
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
Binary file
|