kuroko/test/testSlicers.krk
K. Lange 6613db6cd4 Implement slice objects, slice stepping
This is an initial implementation of slice stepping and slice objects.
The __getslice__, __setslice__, and __delslice__ methods have been removed.
Slice expressions are now turned into slice objects with the OP_SLICE instruction.
Slice objects have a start, end, and step, all of which default to None.
Slice objects are passed to __getitem__, et al., as a normal parameter.

Support for slices in list.__getitem__, str.__getitem__, and bytes.__getitem__ has
been implemented.
2022-05-03 16:49:58 +09:00

35 lines
634 B
Python

def test(a):
print(a[::])
print(a[::-1])
print(a[::2])
print(a[::-2])
print(a[1:2])
print(a[1:7:3])
print(a[5::-3])
test([1,2,3,4,5,6,7,8,9,10,11,12,13])
test("こんにちは、みんなさま。クロコへようこそ。")
class SlicerTester:
def __getitem__(self, indexer):
print(indexer)
SlicerTester()[::]
SlicerTester()[::-1]
SlicerTester()[1:2:3]
SlicerTester()['a':'b':'c']
SlicerTester()[:]
SlicerTester()[:'end']
SlicerTester()['start':]
SlicerTester()[:'end':]
SlicerTester()[:'end':'step']
SlicerTester()['start'::'step']
SlicerTester()[1:2,3:4]
SlicerTester()[1:2:3,::4]