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

52 lines
1,017 B
Python
Raw Normal View History

2021-08-21 20:07:57 +00:00
"""
"""
2021-09-20 00:05:22 +00:00
from lilith.interpreter import (
Bindings,
eval,
Runtime,
)
from lilith.parser import Apply, Args, Symbol
2021-08-22 17:15:28 +00:00
from lilith.reader import Def, Module
2021-08-21 20:07:57 +00:00
import pytest
@pytest.fixture
def runtime():
return Runtime("test", None, {})
2021-08-21 22:58:59 +00:00
@pytest.mark.parametrize(
"expr, expected",
[
(1, 1),
([1, 2], [1, 2]),
({"foo": "bar"}, {"foo": "bar"}),
],
)
def test_eval(runtime, expr, expected):
2021-08-21 22:58:59 +00:00
assert (
eval(
runtime,
Module("__repl__", [], dict()),
2021-08-21 22:58:59 +00:00
Bindings("__root__", None),
expr,
)
== expected
)
2021-08-21 20:07:57 +00:00
def test_hello_world(capsys, runtime):
2021-08-21 22:58:59 +00:00
assert (
eval(
runtime,
2021-08-22 17:15:28 +00:00
Module("__repl__", [], {Symbol("print"): Def("__builtin__.print", print)}),
2021-08-21 22:58:59 +00:00
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"