-
-
Notifications
You must be signed in to change notification settings - Fork 782
/
test_slice.py
55 lines (45 loc) · 1.03 KB
/
test_slice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
from pytest import raises
from vyper import compiler
from vyper.exceptions import TypeMismatchException
fail_list = [
"""
@public
def foo(inp: bytes[10]) -> bytes[2]:
return slice(inp, start=2, len=3)
""",
"""
@public
def foo(inp: int128) -> bytes[3]:
return slice(inp, start=2, len=3)
""",
"""
@public
def foo(inp: bytes[10]) -> bytes[3]:
return slice(inp, start=4.0, len=3)
"""
]
@pytest.mark.parametrize('bad_code', fail_list)
def test_slice_fail(bad_code):
with raises(TypeMismatchException):
compiler.compile(bad_code)
valid_list = [
"""
@public
def foo(inp: bytes[10]) -> bytes[3]:
return slice(inp, start=2, len=3)
""",
"""
@public
def foo(inp: bytes[10]) -> bytes[4]:
return slice(inp, start=2, len=3)
""",
"""
@public
def foo() -> bytes[10]:
return slice("badmintonzzz", start=1, len=10)
"""
]
@pytest.mark.parametrize('good_code', valid_list)
def test_slice_success(good_code):
assert compiler.compile(good_code) is not None