use System.Collections class Test def makeList(values as vari int) as ArrayList is shared t = ArrayList() for value in values t.add(value) return t def main is shared t as ArrayList = .makeList(1, 2, 3, 4) assert t[0:4]==.makeList(1, 2, 3, 4) assert t[0:3]==.makeList(1, 2, 3) assert t[0:2]==.makeList(1, 2) assert t[0:1]==.makeList(1) assert t[0:0]==.makeList assert t[1:4]==.makeList(2, 3, 4) assert t[2:4]==.makeList(3, 4) assert t[3:4]==.makeList(4) assert t[4:4]==.makeList assert t[0:-1]==.makeList(1, 2, 3) assert t[0:-2]==.makeList(1, 2) assert t[0:-3]==.makeList(1) assert t[0:-4]==.makeList assert t[1:-1]==.makeList(2, 3) assert t[1:3:1]==.makeList(2, 3) assert t[:4]==.makeList(1, 2, 3, 4) assert t[0:]==.makeList(1, 2, 3, 4) assert t[:-1]==.makeList(1, 2, 3) assert t[:-2]==.makeList(1, 2) assert t[:-3]==.makeList(1) assert t[:-4]==.makeList assert t[0:]==.makeList(1, 2, 3, 4) assert t[1:]==.makeList(2, 3, 4) assert t[2:]==.makeList(3, 4) assert t[3:]==.makeList(4) assert t[4:]==.makeList # a step other than 1 is not current supported assert t[1:-1:1]==.makeList(2, 3) assert t[::1]==.makeList(1, 2, 3, 4) # out of range does not complain assert t[0:5]==.makeList(1,2,3,4) assert t[5:5]==.makeList assert t[0:-5]==.makeList print t[3:2] # using slice in string substitution # this is tricky for the implementation because colon is also used to format strings like '[s:N]' s as String = '[CobraCore.toTechString(t[1:3])]' assert s==r'ArrayList[2, 3]' or s==r'Range[2, 3]' or s==r'RangedArrayList[2, 3]', s # IList ilist as IList = t assert ilist[:-1]==.makeList(1, 2, 3)