Skip to content

Commit 226e82b

Browse files
committed
Change value for parsed Hash to array of hashes
This fixes wrong parsing of Hashes like {a: 1, b: '2'} to {hash: {Symbol => String}} instead of {hash: [{Symbol => Fixnum}, {Symbol => String}]}
1 parent b1e0fb1 commit 226e82b

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

lib/code_breaker/parsable/data_types.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,11 @@ def parse_int_node(node)
4545
node.children[0].class
4646
end
4747

48-
def parse_hash_node(node)
49-
{ node.type => parse_children(node).inject(:merge).to_h }
50-
end
51-
5248
def parse_pair_node(node)
5349
{ parse(node.children[0]) => parse(node.children[1]) }
5450
end
5551

52+
alias :parse_hash_node :parse_as_hash
5653
alias :parse_array_node :parse_as_hash
5754
end
5855
end

spec/code_breaker/parser/data_types_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@
3232
context 'for a root node representing a Hash' do
3333
it 'returns a Hash with key :hash and a Hash of key/type pairs' do
3434
input = "{ euro: '€', 'dollar' => 1.1521 }"
35-
output = { hash: { Symbol => String, String => Float } }
35+
output = { hash: [{ Symbol => String }, { String => Float }] }
36+
expect(input).to be_parsed_as output
37+
end
38+
39+
it 'returns a Hash with key :hash and a Hash of key/type pairs' do
40+
input = "{ euro: '€', dollar: 1.1521 }"
41+
output = { hash: [{ Symbol => String }, { Symbol => Float }] }
3642
expect(input).to be_parsed_as output
3743
end
3844
end

spec/code_breaker/parser/language_elements_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
{
8181
args: [
8282
{ arg: :name},
83-
{ optarg: [:options, { hash: { Symbol => Fixnum } }] }
83+
{ optarg: [:options, { hash: [{ Symbol => Fixnum }] }] }
8484
]
8585
},
8686
String

0 commit comments

Comments
 (0)