Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/ruby2ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,13 @@ def process_hash(exp) # :nodoc:
result = pairs.each_slice(2).map { |k, v|
if k.sexp_type == :kwsplat then
"%s" % process(k)
elsif v.nil?
# Shorthand hash syntax
unless k.sexp_type == :lit and k.value.is_a? Symbol
raise "Expected symbol for hash key, but got #{k.inspect}"
end

"#{k.value}:"
else
t = v.sexp_type

Expand Down
8 changes: 8 additions & 0 deletions test/test_ruby2ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ def test_hash_parens_iter
assert_parse inn, out
end

def test_hash_shorthand_invalid_key_type
inn = s(:hash, s(:str, 'k'), nil)
out = '{ k: }'
assert_raises do
assert_parse inn, out
end
end

def test_and_alias
inn = s(:and, s(:true), s(:alias, s(:lit, :a), s(:lit, :b)))
out = "true and (alias :a :b)"
Expand Down