Skip to content

Commit

Permalink
Adding tests for dictionary indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
freyamade committed Mar 4, 2019
1 parent 2d176c7 commit 2c1efb4
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions spec/evaluator_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 369,51 @@ describe Drizzle::Evaluator do
}
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
pair = dict.pairs[k]?
pair.nil?.should be_false
test_integer pair.not_nil!.value, v
end
end

it "correctly handles dictionary index expressions" do
tests = {
{
"{'foo': 5}['foo']",
5_i64,
},
{
"{'foo': 5}['bar']",
"nil",
},
{
"let key = 'foo'; {'foo': 5}[key]",
5_i64,
},
{
"{}['foo']",
"nil",
},
{
"{5: 5}[5]",
5_i64,
},
{
"{true: 5}[true]",
5_i64,
},
{
"{false: 5}[false]",
5_i64,
},
}
tests.each do |test|
evaluated = test_eval test[0]
if test[1].is_a?(String)
evaluated.object_type.should eq Drizzle::Object::ObjectType::ERROR
evaluated.as(Drizzle::Object::Error).message.should eq test[1]
else
test_integer evaluated, test[1].to_i64
end
end
end
end

0 comments on commit 2c1efb4

Please sign in to comment.