source/projects/lilith/test/python/test_interpreter.py

44 lines
902 B
Python
Raw Normal View History

2021-08-21 20:07:57 +00:00
"""
"""
from lilith.interpreter import Bindings, Runtime, eval
from lilith.reader import Module
2021-08-21 22:58:59 +00:00
from lilith.parser import Args, Apply, Symbol
2021-08-21 20:07:57 +00:00
import pytest
2021-08-21 22:58:59 +00:00
@pytest.mark.parametrize(
"expr, expected",
[
(1, 1),
([1, 2], [1, 2]),
({"foo": "bar"}, {"foo": "bar"}),
],
)
2021-08-21 20:07:57 +00:00
def test_eval(expr, expected):
2021-08-21 22:58:59 +00:00
assert (
eval(
Runtime("test", dict()),
Module("__repl__", dict()),
Bindings("__root__", None),
expr,
)
== expected
)
2021-08-21 20:07:57 +00:00
def test_hello_world(capsys):
2021-08-21 22:58:59 +00:00
assert (
eval(
Runtime("test", {}),
Module("__repl__", {Symbol("print"): print}),
Bindings("__root__", None),
Apply(Symbol("print"), Args(["hello, world"], {})),
)
is None
)
2021-08-21 20:07:57 +00:00
captured = capsys.readouterr()
assert captured.out == "hello, world\n"