Skip to content

Commit

Permalink
Change value for parsed Hash to array of hashes
Browse files Browse the repository at this point in the history
This fixes wrong parsing of Hashes like {a: 1, b: '2'} to
{hash: {Symbol => String}} instead of
{hash: [{Symbol => Fixnum}, {Symbol => String}]}
  • Loading branch information
paulgoetze committed Sep 22, 2015
1 parent b1e0fb1 commit 226e82b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 1 addition & 4 deletions lib/code_breaker/parsable/data_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,11 @@ def parse_int_node(node)
node.children[0].class
end

def parse_hash_node(node)
{ node.type => parse_children(node).inject(:merge).to_h }
end

def parse_pair_node(node)
{ parse(node.children[0]) => parse(node.children[1]) }
end

alias :parse_hash_node :parse_as_hash
alias :parse_array_node :parse_as_hash
end
end
Expand Down
8 changes: 7 additions & 1 deletion spec/code_breaker/parser/data_types_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@
context 'for a root node representing a Hash' do
it 'returns a Hash with key :hash and a Hash of key/type pairs' do
input = "{ euro: '€', 'dollar' => 1.1521 }"
output = { hash: { Symbol => String, String => Float } }
output = { hash: [{ Symbol => String }, { String => Float }] }
expect(input).to be_parsed_as output
end

it 'returns a Hash with key :hash and a Hash of key/type pairs' do
input = "{ euro: '€', dollar: 1.1521 }"
output = { hash: [{ Symbol => String }, { Symbol => Float }] }
expect(input).to be_parsed_as output
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/code_breaker/parser/language_elements_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
{
args: [
{ arg: :name},
{ optarg: [:options, { hash: { Symbol => Fixnum } }] }
{ optarg: [:options, { hash: [{ Symbol => Fixnum }] }] }
]
},
String
Expand Down

0 comments on commit 226e82b

Please sign in to comment.