Skip to content

Commit

Permalink
Added tests for evaluating dict literals
Browse files Browse the repository at this point in the history
  • Loading branch information
freyamade committed Feb 28, 2019
1 parent dc312fc commit c00e88c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions spec/evaluator_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 345,33 @@ describe Drizzle::Evaluator do
end
end
end

it "correctly handles dict literals" do
input = "let two: str = 'two'
return {
'one': 10 - 9,
two: 1 1,
'thr' 'ee': 6 / 2,
4: 4,
true: 5,
false: 6,
}"
evaluated = test_eval input
evaluated.object_type.should eq Drizzle::Object::ObjectType::DICT
dict = evaluated.as Drizzle::Object::Dictionary
expected : Hash(Drizzle::Object::HashKey, Int64) = {
(Drizzle::Object::String.new "one").hash => 1_i64,
(Drizzle::Object::String.new "two").hash => 2_i64,
(Drizzle::Object::String.new "three").hash => 3_i64,
(Drizzle::Object::Integer.new 4).hash => 4_i64,
(Drizzle::Object::Boolean.new true).hash => 5_i64,
(Drizzle::Object::Boolean.new false).hash => 6_i64,
}
dict.pairs.size.should eq expected.size
expected.each do |k, v|
value = dict.pairs[k]?
value.nil?.should be_false
test_integer value, v
end
end
end

0 comments on commit c00e88c

Please sign in to comment.