ruby2ruby 2.1.3 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74c87f0ca74e11a422495c56f40bac470ab3379f
4
- data.tar.gz: 29e705948c7770c3722eab456247992042752495
3
+ metadata.gz: d5a340729045b8139f699cb585b8fcc302b8282f
4
+ data.tar.gz: cbfd1a1d811f65485c8175d33854ca21c80dad94
5
5
  SHA512:
6
- metadata.gz: 5e9540e531c0456eb52033bba31c56f5d9a5a1e317839e566e1385620205494a8f18499d40e762b65976c5feca0f3f08949d7092cfb6d06d2cc929f8015638e6
7
- data.tar.gz: ddb3bd03f2ed3495ec701530f791aca28099cbb07773355477cf1d8b5fa638e33b7c26dde8cf9d2fbde59ef1595e6c608d35c2d58f6b6861760908528fe805d0
6
+ metadata.gz: 2af547a9f8c9534c09e3b60f7c03e38d2342b9f63643a518bb30ee0126d4b691313f36e7a61ede70d4d385216493cdf840aa99ad032e792a87502fe669b94648
7
+ data.tar.gz: 04c75aab59b408c62a1a34eea38639cba985ca9d8286ca355def1e01cdb4b1ca07377dbfb4d4def1695e1198ef3e927a2cf2f90cdd47f568bf66b4a90800771e
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ === 2.1.4 / 2015-04-13
2
+
3
+ * 1 minor enhancement:
4
+
5
+ * Wrap fewer hash values in parentheses. (jaredbeck)
6
+
7
+ * 1 bug fix:
8
+
9
+ * Fixed handling of kwsplat args.
10
+
1
11
  === 2.1.3 / 2014-09-26
2
12
 
3
13
  * 1 bug fix:
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.1.3" # :nodoc:
34
+ VERSION = "2.1.4" # :nodoc:
35
35
 
36
36
  # cutoff for one-liners
37
37
  LINE_LENGTH = 78
@@ -60,6 +60,24 @@ class Ruby2Ruby < SexpProcessor
60
60
  :rescue,
61
61
  ]
62
62
 
63
+ ##
64
+ # Some sexp types are OK without parens when appearing as hash values.
65
+ # This list can include `:call`s because they're always printed with parens
66
+ # around their arguments. For example:
67
+ #
68
+ # { :foo => (bar("baz")) } # The outer parens are unnecessary
69
+ # { :foo => bar("baz") } # This is the normal code style
70
+
71
+ HASH_VAL_NO_PAREN = [
72
+ :call,
73
+ :false,
74
+ :lit,
75
+ :lvar,
76
+ :nil,
77
+ :str,
78
+ :true
79
+ ]
80
+
63
81
  def initialize # :nodoc:
64
82
  super
65
83
  @indent = " "
@@ -481,13 +499,21 @@ class Ruby2Ruby < SexpProcessor
481
499
  result = []
482
500
 
483
501
  until exp.empty?
484
- lhs = process(exp.shift)
485
- rhs = exp.shift
486
- t = rhs.first
487
- rhs = process rhs
488
- rhs = "(#{rhs})" unless [:lit, :str].include? t # TODO: verify better!
502
+ s = exp.shift
503
+ t = s.sexp_type
504
+ lhs = process s
505
+
506
+ case t
507
+ when :kwsplat then
508
+ result << lhs
509
+ else
510
+ rhs = exp.shift
511
+ t = rhs.first
512
+ rhs = process rhs
513
+ rhs = "(#{rhs})" unless HASH_VAL_NO_PAREN.include? t
489
514
 
490
- result << "#{lhs} => #{rhs}"
515
+ result << "#{lhs} => #{rhs}"
516
+ end
491
517
  end
492
518
 
493
519
  return result.empty? ? "{}" : "{ #{result.join(', ')} }"
@@ -80,6 +80,49 @@ class TestRuby2Ruby < R2RTestCase
80
80
  assert_equal exp, eval(out)
81
81
  end
82
82
 
