Handle negative indices

This commit is contained in:
Michael Miller 2018-10-14 19:33:38 -06:00
parent 155e9ec81a
commit cd86687dfb

View file

@ -31,8 +31,9 @@ module Spectator
getter example_count = 0
def [](index : Int) : Example
raise IndexError.new if index < 0
offset = index
offset += example_count if offset < 0
raise IndexError.new if offset < 0 || offset >= example_count
found = children.find do |child|
count = child.example_count
if offset < count