-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_op_vm.py
34 lines (28 loc) · 958 Bytes
/
test_op_vm.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
"""Tests of VM operators for stilted."""
import pytest
from error import StiltedError
from evaluate import evaluate
from test_helpers import compare_stacks
@pytest.mark.parametrize(
"text, stack",
[
("/foo 17 def save /foo 23 def foo exch restore foo", [23, 17]),
("/d 10 dict def d /foo 17 put save d /foo 23 put d begin foo exch restore foo", [23, 17]),
],
)
def test_evaluate(text, stack):
compare_stacks(evaluate(text).ostack, stack)
@pytest.mark.parametrize(
"text, error",
[
("restore", "stackunderflow"),
("123 restore", "typecheck"),
("save dup restore restore", "invalidrestore"),
("save save exch restore restore", "invalidrestore"),
("save 10 dict exch restore", "invalidrestore"),
("save 10 dict begin restore", "invalidrestore"),
],
)
def test_evaluate_error(text, error):
with pytest.raises(StiltedError, match=error):
evaluate(text)