-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_generic_language.py
51 lines (36 loc) · 1.32 KB
/
test_generic_language.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
from shrinkray.passes.genericlanguages import (
combine_expressions,
cut_comment_like_things,
reduce_integer_literals,
)
from tests.helpers import reduce_with
def test_can_reduce_an_integer_in_the_middle_of_a_string() -> None:
assert (
reduce_with([reduce_integer_literals], b"bobcats99999hello", lambda x: True)
== b"bobcats0hello"
)
def test_can_reduce_integers_to_boundaries() -> None:
assert (
reduce_with([reduce_integer_literals], b"100", lambda x: eval(x) >= 73) == b"73"
)
def test_can_combine_expressions() -> None:
assert reduce_with([combine_expressions], b"10 + 10", lambda x: True) == b"20"
def test_does_not_error_on_bad_expression() -> None:
assert reduce_with([combine_expressions], b"1 / 0", lambda x: True) == b"1 / 0"
def test_can_combine_expressions_with_no_expressions() -> None:
assert (
reduce_with([combine_expressions], b"hello world", lambda x: True)
== b"hello world"
)
LOTS_OF_COMMENTS = b"""
hello # this is a single line comment
/* this
is
a
multiline
comment */ world // some extraneous garbage
"""
def test_comment_removal():
x = reduce_with([cut_comment_like_things], LOTS_OF_COMMENTS, lambda x: True)
lines = [line.strip() for line in x.splitlines() if line.strip()]
assert lines == [b"hello", b"world"]