83
+ def test_hash_parens_str
84
+ inn = s(:hash, s(:lit, :k), s(:str, "banana"))
85
+ out = '{ :k => "banana" }'
86
+ util_compare inn, out
87
+ end
88
+
89
+ def test_hash_parens_lit
90
+ inn = s(:hash, s(:lit, :k), s(:lit, 0.07))
91
+ out = "{ :k => 0.07 }"
92
+ util_compare inn, out
93
+ end
94
+
95
+ def test_hash_parens_bool
96
+ inn = s(:hash, s(:lit, :k), s(:true))
97
+ out = "{ :k => true }"
98
+ util_compare inn, out
99
+ end
100
+
101
+ def test_hash_parens_nil
102
+ inn = s(:hash, s(:lit, :k), s(:nil))
103
+ out = "{ :k => nil }"
104
+ util_compare inn, out
105
+ end
106
+
107
+ def test_hash_parens_lvar
108
+ inn = s(:hash, s(:lit, :k), s(:lvar, :x))
109
+ out = "{ :k => x }"
110
+ util_compare inn, out
111
+ end
112
+
113
+ def test_hash_parens_call
114
+ inn = s(:hash, s(:lit, :k), s(:call, nil, :foo, s(:lit, :bar)))
115
+ out = "{ :k => foo(:bar) }"
116
+ util_compare inn, out
117
+ end
118
+
119
+ def test_hash_parens_iter
120
+ iter = s(:iter, s(:call, nil, :foo), s(:args), s(:str, "bar"))
121
+ inn = s(:hash, s(:lit, :k), iter)
122
+ out = '{ :k => (foo { "bar" }) }'
123
+ util_compare inn, out
124
+ end
125
+
83
126
  def test_and_alias
84
127
  inn = s(:and, s(:true), s(:alias, s(:lit, :a), s(:lit, :b)))
85
128
  out = "true and (alias :a :b)"
@@ -168,8 +211,25 @@ class TestRuby2Ruby < R2RTestCase
168
211
  end
169
212
 
170
213
  def test_call_kwsplat
171
- inn = s(:call, nil, :test_splat, s(:kwsplat, s(:call, nil, :testing)))
214
+ inn = s(:call, nil, :test_splat, s(:hash, s(:kwsplat, s(:call, nil, :testing))))
172
215
  out = "test_splat(**testing)"
216
+
217
+ util_compare inn, out
218
+ end
219
+
220
+ def test_call_arg_assoc_kwsplat
221
+ inn = s(:call, nil, :f,
222
+ s(:lit, 1),
223
+ s(:hash, s(:lit, :kw), s(:lit, 2), s(:kwsplat, s(:lit, 3))))
224
+ out = "f(1, :kw => 2, **3)"
225
+
226
+ util_compare inn, out
227
+ end
228
+
229
+ def test_call_kwsplat_x
230
+ inn = s(:call, nil, :a, s(:hash, s(:kwsplat, s(:lit, 1))))
231
+ out = "a(**1)"
232
+
173
233
  util_compare inn, out
174
234
  end
175
235
 
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.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  xJcC6UN6NHMOVMyAXsr2HR0gRRx4ofN1LoP2KhXzSr8UMvQYlwPmE0N5GQv1b5AO
30
30
  VpzF30vNaJK6ZT7xlIsIlwmH
31
31
  -----END CERTIFICATE-----
32
- date: 2014-09-27 00:00:00.000000000 Z
32
+ date: 2015-04-13 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
@@ -65,14 +65,14 @@ dependencies:
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '5.4'
68
+ version: '5.6'
69
69
  type: :development
70
70
  prerelease: false
71
71
  version_requirements: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '5.4'
75
+ version: '5.6'
76
76
  - !ruby/object:Gem::Dependency
77
77
  name: rdoc
78
78
  requirement: !ruby/object:Gem::Requirement
@@ -146,10 +146,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  version: '0'
147
147
  requirements: []
148
148
  rubyforge_project:
149
- rubygems_version: 2.4.1
149
+ rubygems_version: 2.4.5
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: ruby2ruby provides a means of generating pure ruby code easily from RubyParser
153
153
  compatible Sexps
154
- test_files:
155
- - test/test_ruby2ruby.rb
154
+ test_files: []
metadata.gz.sig CHANGED
Binary file