spec/transformer_spec.rb in ripper-plus-1.0.0 vs spec/transformer_spec.rb in ripper-plus-1.0.1
- old
+ new
@@ -462,6 +462,104 @@
[[:sclass,
[:zcall, [:@ident, "x", [1, 19]]],
[:bodystmt, [[:void_stmt]], nil, nil, nil]]]]
input_tree.should transform_to output_tree
end
+
+ it 'observes the creation of local variables by rescue clauses' do
+ input_tree =
+ [:program,
+ [[:def,
+ [:@ident, "foo", [1, 4]],
+ [:paren, [:params, [[:@ident, "x", [1, 8]]], nil, nil, nil, nil]],
+ [:bodystmt,
+ [[:void_stmt],
+ [:assign,
+ [:var_field, [:@ident, "y", [1, 12]]],
+ [:binary,
+ [:@int, "1", [1, 16]],
+ :/,
+ [:var_ref, [:@ident, "x", [1, 20]]]]]],
+ [:rescue,
+ [[:var_ref, [:@const, "Exception", [1, 30]]]],
+ [:var_field, [:@ident, "err", [1, 43]]],
+ [[:command,
+ [:@ident, "p", [1, 48]],
+ [:args_add_block, [[:var_ref, [:@ident, "err", [1, 50]]]], false]]],
+ nil],
+ [:else,
+ [[:void_stmt],
+ [:command,
+ [:@ident, "p", [1, 61]],
+ [:args_add_block, [[:var_ref, [:@ident, "err", [1, 63]]]], false]]]],
+ [:ensure,
+ [[:void_stmt],
+ [:command,
+ [:@ident, "p", [1, 76]],
+ [:args_add_block, [[:var_ref, [:@ident, "err", [1, 78]]]], false]]]]]]]]
+ input_tree.should transform_to input_tree
+ end
+
+ it 'handles rescue clauses normally otherwise' do
+ input_tree =
+ [:program,
+ [[:def,
+ [:@ident, "foo", [1, 4]],
+ [:paren, [:params, [[:@ident, "x", [1, 8]]], nil, nil, nil, nil]],
+ [:bodystmt,
+ [[:void_stmt],
+ [:assign,
+ [:var_field, [:@ident, "y", [1, 12]]],
+ [:binary,
+ [:@int, "1", [1, 16]],
+ :/,
+ [:var_ref, [:@ident, "x", [1, 20]]]]]],
+ [:rescue,
+ [[:var_ref, [:@const, "Exception", [1, 30]]]],
+ nil,
+ [[:command,
+ [:@ident, "p", [1, 48]],
+ [:args_add_block, [[:var_ref, [:@ident, "err", [1, 50]]]], false]]],
+ nil],
+ [:else,
+ [[:void_stmt],
+ [:command,
+ [:@ident, "p", [1, 61]],
+ [:args_add_block, [[:var_ref, [:@ident, "err", [1, 63]]]], false]]]],
+ [:ensure,
+ [[:void_stmt],
+ [:command,
+ [:@ident, "p", [1, 76]],
+ [:args_add_block, [[:var_ref, [:@ident, "err", [1, 78]]]], false]]]]]]]]
+ output_tree =
+ [:program,
+ [[:def,
+ [:@ident, "foo", [1, 4]],
+ [:paren, [:params, [[:@ident, "x", [1, 8]]], nil, nil, nil, nil]],
+ [:bodystmt,
+ [[:void_stmt],
+ [:assign,
+ [:var_field, [:@ident, "y", [1, 12]]],
+ [:binary,
+ [:@int, "1", [1, 16]],
+ :/,
+ [:var_ref, [:@ident, "x", [1, 20]]]]]],
+ [:rescue,
+ [[:var_ref, [:@const, "Exception", [1, 30]]]],
+ nil,
+ [[:command,
+ [:@ident, "p", [1, 48]],
+ [:args_add_block, [[:zcall, [:@ident, "err", [1, 50]]]], false]]],
+ nil],
+ [:else,
+ [[:void_stmt],
+ [:command,
+ [:@ident, "p", [1, 61]],
+ [:args_add_block, [[:zcall, [:@ident, "err", [1, 63]]]], false]]]],
+ [:ensure,
+ [[:void_stmt],
+ [:command,
+ [:@ident, "p", [1, 76]],
+ [:args_add_block, [[:zcall, [:@ident, "err", [1, 78]]]], false]]]]]]]]
+ input_tree.should transform_to output_tree
+ end
end