Commit e56bc6a1 authored by Stefan Behnel's avatar Stefan Behnel

Tighten the new 2-item slicing tests by asserting a specific tree structure.

parent c6177dfd
# mode: run # mode: run
# tag: list, tuple, slice, slicing # tag: list, tuple, slice, slicing
cimport cython
@cython.test_fail_if_path_exists("//CondExprNode")
def slice_list(list l, int start, int stop): def slice_list(list l, int start, int stop):
""" """
>>> slice_list([1,2,3,4], 1, 3) >>> slice_list([1,2,3,4], 1, 3)
...@@ -22,6 +26,7 @@ def slice_list(list l, int start, int stop): ...@@ -22,6 +26,7 @@ def slice_list(list l, int start, int stop):
""" """
return l[start:stop] return l[start:stop]
@cython.test_fail_if_path_exists("//CondExprNode")
def slice_list_start(list l, int start): def slice_list_start(list l, int start):
""" """
>>> slice_list_start([1,2,3,4], 1) >>> slice_list_start([1,2,3,4], 1)
...@@ -44,6 +49,7 @@ def slice_list_start(list l, int start): ...@@ -44,6 +49,7 @@ def slice_list_start(list l, int start):
return l[start:] return l[start:]
@cython.test_fail_if_path_exists("//CondExprNode")
def slice_list_stop(list l, int stop): def slice_list_stop(list l, int stop):
""" """
>>> slice_list_stop([1,2,3,4], 3) >>> slice_list_stop([1,2,3,4], 3)
...@@ -68,6 +74,7 @@ def slice_list_stop(list l, int stop): ...@@ -68,6 +74,7 @@ def slice_list_stop(list l, int stop):
return l[:stop] return l[:stop]
@cython.test_fail_if_path_exists("//CondExprNode")
def slice_list_copy(list l): def slice_list_copy(list l):
""" """
>>> slice_list_copy([]) >>> slice_list_copy([])
...@@ -78,6 +85,7 @@ def slice_list_copy(list l): ...@@ -78,6 +85,7 @@ def slice_list_copy(list l):
return l[:] return l[:]
@cython.test_fail_if_path_exists("//CondExprNode")
def slice_tuple_copy(tuple l): def slice_tuple_copy(tuple l):
""" """
>>> slice_tuple_copy(()) >>> slice_tuple_copy(())
...@@ -88,6 +96,7 @@ def slice_tuple_copy(tuple l): ...@@ -88,6 +96,7 @@ def slice_tuple_copy(tuple l):
return l[:] return l[:]
@cython.test_fail_if_path_exists("//CondExprNode")
def slice_tuple(tuple t, int start, int stop): def slice_tuple(tuple t, int start, int stop):
""" """
>>> slice_tuple((1,2,3,4), 1, 3) >>> slice_tuple((1,2,3,4), 1, 3)
...@@ -110,6 +119,7 @@ def slice_tuple(tuple t, int start, int stop): ...@@ -110,6 +119,7 @@ def slice_tuple(tuple t, int start, int stop):
return t[start:stop] return t[start:stop]
@cython.test_fail_if_path_exists("//CondExprNode")
def slice_tuple_start(tuple t, int start): def slice_tuple_start(tuple t, int start):
""" """
>>> slice_tuple_start((1,2,3,4), 1) >>> slice_tuple_start((1,2,3,4), 1)
...@@ -129,6 +139,8 @@ def slice_tuple_start(tuple t, int start): ...@@ -129,6 +139,8 @@ def slice_tuple_start(tuple t, int start):
""" """
return t[start:] return t[start:]
@cython.test_fail_if_path_exists("//CondExprNode")
def slice_tuple_stop(tuple t, int stop): def slice_tuple_stop(tuple t, int stop):
""" """
>>> slice_tuple_stop((1,2,3,4), 3) >>> slice_tuple_stop((1,2,3,4), 3)
...@@ -147,6 +159,7 @@ def slice_tuple_stop(tuple t, int stop): ...@@ -147,6 +159,7 @@ def slice_tuple_stop(tuple t, int stop):
return t[:stop] return t[:stop]
@cython.test_fail_if_path_exists("//CondExprNode")
def slice_list_assign_list(list l): def slice_list_assign_list(list l):
""" """
>>> l = [1,2,3,4] >>> l = [1,2,3,4]
...@@ -158,6 +171,7 @@ def slice_list_assign_list(list l): ...@@ -158,6 +171,7 @@ def slice_list_assign_list(list l):
return l return l
@cython.test_fail_if_path_exists("//CondExprNode")
def slice_list_assign_tuple(list l): def slice_list_assign_tuple(list l):
""" """
>>> l = [1,2,3,4] >>> l = [1,2,3,4]
...@@ -169,6 +183,7 @@ def slice_list_assign_tuple(list l): ...@@ -169,6 +183,7 @@ def slice_list_assign_tuple(list l):
return l return l
@cython.test_fail_if_path_exists("//CondExprNode")
def slice_list_assign(list l, value): def slice_list_assign(list l, value):
""" """
>>> l = [1,2,3,4] >>> l = [1,2,3,4]
...@@ -204,6 +219,7 @@ def slice_charp_repeat(py_string_arg): ...@@ -204,6 +219,7 @@ def slice_charp_repeat(py_string_arg):
s = slice_val s = slice_val
return s[1:3].decode(u'ASCII') return s[1:3].decode(u'ASCII')
# Readers will find the common boilerplate in the tests below: # Readers will find the common boilerplate in the tests below:
# >>> l = [1,2,3,4,5] # >>> l = [1,2,3,4,5]
# >>> t = tuple(l) # >>> t = tuple(l)
...@@ -227,6 +243,8 @@ ctypedef fused slicable: ...@@ -227,6 +243,8 @@ ctypedef fused slicable:
bytes bytes
unicode unicode
@cython.test_assert_path_exists("//SliceIndexNode//CondExprNode")
def slice_fused_type_start(slicable seq, start): def slice_fused_type_start(slicable seq, start):
""" """
>>> l = [1,2,3,4,5] >>> l = [1,2,3,4,5]
...@@ -269,6 +287,8 @@ def slice_fused_type_start(slicable seq, start): ...@@ -269,6 +287,8 @@ def slice_fused_type_start(slicable seq, start):
obj = seq[start:] obj = seq[start:]
return obj return obj
@cython.test_assert_path_exists("//SliceIndexNode//CondExprNode")
def slice_fused_type_stop(slicable seq, stop): def slice_fused_type_stop(slicable seq, stop):
""" """
>>> l = [1,2,3,4,5] >>> l = [1,2,3,4,5]
...@@ -311,6 +331,8 @@ def slice_fused_type_stop(slicable seq, stop): ...@@ -311,6 +331,8 @@ def slice_fused_type_stop(slicable seq, stop):
obj = seq[:stop] obj = seq[:stop]
return obj return obj
@cython.test_assert_path_exists("//SliceIndexNode//CondExprNode")
def slice_fused_type_start_and_stop(slicable seq, start, stop): def slice_fused_type_start_and_stop(slicable seq, start, stop):
""" """
>>> l = [1,2,3,4,5] >>> l = [1,2,3,4,5]
...@@ -354,6 +376,7 @@ def slice_fused_type_start_and_stop(slicable seq, start, stop): ...@@ -354,6 +376,7 @@ def slice_fused_type_start_and_stop(slicable seq, start, stop):
obj = seq[start:stop] obj = seq[start:stop]
return obj return obj
def slice_fused_type_step(slicable seq, step): def slice_fused_type_step(slicable seq, step):
""" """
>>> l = [1,2,3,4,5] >>> l = [1,2,3,4,5]
...@@ -405,6 +428,7 @@ def slice_fused_type_step(slicable seq, step): ...@@ -405,6 +428,7 @@ def slice_fused_type_step(slicable seq, step):
obj = seq[::step] obj = seq[::step]
return obj return obj
def slice_fused_type_start_and_step(slicable seq, start, step): def slice_fused_type_start_and_step(slicable seq, start, step):
""" """
>>> l = [1,2,3,4,5] >>> l = [1,2,3,4,5]
...@@ -468,6 +492,7 @@ def slice_fused_type_start_and_step(slicable seq, start, step): ...@@ -468,6 +492,7 @@ def slice_fused_type_start_and_step(slicable seq, start, step):
obj = seq[start::step] obj = seq[start::step]
return obj return obj
def slice_fused_type_stop_and_step(slicable seq, stop, step): def slice_fused_type_stop_and_step(slicable seq, stop, step):
""" """
>>> l = [1,2,3,4,5] >>> l = [1,2,3,4,5]
...@@ -521,6 +546,7 @@ def slice_fused_type_stop_and_step(slicable seq, stop, step): ...@@ -521,6 +546,7 @@ def slice_fused_type_stop_and_step(slicable seq, stop, step):
obj = seq[:stop:step] obj = seq[:stop:step]
return obj return obj
def slice_fused_type_all(slicable seq, start, stop, step): def slice_fused_type_all(slicable seq, start, stop, step):
""" """
>>> l = [1,2,3,4,5] >>> l = [1,2,3,4,5]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment