2021-08-21 20:07:57 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2021-08-22 00:58:33 +00:00
|
|
|
from lilith.interpreter import Bindings, eval, Runtime
|
|
|
|
from lilith.parser import Apply, Args, Symbol
|
2021-08-21 20:07:57 +00:00
|
|
|
from lilith.reader import Module
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2021-08-22 00:58:33 +00:00
|
|
|
@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"}),
|
|
|
|
],
|
|
|
|
)
|
2021-08-22 00:58:33 +00:00
|
|
|
def test_eval(runtime, expr, expected):
|
2021-08-21 22:58:59 +00:00
|
|
|
assert (
|
|
|
|
eval(
|
2021-08-22 00:58:33 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2021-08-22 00:58:33 +00:00
|
|
|
def test_hello_world(capsys, runtime):
|
2021-08-21 22:58:59 +00:00
|
|
|
assert (
|
|
|
|
eval(
|
2021-08-22 00:58:33 +00:00
|
|
|
runtime,
|
|
|
|
Module("__repl__", [], {Symbol("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"
|