Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
dwt committed May 3, 2017
1 parent 370f93f commit 699ac7e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions tests/transformer/test_slice.py
Expand Up @@ -5,14 +5,17 @@ def test_slice():
low = 1
high = 4
stride = 3

from operator import getitem
restricted_globals = dict(_getitem_=getitem)
restricted_eval = lambda code: e_eval[1][1](code, restricted_globals)

assert e_eval('[1, 2, 3, 4, 5]') == [1, 2, 3, 4, 5]
assert e_eval('[1, 2, 3, 4, 5][:]') == [1, 2, 3, 4, 5]
assert e_eval('[1, 2, 3, 4, 5][' + low + ':]') == []
assert e_eval('[1, 2, 3, 4, 5][:' + high + ']') == []
assert e_eval('[1, 2, 3, 4, 5][' + low + ':' + high + ']') == []
assert e_eval('[1, 2, 3, 4, 5][::' + stride + ']') == []
assert e_eval('[1, 2, 3, 4, 5][' + low + '::' + stride + ']') == []
assert e_eval('[1, 2, 3, 4, 5][:' + high + ':' + stride + ']') == []
assert e_eval('[1, 2, 3, 4, 5][' + low + ':' + high + ':' + stride + ']') \
== []
assert restricted_eval('[1, 2, 3, 4, 5]') == [1, 2, 3, 4, 5]
assert restricted_eval('[1, 2, 3, 4, 5][:]') == [1, 2, 3, 4, 5]
assert restricted_eval('[1, 2, 3, 4, 5][%d:]' % low) == [2, 3, 4, 5]
assert restricted_eval('[1, 2, 3, 4, 5][:%d]' % high) == [1, 2, 3, 4]
assert restricted_eval('[1, 2, 3, 4, 5][%d:%d]' % (low, high)) == [2, 3, 4]
assert restricted_eval('[1, 2, 3, 4, 5][::%d]' % stride) == [1, 4]
assert restricted_eval('[1, 2, 3, 4, 5][%d::%d]' % (low, stride)) == [2, 5]
assert restricted_eval('[1, 2, 3, 4, 5][:%d:%d]' % (high, stride)) == [1, 4]
assert restricted_eval('[1, 2, 3, 4, 5][%d:%d:%d]' % (low, high, stride)) == [2]

0 comments on commit 699ac7e

Please sign in to comment.