sexp2ruby 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +3 -0
- data/.travis.yml +1 -2
- data/README.md +9 -0
- data/lib/{sexp2ruby/core_extensions → core_extensions}/regexp.rb +0 -0
- data/lib/sexp2ruby/node/alias.rb +9 -0
- data/lib/sexp2ruby/node/and.rb +9 -0
- data/lib/sexp2ruby/node/arglist.rb +16 -0
- data/lib/sexp2ruby/node/args.rb +33 -0
- data/lib/sexp2ruby/node/array.rb +9 -0
- data/lib/sexp2ruby/node/attrasgn.rb +27 -0
- data/lib/sexp2ruby/node/back_ref.rb +9 -0
- data/lib/sexp2ruby/node/base.rb +36 -0
- data/lib/sexp2ruby/node/begin.rb +19 -0
- data/lib/sexp2ruby/node/block.rb +24 -0
- data/lib/sexp2ruby/node/block_pass.rb +10 -0
- data/lib/sexp2ruby/node/break.rb +14 -0
- data/lib/sexp2ruby/node/call.rb +70 -0
- data/lib/sexp2ruby/node/case.rb +27 -0
- data/lib/sexp2ruby/node/cdecl.rb +17 -0
- data/lib/sexp2ruby/node/class.rb +9 -0
- data/lib/sexp2ruby/node/colon2.rb +9 -0
- data/lib/sexp2ruby/node/colon3.rb +9 -0
- data/lib/sexp2ruby/node/const.rb +9 -0
- data/lib/sexp2ruby/node/cvar.rb +9 -0
- data/lib/sexp2ruby/node/cvasgn.rb +9 -0
- data/lib/sexp2ruby/node/cvdecl.rb +9 -0
- data/lib/sexp2ruby/node/defined.rb +9 -0
- data/lib/sexp2ruby/node/defn.rb +66 -0
- data/lib/sexp2ruby/node/defs.rb +17 -0
- data/lib/sexp2ruby/node/dot2.rb +9 -0
- data/lib/sexp2ruby/node/dot3.rb +9 -0
- data/lib/sexp2ruby/node/dregx.rb +19 -0
- data/lib/sexp2ruby/node/dregx_once.rb +9 -0
- data/lib/sexp2ruby/node/dstr.rb +9 -0
- data/lib/sexp2ruby/node/dsym.rb +9 -0
- data/lib/sexp2ruby/node/dxstr.rb +9 -0
- data/lib/sexp2ruby/node/ensure.rb +18 -0
- data/lib/sexp2ruby/node/evstr.rb +9 -0
- data/lib/sexp2ruby/node/false.rb +9 -0
- data/lib/sexp2ruby/node/flip2.rb +9 -0
- data/lib/sexp2ruby/node/flip3.rb +9 -0
- data/lib/sexp2ruby/node/for.rb +17 -0
- data/lib/sexp2ruby/node/gasgn.rb +9 -0
- data/lib/sexp2ruby/node/gvar.rb +9 -0
- data/lib/sexp2ruby/node/hash.rb +53 -0
- data/lib/sexp2ruby/node/iasgn.rb +14 -0
- data/lib/sexp2ruby/node/if.rb +41 -0
- data/lib/sexp2ruby/node/iter.rb +50 -0
- data/lib/sexp2ruby/node/ivar.rb +9 -0
- data/lib/sexp2ruby/node/kwsplat.rb +9 -0
- data/lib/sexp2ruby/node/lasgn.rb +11 -0
- data/lib/sexp2ruby/node/lit.rb +15 -0
- data/lib/sexp2ruby/node/lvar.rb +9 -0
- data/lib/sexp2ruby/node/masgn.rb +46 -0
- data/lib/sexp2ruby/node/match.rb +9 -0
- data/lib/sexp2ruby/node/match2.rb +11 -0
- data/lib/sexp2ruby/node/match3.rb +17 -0
- data/lib/sexp2ruby/node/module.rb +9 -0
- data/lib/sexp2ruby/node/next.rb +14 -0
- data/lib/sexp2ruby/node/nil.rb +9 -0
- data/lib/sexp2ruby/node/not.rb +9 -0
- data/lib/sexp2ruby/node/nth_ref.rb +9 -0
- data/lib/sexp2ruby/node/op_asgn1.rb +16 -0
- data/lib/sexp2ruby/node/op_asgn2.rb +17 -0
- data/lib/sexp2ruby/node/op_asgn_and.rb +13 -0
- data/lib/sexp2ruby/node/op_asgn_or.rb +13 -0
- data/lib/sexp2ruby/node/or.rb +9 -0
- data/lib/sexp2ruby/node/postexe.rb +9 -0
- data/lib/sexp2ruby/node/redo.rb +9 -0
- data/lib/sexp2ruby/node/resbody.rb +19 -0
- data/lib/sexp2ruby/node/rescue.rb +32 -0
- data/lib/sexp2ruby/node/retry.rb +9 -0
- data/lib/sexp2ruby/node/return.rb +13 -0
- data/lib/sexp2ruby/node/sclass.rb +9 -0
- data/lib/sexp2ruby/node/self.rb +9 -0
- data/lib/sexp2ruby/node/splat.rb +13 -0
- data/lib/sexp2ruby/node/str.rb +9 -0
- data/lib/sexp2ruby/node/super.rb +10 -0
- data/lib/sexp2ruby/node/svalue.rb +13 -0
- data/lib/sexp2ruby/node/to_ary.rb +9 -0
- data/lib/sexp2ruby/node/true.rb +9 -0
- data/lib/sexp2ruby/node/undef.rb +9 -0
- data/lib/sexp2ruby/node/until.rb +9 -0
- data/lib/sexp2ruby/node/valias.rb +9 -0
- data/lib/sexp2ruby/node/when.rb +24 -0
- data/lib/sexp2ruby/node/while.rb +9 -0
- data/lib/sexp2ruby/node/xstr.rb +9 -0
- data/lib/sexp2ruby/node/yield.rb +18 -0
- data/lib/sexp2ruby/node/zsuper.rb +9 -0
- data/lib/sexp2ruby/processor.rb +121 -912
- data/lib/sexp2ruby/version.rb +1 -1
- data/lib/sexp2ruby.rb +88 -1
- data/sexp2ruby.gemspec +1 -0
- data/spec/lib/processor_spec.rb +478 -1
- metadata +104 -8
- data/Rakefile +0 -92
- data/test/test_ruby2ruby.rb +0 -496
data/test/test_ruby2ruby.rb
DELETED
@@ -1,496 +0,0 @@
|
|
1
|
-
# WIP: Converting to rspec. This file is not in a usable state.
|
2
|
-
class TestRuby2Ruby
|
3
|
-
def setup
|
4
|
-
super
|
5
|
-
@check_sexp = ENV["CHECK_SEXPS"]
|
6
|
-
@processor = Ruby2Ruby.new
|
7
|
-
end
|
8
|
-
|
9
|
-
def do_not_check_sexp!
|
10
|
-
@check_sexp = false
|
11
|
-
end
|
12
|
-
|
13
|
-
def processor(opts)
|
14
|
-
Ruby2Ruby.new(opts)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_and_alias
|
18
|
-
inn = s(:and, s(:true), s(:alias, s(:lit, :a), s(:lit, :b)))
|
19
|
-
out = "true and (alias :a :b)"
|
20
|
-
util_compare inn, out
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_attr_reader_diff
|
24
|
-
inn = s(:defn, :same, s(:args), s(:ivar, :@diff))
|
25
|
-
out = "def same\n @diff\nend"
|
26
|
-
util_compare inn, out
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_attr_reader_same
|
30
|
-
do_not_check_sexp!
|
31
|
-
|
32
|
-
inn = s(:defn, :same, s(:args), s(:ivar, :@same))
|
33
|
-
out = "attr_reader :same"
|
34
|
-
util_compare inn, out
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_attr_reader_double
|
38
|
-
inn = s(:defn, :same, s(:args), s(:ivar, :@same), s(:ivar, :@diff))
|
39
|
-
out = "def same\n @same\n @diff\nend"
|
40
|
-
util_compare inn, out
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_attr_reader_same_name_diff_body
|
44
|
-
do_not_check_sexp!
|
45
|
-
|
46
|
-
inn = s(:defn, :same, s(:args), s(:not, s(:ivar, :@same)))
|
47
|
-
out = "def same\n (not @same)\nend"
|
48
|
-
util_compare inn, out
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_attr_writer_diff
|
52
|
-
inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@diff, s(:lvar, :o)))
|
53
|
-
out = "def same=(o)\n @diff = o\nend"
|
54
|
-
util_compare inn, out
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_attr_writer_double
|
58
|
-
inn = s(:defn, :same=, s(:args, :o),
|
59
|
-
s(:iasgn, :@same, s(:lvar, :o)), s(:iasgn, :@diff, s(:lvar, :o)))
|
60
|
-
out = "def same=(o)\n @same = o\n @diff = o\nend"
|
61
|
-
util_compare inn, out
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_attr_writer_same_name_diff_body
|
65
|
-
inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@same, s(:lit, 42)))
|
66
|
-
out = "def same=(o)\n @same = 42\nend"
|
67
|
-
util_compare inn, out
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_attr_writer_same
|
71
|
-
do_not_check_sexp!
|
72
|
-
|
73
|
-
inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@same , s(:lvar, :o)))
|
74
|
-
out = "attr_writer :same"
|
75
|
-
util_compare inn, out
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_dregx_slash
|
79
|
-
do_not_check_sexp!
|
80
|
-
|
81
|
-
inn = util_thingy(:dregx)
|
82
|
-
out = '/a"b#{(1 + 1)}c"d\/e/'
|
83
|
-
util_compare inn, out, /a"b2c"d\/e/
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_dstr_quote
|
87
|
-
inn = util_thingy(:dstr)
|
88
|
-
out = '"a\"b#{(1 + 1)}c\"d/e"'
|
89
|
-
util_compare inn, out, 'a"b2c"d/e'
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_dsym_quote
|
93
|
-
inn = util_thingy(:dsym)
|
94
|
-
out = ':"a\"b#{(1 + 1)}c\"d/e"'
|
95
|
-
util_compare inn, out, :'a"b2c"d/e'
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_lit_regexp_slash
|
99
|
-
do_not_check_sexp! # dunno why on this one
|
100
|
-
|
101
|
-
util_compare s(:lit, /blah\/blah/), '/blah\/blah/', /blah\/blah/
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_call_kwsplat
|
105
|
-
inn = s(:call, nil, :test_splat, s(:hash, s(:kwsplat, s(:call, nil, :testing))))
|
106
|
-
out = "test_splat(**testing)"
|
107
|
-
|
108
|
-
util_compare inn, out
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_call_arg_assoc_kwsplat
|
112
|
-
inn = s(:call, nil, :f,
|
113
|
-
s(:lit, 1),
|
114
|
-
s(:hash, s(:lit, :kw), s(:lit, 2), s(:kwsplat, s(:lit, 3))))
|
115
|
-
out = "f(1, :kw => 2, **3)"
|
116
|
-
|
117
|
-
util_compare inn, out
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_call_kwsplat_x
|
121
|
-
inn = s(:call, nil, :a, s(:hash, s(:kwsplat, s(:lit, 1))))
|
122
|
-
out = "a(**1)"
|
123
|
-
|
124
|
-
util_compare inn, out
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_defn_kwargs
|
128
|
-
inn = s(:defn, :initialize,
|
129
|
-
s(:args, :arg, s(:kwarg, :keyword, s(:nil)), :"**args"),
|
130
|
-
s(:nil))
|
131
|
-
out = "def initialize(arg, keyword: nil, **args)\n # do nothing\nend"
|
132
|
-
|
133
|
-
util_compare inn, out
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_defn_kwargs2
|
137
|
-
inn = s(:defn, :initialize,
|
138
|
-
s(:args, :arg,
|
139
|
-
s(:kwarg, :kw1, s(:nil)),
|
140
|
-
s(:kwarg, :kw2, s(:nil)),
|
141
|
-
:"**args"),
|
142
|
-
s(:nil))
|
143
|
-
out = "def initialize(arg, kw1: nil, kw2: nil, **args)\n # do nothing\nend"
|
144
|
-
|
145
|
-
util_compare inn, out
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_call_self_index
|
149
|
-
util_compare s(:call, nil, :[], s(:lit, 42)), "self[42]"
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_call_self_index_equals
|
153
|
-
util_compare(s(:attrasgn, s(:self), :[]=, s(:lit, 42), s(:lit, 24)),
|
154
|
-
"self[42] = 24")
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_call_self_index_equals_array
|
158
|
-
util_compare(s(:attrasgn, s(:self), :[]=, s(:lit, 1), s(:lit, 2), s(:lit, 3)),
|
159
|
-
"self[1, 2] = 3")
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_call_arglist_hash_first
|
163
|
-
inn = s(:call, nil, :method,
|
164
|
-
s(:hash, s(:lit, :a), s(:lit, 1)),
|
165
|
-
s(:call, nil, :b))
|
166
|
-
out = "method({ :a => 1 }, b)"
|
167
|
-
|
168
|
-
util_compare inn, out
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_call_arglist_hash_first_last
|
172
|
-
inn = s(:call, nil, :method,
|
173
|
-
s(:hash, s(:lit, :a), s(:lit, 1)),
|
174
|
-
s(:call, nil, :b),
|
175
|
-
s(:hash, s(:lit, :c), s(:lit, 1)))
|
176
|
-
out = "method({ :a => 1 }, b, :c => 1)"
|
177
|
-
|
178
|
-
util_compare inn, out
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_call_arglist_hash_last
|
182
|
-
inn = s(:call, nil, :method,
|
183
|
-
s(:call, nil, :b),
|
184
|
-
s(:hash, s(:lit, :a), s(:lit, 1)))
|
185
|
-
out = "method(b, :a => 1)"
|
186
|
-
|
187
|
-
util_compare inn, out
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_call_arglist_if
|
191
|
-
inn = s(:call,
|
192
|
-
s(:call, nil, :a),
|
193
|
-
:+,
|
194
|
-
s(:if,
|
195
|
-
s(:call, nil, :b),
|
196
|
-
s(:call, nil, :c),
|
197
|
-
s(:call, nil, :d)))
|
198
|
-
|
199
|
-
out = "(a + (b ? (c) : (d)))"
|
200
|
-
util_compare inn, out
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_defn_kwsplat
|
204
|
-
inn = s(:defn, :test, s(:args, :"**testing"), s(:nil))
|
205
|
-
out = "def test(**testing)\n # do nothing\nend"
|
206
|
-
assert_parse inn, out
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_defn_rescue_return
|
210
|
-
inn = s(:defn, :blah, s(:args),
|
211
|
-
s(:rescue,
|
212
|
-
s(:lasgn, :a, s(:lit, 1)),
|
213
|
-
s(:resbody, s(:array), s(:return, s(:str, "a")))))
|
214
|
-
out = "def blah\n a = 1\nrescue\n return \"a\"\nend"
|
215
|
-
|
216
|
-
assert_parse inn, out
|
217
|
-
end
|
218
|
-
|
219
|
-
def test_masgn_block_arg
|
220
|
-
inn = s(:iter,
|
221
|
-
s(:call,
|
222
|
-
s(:nil),
|
223
|
-
:x),
|
224
|
-
s(:args, s(:masgn, :a, :b)),
|
225
|
-
s(:dstr, "",
|
226
|
-
s(:evstr, s(:lvar, :a)),
|
227
|
-
s(:str, "="),
|
228
|
-
s(:evstr, s(:lvar, :b))))
|
229
|
-
out = 'nil.x { |(a, b)| "#{a}=#{b}" }'
|
230
|
-
|
231
|
-
util_compare inn, out
|
232
|
-
end
|
233
|
-
|
234
|
-
def test_masgn_wtf
|
235
|
-
inn = s(:block,
|
236
|
-
s(:masgn,
|
237
|
-
s(:array, s(:lasgn, :k), s(:lasgn, :v)),
|
238
|
-
s(:splat,
|
239
|
-
s(:call,
|
240
|
-
s(:call, nil, :line),
|
241
|
-
:split,
|
242
|
-
s(:lit, /\=/), s(:lit, 2)))),
|
243
|
-
s(:attrasgn,
|
244
|
-
s(:self),
|
245
|
-
:[]=,
|
246
|
-
s(:lvar, :k),
|
247
|
-
s(:call, s(:lvar, :v), :strip)))
|
248
|
-
|
249
|
-
out = "k, v = *line.split(/\\=/, 2)\nself[k] = v.strip\n"
|
250
|
-
|
251
|
-
util_compare inn, out
|
252
|
-
end
|
253
|
-
|
254
|
-
def test_masgn_splat_wtf
|
255
|
-
inn = s(:masgn,
|
256
|
-
s(:array, s(:lasgn, :k), s(:lasgn, :v)),
|
257
|
-
s(:splat,
|
258
|
-
s(:call,
|
259
|
-
s(:call, nil, :line),
|
260
|
-
:split,
|
261
|
-
s(:lit, /\=/), s(:lit, 2))))
|
262
|
-
out = 'k, v = *line.split(/\\=/, 2)'
|
263
|
-
util_compare inn, out
|
264
|
-
end
|
265
|
-
|
266
|
-
def test_match3_asgn
|
267
|
-
inn = s(:match3, s(:lit, //), s(:lasgn, :y, s(:call, nil, :x)))
|
268
|
-
out = "(y = x) =~ //"
|
269
|
-
# "y = x =~ //", which matches on x and assigns to y (not what sexp says).
|
270
|
-
util_compare inn, out
|
271
|
-
end
|
272
|
-
|
273
|
-
def test_splat_call
|
274
|
-
inn = s(:call, nil, :x,
|
275
|
-
s(:splat,
|
276
|
-
s(:call,
|
277
|
-
s(:call, nil, :line),
|
278
|
-
:split,
|
279
|
-
s(:lit, /\=/), s(:lit, 2))))
|
280
|
-
|
281
|
-
out = 'x(*line.split(/\=/, 2))'
|
282
|
-
util_compare inn, out
|
283
|
-
end
|
284
|
-
|
285
|
-
def test_resbody_block
|
286
|
-
inn = s(:rescue,
|
287
|
-
s(:call, nil, :x1),
|
288
|
-
s(:resbody,
|
289
|
-
s(:array),
|
290
|
-
s(:call, nil, :x2),
|
291
|
-
s(:call, nil, :x3)))
|
292
|
-
|
293
|
-
out = "begin\n x1\nrescue\n x2\n x3\nend"
|
294
|
-
util_compare inn, out
|
295
|
-
end
|
296
|
-
|
297
|
-
def test_resbody_short_with_begin_end
|
298
|
-
# "begin; blah; rescue; []; end"
|
299
|
-
inn = s(:rescue,
|
300
|
-
s(:call, nil, :blah),
|
301
|
-
s(:resbody, s(:array), s(:array)))
|
302
|
-
out = "blah rescue []"
|
303
|
-
util_compare inn, out
|
304
|
-
end
|
305
|
-
|
306
|
-
def test_resbody_short_with_begin_end_multiple
|
307
|
-
# "begin; blah; rescue; []; end"
|
308
|
-
inn = s(:rescue,
|
309
|
-
s(:call, nil, :blah),
|
310
|
-
s(:resbody, s(:array),
|
311
|
-
s(:call, nil, :log),
|
312
|
-
s(:call, nil, :raise)))
|
313
|
-
out = "begin\n blah\nrescue\n log\n raise\nend"
|
314
|
-
util_compare inn, out
|
315
|
-
end
|
316
|
-
|
317
|
-
def test_resbody_short_with_defn_multiple
|
318
|
-
inn = s(:defn,
|
319
|
-
:foo,
|
320
|
-
s(:args),
|
321
|
-
s(:rescue,
|
322
|
-
s(:lasgn, :a, s(:lit, 1)),
|
323
|
-
s(:resbody,
|
324
|
-
s(:array),
|
325
|
-
s(:call, nil, :log),
|
326
|
-
s(:call, nil, :raise))))
|
327
|
-
out = "def foo\n a = 1\nrescue\n log\n raise\nend"
|
328
|
-
util_compare inn, out
|
329
|
-
end
|
330
|
-
|
331
|
-
def test_regexp_options
|
332
|
-
inn = s(:match3,
|
333
|
-
s(:dregx,
|
334
|
-
"abc",
|
335
|
-
s(:evstr, s(:call, nil, :x)),
|
336
|
-
s(:str, "def"),
|
337
|
-
4),
|
338
|
-
s(:str, "a"))
|
339
|
-
out = '"a" =~ /abc#{x}def/m'
|
340
|
-
util_compare inn, out
|
341
|
-
end
|
342
|
-
|
343
|
-
def test_resbody_short_with_rescue_args
|
344
|
-
inn = s(:rescue,
|
345
|
-
s(:call, nil, :blah),
|
346
|
-
s(:resbody, s(:array, s(:const, :A), s(:const, :B)), s(:array)))
|
347
|
-
out = "begin\n blah\nrescue A, B\n []\nend"
|
348
|
-
util_compare inn, out
|
349
|
-
end
|
350
|
-
|
351
|
-
def test_call_binary_call_with_hash_arg
|
352
|
-
# if 42
|
353
|
-
# args << {:key => 24}
|
354
|
-
# end
|
355
|
-
|
356
|
-
inn = s(:if, s(:lit, 42),
|
357
|
-
s(:call, s(:call, nil, :args),
|
358
|
-
:<<,
|
359
|
-
s(:hash, s(:lit, :key), s(:lit, 24))),
|
360
|
-
nil)
|
361
|
-
|
362
|
-
out = "(args << { :key => 24 }) if 42"
|
363
|
-
|
364
|
-
util_compare inn, out
|
365
|
-
end
|
366
|
-
|
367
|
-
def test_binary_operators
|
368
|
-
# (1 > 2)
|
369
|
-
Ruby2Ruby::BINARY.each do |op|
|
370
|
-
inn = s(:call, s(:lit, 1), op, s(:lit, 2))
|
371
|
-
out = "(1 #{op} 2)"
|
372
|
-
util_compare inn, out
|
373
|
-
end
|
374
|
-
end
|
375
|
-
|
376
|
-
def test_call_empty_hash
|
377
|
-
inn = s(:call, nil, :foo, s(:hash))
|
378
|
-
out = "foo({})"
|
379
|
-
util_compare inn, out
|
380
|
-
end
|
381
|
-
|
382
|
-
def test_if_empty
|
383
|
-
inn = s(:if, s(:call, nil, :x), nil, nil)
|
384
|
-
out = "if x then\n # do nothing\nend"
|
385
|
-
util_compare inn, out
|
386
|
-
end
|
387
|
-
|
388
|
-
def test_interpolation_and_escapes
|
389
|
-
# log_entry = " \e[#{message_color}m#{message}\e[0m "
|
390
|
-
inn = s(:lasgn, :log_entry,
|
391
|
-
s(:dstr, " \e[",
|
392
|
-
s(:evstr, s(:call, nil, :message_color)),
|
393
|
-
s(:str, "m"),
|
394
|
-
s(:evstr, s(:call, nil, :message)),
|
395
|
-
s(:str, "\e[0m ")))
|
396
|
-
out = "log_entry = \" \e[#\{message_color}m#\{message}\e[0m \""
|
397
|
-
|
398
|
-
util_compare inn, out
|
399
|
-
end
|
400
|
-
|
401
|
-
def test_class_comments
|
402
|
-
inn = s(:class, :Z, nil)
|
403
|
-
inn.comments = "# x\n# y\n"
|
404
|
-
out = "# x\n# y\nclass Z\nend"
|
405
|
-
util_compare inn, out
|
406
|
-
end
|
407
|
-
|
408
|
-
def test_module_comments
|
409
|
-
inn = s(:module, :Z)
|
410
|
-
inn.comments = "# x\n# y\n"
|
411
|
-
out = "# x\n# y\nmodule Z\nend"
|
412
|
-
util_compare inn, out
|
413
|
-
end
|
414
|
-
|
415
|
-
def test_method_comments
|
416
|
-
inn = s(:defn, :z, s(:args), s(:nil))
|
417
|
-
inn.comments = "# x\n# y\n"
|
418
|
-
out = "# x\n# y\ndef z\n # do nothing\nend"
|
419
|
-
util_compare inn, out
|
420
|
-
end
|
421
|
-
|
422
|
-
def test_basic_ensure
|
423
|
-
inn = s(:ensure, s(:lit, 1), s(:lit, 2))
|
424
|
-
out = "begin\n 1\nensure\n 2\nend"
|
425
|
-
util_compare inn, out
|
426
|
-
end
|
427
|
-
|
428
|
-
def test_nested_ensure
|
429
|
-
inn = s(:ensure, s(:lit, 1), s(:ensure, s(:lit, 2), s(:lit, 3)))
|
430
|
-
out = "begin\n 1\nensure\n begin\n 2\n ensure\n 3\n end\nend"
|
431
|
-
util_compare inn, out
|
432
|
-
end
|
433
|
-
|
434
|
-
def test_nested_rescue
|
435
|
-
inn = s(:ensure, s(:lit, 1), s(:rescue, s(:lit, 2), s(:resbody, s(:array), s(:lit, 3))))
|
436
|
-
out = "begin\n 1\nensure\n 2 rescue 3\nend"
|
437
|
-
util_compare inn, out
|
438
|
-
end
|
439
|
-
|
440
|
-
def test_nested_rescue_exception
|
441
|
-
inn = s(:ensure, s(:lit, 1), s(:rescue, s(:lit, 2), s(:resbody, s(:array, s(:const, :Exception)), s(:lit, 3))))
|
442
|
-
out = "begin\n 1\nensure\n begin\n 2\n rescue Exception\n 3\n end\nend"
|
443
|
-
util_compare inn, out
|
444
|
-
end
|
445
|
-
|
446
|
-
def test_nested_rescue_exception2
|
447
|
-
inn = s(:ensure, s(:rescue, s(:lit, 2), s(:resbody, s(:array, s(:const, :Exception)), s(:lit, 3))), s(:lit, 1))
|
448
|
-
out = "begin\n 2\nrescue Exception\n 3\nensure\n 1\nend"
|
449
|
-
util_compare inn, out
|
450
|
-
end
|
451
|
-
|
452
|
-
def test_rescue_block
|
453
|
-
inn = s(:rescue,
|
454
|
-
s(:call, nil, :alpha),
|
455
|
-
s(:resbody, s(:array),
|
456
|
-
s(:call, nil, :beta),
|
457
|
-
s(:call, nil, :gamma)))
|
458
|
-
out = "begin\n alpha\nrescue\n beta\n gamma\nend"
|
459
|
-
util_compare inn, out
|
460
|
-
end
|
461
|
-
|
462
|
-
def test_array_adds_parens_around_rescue
|
463
|
-
inn = s(:array,
|
464
|
-
s(:call, nil, :a),
|
465
|
-
s(:rescue, s(:call, nil, :b), s(:resbody, s(:array), s(:call, nil, :c))))
|
466
|
-
out = "[a, (b rescue c)]"
|
467
|
-
|
468
|
-
util_compare inn, out
|
469
|
-
end
|
470
|
-
|
471
|
-
def test_call_arglist_rescue
|
472
|
-
inn = s(:call,
|
473
|
-
nil,
|
474
|
-
:method,
|
475
|
-
s(:rescue,
|
476
|
-
s(:call, nil, :a),
|
477
|
-
s(:resbody, s(:array), s(:call, nil, :b))))
|
478
|
-
out = "method((a rescue b))"
|
479
|
-
util_compare inn, out
|
480
|
-
end
|
481
|
-
|
482
|
-
def test_unless_vs_if_not
|
483
|
-
rb1 = "a unless b"
|
484
|
-
rb2 = "a if (not b)"
|
485
|
-
rb3 = "a if ! b"
|
486
|
-
|
487
|
-
util_compare Ruby18Parser.new.parse(rb1), rb1
|
488
|
-
util_compare Ruby19Parser.new.parse(rb1), rb1
|
489
|
-
|
490
|
-
util_compare Ruby18Parser.new.parse(rb2), rb1
|
491
|
-
util_compare Ruby19Parser.new.parse(rb2), rb2
|
492
|
-
|
493
|
-
util_compare Ruby18Parser.new.parse(rb3), rb1
|
494
|
-
util_compare Ruby19Parser.new.parse(rb3), rb2
|
495
|
-
end
|
496
|
-
end
|