Skip to content

Commit

Permalink
Added index error to index expression
Browse files Browse the repository at this point in the history
  • Loading branch information
freyamade committed Feb 28, 2019
1 parent ef54ff3 commit 81530d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions spec/evaluator_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 328,7 @@ describe Drizzle::Evaluator do
},
{
"[1, 2, 3][3]",
nil,
"IndexError: Index out of bounds (3)",
},
{
"[1, 2, 3][-1]",
Expand All @@ -337,10 337,11 @@ describe Drizzle::Evaluator do
}
tests.each do |test|
evaluated = test_eval test[0]
if test[1].nil?
test_null evaluated
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].not_nil!
test_integer evaluated, test[1].to_i64
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/drizzle/evaluator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 308,7 @@ module Drizzle
max_index = list.elements.size - 1

if index_val < min_index || index_val > max_index
return @@NULL
return new_error "IndexError: Index out of bounds (#{index_val})"
end
# handle negative indexing
if index_val < 0
Expand Down

0 comments on commit 81530d8

Please sign in to comment.