[DRE-commits] [ruby-ruby2ruby] 01/06: Imported Upstream version 2.3.0

Cédric Boutillier boutil at moszumanska.debian.org
Thu Jul 21 04:22:17 UTC 2016


This is an automated email from the git hooks/post-receive script.

boutil pushed a commit to branch master
in repository ruby-ruby2ruby.

commit d3defba094e9ceed0df75a4c757caf55154e1cce
Author: Cédric Boutillier <boutil at debian.org>
Date:   Thu Jul 21 05:28:09 2016 +0200

    Imported Upstream version 2.3.0
---
 .autotest              |   2 +-
 .gemtest               |   0
 History.txt            |  57 ++++++++++++++++++
 README.txt             |   7 ++-
 Rakefile               |   6 +-
 checksums.yaml.gz      | Bin 270 -> 0 bytes
 checksums.yaml.gz.sig  | Bin 256 -> 256 bytes
 data.tar.gz.sig        | Bin 256 -> 256 bytes
 lib/ruby2ruby.rb       | 100 +++++++++++++++++++++++++------
 metadata.gz.sig        | Bin 256 -> 256 bytes
 metadata.yml           | 155 -------------------------------------------------
 ruby2ruby.gemspec      |  49 ++++++++++++++++
 test/test_ruby2ruby.rb | 143 ++++++++++++++++++++++++++++++++++++++++++++-
 13 files changed, 338 insertions(+), 181 deletions(-)

diff --git a/.autotest b/.autotest
index d17fecb..4ba6cdf 100644
--- a/.autotest
+++ b/.autotest
@@ -3,7 +3,7 @@
 require 'autotest/restart'
 
 Autotest.add_hook :initialize do |at|
-  at.order = :random
+  at.libs << ':../../minitest/dev/lib'
   at.testlib = "minitest/autorun"
 
   at.extra_files << "../../sexp_processor/dev/lib/pt_testcase.rb"
diff --git a/.gemtest b/.gemtest
deleted file mode 100644
index e69de29..0000000
diff --git a/History.txt b/History.txt
index ee5b50b..e9b0570 100644
--- a/History.txt
+++ b/History.txt
@@ -1,3 +1,60 @@
+=== 2.3.0 / 2016-02-18
+
+* 3 minor enhancements:
+
+  * Added support for safe navigation/lonely operator. (presidentbeef)
+  * Expanded tests for 2.3 support
+  * Support safe attrasgn. (presidentbeef).
+
+=== 2.2.0 / 2015-05-27
+
+* 1 minor enhancement:
+
+  * Normalized block arg goalposts (always there unless arg slot == 0).
+
+=== 2.1.4 / 2015-04-13
+
+* 1 minor enhancement:
+
+  * Wrap fewer hash values in parentheses. (jaredbeck)
+
+* 1 bug fix:
+
+  * Fixed handling of kwsplat args.
+
+=== 2.1.3 / 2014-09-26
+
+* 1 bug fix:
+
+  * Fixed handling of kwargs. (joenas)
+
+=== 2.1.2 / 2014-08-28
+
+* 1 bug fix:
+
+  * Fixed readme to point out that deep_clone may be needed. (heathd)
+
+=== 2.1.1 / 2014-06-09
+
+* 1 bug fix:
+
+  * Moved Regexp::CODES out of guard on ::ENC_NONE. (presidentbeef)
+
+=== 2.1.0 / 2014-04-23
+
+* 4 minor enhancements:
+
+  * Don't indent defn body extra if it has a top-level rescue.
+  * Don't indent defn body until fully processed.
+  * Don't use simple rescue form if resbody is a return (statement keyword). (eyberg)
+  * Remove superfluous begin/end for top-level defn rescue.
+
+=== 2.0.8 / 2014-03-24
+
+* 1 bug fix:
+
+  * 2.0/2.1: Fixed support for **kwsplat. (troessner)
+
 === 2.0.7 / 2013-12-13
 
 * 4 minor enhancements:
diff --git a/README.txt b/README.txt
index 2293870..5cd62c4 100644
--- a/README.txt
+++ b/README.txt
@@ -1,7 +1,7 @@
 = ruby2ruby
 
 home :: https://github.com/seattlerb/ruby2ruby
-rdoc :: http://seattlerb.rubyforge.org/ruby2ruby
+rdoc :: http://docs.seattlerb.org/ruby2ruby
 
 == DESCRIPTION:
 
@@ -27,8 +27,9 @@ processors in ruby easier than ever!
     
     pp sexp
 
-    p ruby2ruby.process(sexp)
-    
+    p ruby2ruby.process(sexp.deep_clone) # Note: #process destroys its input, so
+                                         # #deep_clone if you need to preserve it
+
     ## outputs:
 
     s(:block,
diff --git a/Rakefile b/Rakefile
index ea8fee8..6bf4931 100644
--- a/Rakefile
+++ b/Rakefile
@@ -13,7 +13,7 @@ Hoe.plugin :isolate
 Hoe.spec 'ruby2ruby' do
   developer 'Ryan Davis', 'ryand-ruby at zenspider.com'
 
-  self.rubyforge_name = 'seattlerb'
+  license "MIT"
 
   dependency "sexp_processor", "~> 4.0"
   dependency "ruby_parser",    "~> 3.1"
@@ -85,4 +85,8 @@ task :debug => :isolate do
   puts process(ruby, file)
 end
 
+task :bugs do
+  sh "for f in bug*.rb ; do #{Gem.ruby} -S rake debug F=$f && rm $f ; done"
+end
+
 # vim: syntax=ruby
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
deleted file mode 100644
index d988c7f..0000000
Binary files a/checksums.yaml.gz and /dev/null differ
diff --git a/checksums.yaml.gz.sig b/checksums.yaml.gz.sig
index ffca7e7..120b32c 100644
Binary files a/checksums.yaml.gz.sig and b/checksums.yaml.gz.sig differ
diff --git a/data.tar.gz.sig b/data.tar.gz.sig
index 551b34f..1590498 100644
Binary files a/data.tar.gz.sig and b/data.tar.gz.sig differ
diff --git a/lib/ruby2ruby.rb b/lib/ruby2ruby.rb
index 44bc1cb..9007b4b 100755
--- a/lib/ruby2ruby.rb
+++ b/lib/ruby2ruby.rb
@@ -11,7 +11,9 @@ class Regexp
     ENC_EUC  = /x/e.options
     ENC_SJIS = /x/s.options
     ENC_UTF8 = /x/u.options
+  end
 
+  unless defined? CODES then
     CODES = {
       EXTENDED   => 'x',
       IGNORECASE => 'i',
@@ -29,7 +31,7 @@ end
 # Generate ruby code from a sexp.
 
 class Ruby2Ruby < SexpProcessor
-  VERSION = "2.0.7" # :nodoc:
+  VERSION = "2.3.0" # :nodoc:
 
   # cutoff for one-liners
   LINE_LENGTH = 78
@@ -58,6 +60,24 @@ class Ruby2Ruby < SexpProcessor
                   :rescue,
                  ]
 
+  ##
+  # Some sexp types are OK without parens when appearing as hash values.
+  # This list can include `:call`s because they're always printed with parens
+  # around their arguments. For example:
+  #
+  #     { :foo => (bar("baz")) } # The outer parens are unnecessary
+  #     { :foo => bar("baz") }   # This is the normal code style
+
+  HASH_VAL_NO_PAREN = [
+    :call,
+    :false,
+    :lit,
+    :lvar,
+    :nil,
+    :str,
+    :true
+  ]
+
   def initialize # :nodoc:
     super
     @indent = "  "
@@ -106,6 +126,9 @@ class Ruby2Ruby < SexpProcessor
           args << process(arg)
         when :masgn then
           args << process(arg)
+        when :kwarg then
+          _, k, v = arg
+          args << "#{k}: #{process v}"
         else
           raise "unknown arg type #{arg.first.inspect}"
         end
@@ -195,7 +218,7 @@ class Ruby2Ruby < SexpProcessor
     end
   end
 
-  def process_call(exp) # :nodoc:
+  def process_call(exp, safe_call = false) # :nodoc:
     receiver_node_type = exp.first.nil? ? nil : exp.first.first
     receiver = process exp.shift
     receiver = "(#{receiver})" if ASSIGN_NODES.include? receiver_node_type
@@ -231,7 +254,11 @@ class Ruby2Ruby < SexpProcessor
 
     case name
     when *BINARY then
-      "(#{receiver} #{name} #{args.join(', ')})"
+      if safe_call
+        "#{receiver}&.#{name}(#{args.join(', ')})"
+      else
+        "(#{receiver} #{name} #{args.join(', ')})"
+      end
     when :[] then
       receiver ||= "self"
       "#{receiver}[#{args.join(', ')}]"
@@ -248,7 +275,8 @@ class Ruby2Ruby < SexpProcessor
     else
       args     = nil                    if args.empty?
       args     = "(#{args.join(', ')})" if args
-      receiver = "#{receiver}."         if receiver
+      receiver = "#{receiver}."         if receiver and not safe_call
+      receiver = "#{receiver}&."        if receiver and safe_call
 
       "#{receiver}#{name}#{args}"
     end
@@ -256,6 +284,10 @@ class Ruby2Ruby < SexpProcessor
     @calls.pop
   end
 
+  def process_safe_call(exp) # :nodoc:
+    process_call(exp, :safe)
+  end
+
   def process_case(exp) # :nodoc:
     result = []
     expr = process exp.shift
@@ -370,12 +402,14 @@ class Ruby2Ruby < SexpProcessor
     # REFACTOR: use process_block but get it happier wrt parenthesize
     body = []
     until exp.empty? do
-      body << indent(process(exp.shift))
+      body << process(exp.shift)
     end
 
-    body << indent("# do nothing") if body.empty?
-
+    body << "# do nothing" if body.empty?
     body = body.join("\n")
+    body = body.lines.to_a[1..-2].join("\n") if
+      body =~ /^\Abegin/ && body =~ /^end\z/
+    body = indent(body) unless body =~ /(^|\n)rescue/
 
     return "#{comm}def #{name}#{args}\n#{body}\nend".gsub(/\n\s*\n+/, "\n")
   end
@@ -474,13 +508,21 @@ class Ruby2Ruby < SexpProcessor
     result = []
 
     until exp.empty?
-      lhs = process(exp.shift)
-      rhs = exp.shift
-      t = rhs.first
-      rhs = process rhs
-      rhs = "(#{rhs})" unless [:lit, :str].include? t # TODO: verify better!
+      s = exp.shift
+      t = s.sexp_type
+      lhs = process s
+
+      case t
+      when :kwsplat then
+        result << lhs
+      else
+        rhs = exp.shift
+        t = rhs.first
+        rhs = process rhs
+        rhs = "(#{rhs})" unless HASH_VAL_NO_PAREN.include? t
 
-      result << "#{lhs} => #{rhs}"
+        result << "#{lhs} => #{rhs}"
+      end
     end
 
     return result.empty? ? "{}" : "{ #{result.join(', ')} }"
@@ -538,11 +580,9 @@ class Ruby2Ruby < SexpProcessor
 
     args = case args
            when 0 then
-             " ||"
+             ""
            else
-             a = process(args)[1..-2]
-             a = " |#{a}|" unless a.empty?
-             a
+             " |#{process(args)[1..-2]}|"
            end
 
     b, e = if iter == "END" then
@@ -582,6 +622,10 @@ class Ruby2Ruby < SexpProcessor
     exp.shift.to_s
   end
 
+  def process_kwsplat(exp)
+    "**#{process exp.shift}"
+  end
+
   def process_lasgn(exp) # :nodoc:
     s = "#{exp.shift}"
     s += " = #{process exp.shift}" unless exp.empty?
@@ -756,7 +800,9 @@ class Ruby2Ruby < SexpProcessor
     els  = process(exp.pop)   unless exp.last.first  == :resbody
 
     body ||= "# do nothing"
-    simple = exp.size == 1 && !exp.resbody.block && exp.resbody.size <= 3
+    simple = exp.size == 1 && exp.resbody.size <= 3 &&
+      !exp.resbody.block &&
+      !exp.resbody.return
 
     resbodies = []
     until exp.empty? do
@@ -790,6 +836,24 @@ class Ruby2Ruby < SexpProcessor
     end
   end
 
+  def process_safe_attrasgn(exp) # :nodoc:
+    receiver = process exp.shift
+    name = exp.shift
+    rhs  = exp.pop
+    args = exp.pop # should be nil
+    exp.clear
+
+    raise "dunno what to do: #{args.inspect}" if args
+
+    name = name.to_s.sub(/=$/, '')
+
+    if rhs && rhs != s(:arglist) then
+      "#{receiver}&.#{name} = #{process(rhs)}"
+    else
+      raise "dunno what to do: #{rhs.inspect}"
+    end
+  end
+
   def process_sclass(exp) # :nodoc:
     "class << #{process(exp.shift)}\n#{indent(process_block(exp))}\nend"
   end
diff --git a/metadata.gz.sig b/metadata.gz.sig
index a170ead..83efb31 100644
Binary files a/metadata.gz.sig and b/metadata.gz.sig differ
diff --git a/metadata.yml b/metadata.yml
deleted file mode 100644
index 2b938ea..0000000
--- a/metadata.yml
+++ /dev/null
@@ -1,155 +0,0 @@
---- !ruby/object:Gem::Specification
-name: ruby2ruby
-version: !ruby/object:Gem::Version
-  version: 2.0.7
-platform: ruby
-authors:
-- Ryan Davis
-autorequire: 
-bindir: bin
-cert_chain:
-- |
-  -----BEGIN CERTIFICATE-----
-  MIIDPjCCAiagAwIBAgIBATANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
-  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
-  GRYDY29tMB4XDTEzMDkxNjIzMDQxMloXDTE0MDkxNjIzMDQxMlowRTETMBEGA1UE
-  AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
-  JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
-  b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
-  taCPaLmfYIaFcHHCSY4hYDJijRQkLxPeB3xbOfzfLoBDbjvx5JxgJxUjmGa7xhcT
-  oOvjtt5P8+GSK9zLzxQP0gVLS/D0FmoE44XuDr3iQkVS2ujU5zZL84mMNqNB1znh
-  GiadM9GHRaDiaxuX0cIUBj19T01mVE2iymf9I6bEsiayK/n6QujtyCbTWsAS9Rqt
-  qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
-  gBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
-  HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBBQUAA4IB
-  AQCFZ7JTzoy1gcG4d8A6dmOJy7ygtO5MFpRIz8HuKCF5566nOvpy7aHhDDzFmQuu
-  FX3zDU6ghx5cQIueDhf2SGOncyBmmJRRYawm3wI0o1MeN6LZJ/3cRaOTjSFy6+S6
-  zqDmHBp8fVA2TGJtO0BLNkbGVrBJjh0UPmSoGzWlRhEVnYC33TpDAbNA+u39UrQI
-  ynwhNN7YbnmSR7+JU2cUjBFv2iPBO+TGuWC+9L2zn3NHjuc6tnmSYipA9y8Hv+As
-  Y4evBVezr3SjXz08vPqRO5YRdO3zfeMT8gBjRqZjWJGMZ2lD4XNfrs7eky74CyZw
-  xx3n58i0lQkBE1EpKE0lFu/y
-  -----END CERTIFICATE-----
-date: 2013-12-14 00:00:00.000000000 Z
-dependencies:
-- !ruby/object:Gem::Dependency
-  name: sexp_processor
-  requirement: !ruby/object:Gem::Requirement
-    requirements:
-    - - ~>
-      - !ruby/object:Gem::Version
-        version: '4.0'
-  type: :runtime
-  prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
-    requirements:
-    - - ~>
-      - !ruby/object:Gem::Version
-        version: '4.0'
-- !ruby/object:Gem::Dependency
-  name: ruby_parser
-  requirement: !ruby/object:Gem::Requirement
-    requirements:
-    - - ~>
-      - !ruby/object:Gem::Version
-        version: '3.1'
-  type: :runtime
-  prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
-    requirements:
-    - - ~>
-      - !ruby/object:Gem::Version
-        version: '3.1'
-- !ruby/object:Gem::Dependency
-  name: minitest
-  requirement: !ruby/object:Gem::Requirement
-    requirements:
-    - - ~>
-      - !ruby/object:Gem::Version
-        version: '5.2'
-  type: :development
-  prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
-    requirements:
-    - - ~>
-      - !ruby/object:Gem::Version
-        version: '5.2'
-- !ruby/object:Gem::Dependency
-  name: rdoc
-  requirement: !ruby/object:Gem::Requirement
-    requirements:
-    - - ~>
-      - !ruby/object:Gem::Version
-        version: '4.0'
-  type: :development
-  prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
-    requirements:
-    - - ~>
-      - !ruby/object:Gem::Version
-        version: '4.0'
-- !ruby/object:Gem::Dependency
-  name: hoe
-  requirement: !ruby/object:Gem::Requirement
-    requirements:
-    - - ~>
-      - !ruby/object:Gem::Version
-        version: '3.7'
-  type: :development
-  prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
-    requirements:
-    - - ~>
-      - !ruby/object:Gem::Version
-        version: '3.7'
-description: |-
-  ruby2ruby provides a means of generating pure ruby code easily from
-  RubyParser compatible Sexps. This makes making dynamic language
-  processors in ruby easier than ever!
-email:
-- ryand-ruby at zenspider.com
-executables:
-- r2r_show
-extensions: []
-extra_rdoc_files:
-- History.txt
-- Manifest.txt
-- README.txt
-files:
-- .autotest
-- History.txt
-- Manifest.txt
-- README.txt
-- Rakefile
-- bin/r2r_show
-- lib/ruby2ruby.rb
-- test/test_ruby2ruby.rb
-- .gemtest
-homepage: https://github.com/seattlerb/ruby2ruby
-licenses:
-- MIT
-metadata: {}
-post_install_message: 
-rdoc_options:
-- --main
-- README.txt
-require_paths:
-- lib
-required_ruby_version: !ruby/object:Gem::Requirement
-  requirements:
-  - - '>='
-    - !ruby/object:Gem::Version
-      version: '0'
-required_rubygems_version: !ruby/object:Gem::Requirement
-  requirements:
-  - - '>='
-    - !ruby/object:Gem::Version
-      version: '0'
-requirements: []
-rubyforge_project: seattlerb
-rubygems_version: 2.1.10
-signing_key: 
-specification_version: 4
-summary: ruby2ruby provides a means of generating pure ruby code easily from RubyParser
-  compatible Sexps
-test_files:
-- test/test_ruby2ruby.rb
diff --git a/ruby2ruby.gemspec b/ruby2ruby.gemspec
new file mode 100644
index 0000000..b551c01
--- /dev/null
+++ b/ruby2ruby.gemspec
@@ -0,0 +1,49 @@
+#########################################################
+# This file has been automatically generated by gem2tgz #
+#########################################################
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+  s.name = "ruby2ruby"
+  s.version = "2.3.0"
+
+  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+  s.authors = ["Ryan Davis"]
+  s.cert_chain = ["-----BEGIN CERTIFICATE-----\nMIIDPjCCAiagAwIBAgIBAzANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu\nZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB\nGRYDY29tMB4XDTE1MDkxOTIwNTEyMloXDTE2MDkxODIwNTEyMlowRTETMBEGA1UE\nAwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS\nJomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda\nb9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx\ntaCPaLmfYIaFcHHCSY4hYDJijRQkLxPeB3xbOfzfLoBDbjvx [...]
+  s.date = "2016-02-19"
+  s.description = "ruby2ruby provides a means of generating pure ruby code easily from\nRubyParser compatible Sexps. This makes making dynamic language\nprocessors in ruby easier than ever!"
+  s.email = ["ryand-ruby at zenspider.com"]
+  s.executables = ["r2r_show"]
+  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
+  s.files = [".autotest", "History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/r2r_show", "lib/ruby2ruby.rb", "test/test_ruby2ruby.rb"]
+  s.homepage = "https://github.com/seattlerb/ruby2ruby"
+  s.licenses = ["MIT"]
+  s.rdoc_options = ["--main", "README.txt"]
+  s.require_paths = ["lib"]
+  s.rubygems_version = "1.8.23"
+  s.summary = "ruby2ruby provides a means of generating pure ruby code easily from RubyParser compatible Sexps"
+
+  if s.respond_to? :specification_version then
+    s.specification_version = 4
+
+    if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+      s.add_development_dependency(%q<hoe>, ["~> 3.14"])
+      s.add_development_dependency(%q<minitest>, ["~> 5.8"])
+      s.add_development_dependency(%q<rdoc>, ["~> 4.0"])
+      s.add_runtime_dependency(%q<ruby_parser>, ["~> 3.1"])
+      s.add_runtime_dependency(%q<sexp_processor>, ["~> 4.0"])
+    else
+      s.add_dependency(%q<hoe>, ["~> 3.14"])
+      s.add_dependency(%q<minitest>, ["~> 5.8"])
+      s.add_dependency(%q<rdoc>, ["~> 4.0"])
+      s.add_dependency(%q<ruby_parser>, ["~> 3.1"])
+      s.add_dependency(%q<sexp_processor>, ["~> 4.0"])
+    end
+  else
+    s.add_dependency(%q<hoe>, ["~> 3.14"])
+    s.add_dependency(%q<minitest>, ["~> 5.8"])
+    s.add_dependency(%q<rdoc>, ["~> 4.0"])
+    s.add_dependency(%q<ruby_parser>, ["~> 3.1"])
+    s.add_dependency(%q<sexp_processor>, ["~> 4.0"])
+  end
+end
diff --git a/test/test_ruby2ruby.rb b/test/test_ruby2ruby.rb
index 714ee24..6a0a0d7 100644
--- a/test/test_ruby2ruby.rb
+++ b/test/test_ruby2ruby.rb
@@ -19,7 +19,7 @@ class R2RTestCase < ParseTreeTestCase
   def self.generate_test klass, node, data, input_name, output_name
     output_name = data.has_key?('Ruby2Ruby') ? 'Ruby2Ruby' : 'Ruby'
 
-    return if node.to_s =~ /19$/
+    return if node.to_s =~ /(str_question|not|bang).*_(19|20|21|22|23)$/
 
     klass.class_eval <<-EOM
       def test_#{node}
@@ -80,6 +80,49 @@ class TestRuby2Ruby < R2RTestCase
     assert_equal exp, eval(out)
   end
 
+  def test_hash_parens_str
+    inn = s(:hash, s(:lit, :k), s(:str, "banana"))
+    out = '{ :k => "banana" }'
+    util_compare inn, out
+  end
+
+  def test_hash_parens_lit
+    inn = s(:hash, s(:lit, :k), s(:lit, 0.07))
+    out = "{ :k => 0.07 }"
+    util_compare inn, out
+  end
+
+  def test_hash_parens_bool
+    inn = s(:hash, s(:lit, :k), s(:true))
+    out = "{ :k => true }"
+    util_compare inn, out
+  end
+
+  def test_hash_parens_nil
+    inn = s(:hash, s(:lit, :k), s(:nil))
+    out = "{ :k => nil }"
+    util_compare inn, out
+  end
+
+  def test_hash_parens_lvar
+    inn = s(:hash, s(:lit, :k), s(:lvar, :x))
+    out = "{ :k => x }"
+    util_compare inn, out
+  end
+
+  def test_hash_parens_call
+    inn = s(:hash, s(:lit, :k), s(:call, nil, :foo, s(:lit, :bar)))
+    out = "{ :k => foo(:bar) }"
+    util_compare inn, out
+  end
+
+  def test_hash_parens_iter
+    iter = s(:iter, s(:call, nil, :foo), 0, s(:str, "bar"))
+    inn = s(:hash, s(:lit, :k), iter)
+    out = '{ :k => (foo { "bar" }) }'
+    util_compare inn, out
+  end
+
   def test_and_alias
     inn = s(:and, s(:true), s(:alias, s(:lit, :a), s(:lit, :b)))
     out = "true and (alias :a :b)"
@@ -167,6 +210,50 @@ class TestRuby2Ruby < R2RTestCase
     util_compare s(:lit, /blah\/blah/), '/blah\/blah/', /blah\/blah/
   end
 
+  def test_call_kwsplat
+    inn = s(:call, nil, :test_splat, s(:hash, s(:kwsplat, s(:call, nil, :testing))))
+    out = "test_splat(**testing)"
+
+    util_compare inn, out
+  end
+
+  def test_call_arg_assoc_kwsplat
+    inn = s(:call, nil, :f,
+           s(:lit, 1),
+           s(:hash, s(:lit, :kw), s(:lit, 2), s(:kwsplat, s(:lit, 3))))
+    out = "f(1, :kw => 2, **3)"
+
+    util_compare inn, out
+  end
+
+  def test_call_kwsplat_x
+    inn = s(:call, nil, :a, s(:hash, s(:kwsplat, s(:lit, 1))))
+    out = "a(**1)"
+
+    util_compare inn, out
+  end
+
+  def test_defn_kwargs
+    inn = s(:defn, :initialize,
+            s(:args, :arg, s(:kwarg, :keyword, s(:nil)), :"**args"),
+            s(:nil))
+    out = "def initialize(arg, keyword: nil, **args)\n  # do nothing\nend"
+
+    util_compare inn, out
+  end
+
+  def test_defn_kwargs2
+    inn = s(:defn, :initialize,
+            s(:args, :arg,
+              s(:kwarg, :kw1, s(:nil)),
+              s(:kwarg, :kw2, s(:nil)),
+              :"**args"),
+            s(:nil))
+    out = "def initialize(arg, kw1: nil, kw2: nil, **args)\n  # do nothing\nend"
+
+    util_compare inn, out
+  end
+
   def test_call_self_index
     util_compare s(:call, nil, :[], s(:lit, 42)), "self[42]"
   end
@@ -222,6 +309,22 @@ class TestRuby2Ruby < R2RTestCase
     util_compare inn, out
   end
 
+  def test_defn_kwsplat
+    inn = s(:defn, :test, s(:args, :"**testing"), s(:nil))
+    out = "def test(**testing)\n  # do nothing\nend"
+    assert_parse inn, out
+  end
+
+  def test_defn_rescue_return
+    inn = s(:defn, :blah, s(:args),
+           s(:rescue,
+             s(:lasgn, :a, s(:lit, 1)),
+             s(:resbody, s(:array), s(:return, s(:str, "a")))))
+    out = "def blah\n  a = 1\nrescue\n  return \"a\"\nend"
+
+    assert_parse inn, out
+  end
+
   def test_masgn_block_arg
     inn = s(:iter,
             s(:call,
@@ -276,6 +379,39 @@ class TestRuby2Ruby < R2RTestCase
     util_compare inn, out
   end
 
+  def test_safe_attrasgn
+    inn = s(:safe_attrasgn,
+            s(:call, nil, :x),
+            :y=,
+            s(:lit, 1))
+
+    out = "x&.y = 1"
+
+    util_compare inn, out
+  end
+
+  def test_safe_call
+    inn = s(:safe_call,
+            s(:safe_call,
+              s(:call, nil, :x),
+              :y),
+              :z,
+              s(:lit, 1))
+
+    out ="x&.y&.z(1)"
+    util_compare inn, out
+  end
+
+  def test_safe_call_binary
+    inn = s(:safe_call,
+            s(:call, nil, :x),
+            :>,
+            s(:lit, 1))
+
+    out = "x&.>(1)"
+    util_compare inn, out
+  end
+
   def test_splat_call
     inn = s(:call, nil, :x,
             s(:splat,
@@ -330,7 +466,7 @@ class TestRuby2Ruby < R2RTestCase
                 s(:array),
                 s(:call, nil, :log),
                 s(:call, nil, :raise))))
-    out = "def foo\n  begin\n    a = 1\n  rescue\n    log\n    raise\n  end\nend"
+    out = "def foo\n  a = 1\nrescue\n  log\n  raise\nend"
     util_compare inn, out
   end
 
@@ -500,13 +636,14 @@ class TestRuby2Ruby < R2RTestCase
     util_compare Ruby19Parser.new.parse(rb3), rb2
   end
 
-  def util_compare sexp, expected_ruby, expected_eval = nil
+  def assert_parse sexp, expected_ruby, expected_eval = nil
     assert_equal sexp, RubyParser.new.process(expected_ruby), "ruby -> sexp" if
       @check_sexp
 
     assert_equal expected_ruby, @processor.process(sexp), "sexp -> ruby"
     assert_equal expected_eval, eval(expected_ruby) if expected_eval
   end
+  alias util_compare assert_parse
 
   def util_thingy(type)
     s(type,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-ruby2ruby.git



More information about the Pkg-ruby-extras-commits mailing list