diff --git a/python/src/eval.py b/python/src/eval.py index 9506da3..bb7d0d7 100644 --- a/python/src/eval.py +++ b/python/src/eval.py @@ -191,9 +191,10 @@ async def _eval_ast(ast): # short-curcuit the evaluation: if the condition text is literally # 'true' or 'false', then use it to dispatch into the :if branch. # That way we can use FFI functions with :if statements - prompt_result = "" if condition not in ["false", "true"] \ - else condition - MAX_RETRIES = 3 + prompt_result = ( + "" if condition not in ["false", "true"] else condition + ) + MAX_RETRIES = 3 # TODO: move to config retries = 0 prompt = IF_PROMPT + condition while prompt_result != "true" and prompt_result != "false": diff --git a/python/tests/test_eval.py b/python/tests/test_eval.py index c78dc98..3d2fa81 100644 --- a/python/tests/test_eval.py +++ b/python/tests/test_eval.py @@ -6,16 +6,36 @@ @pytest.mark.asyncio async def test_parameters(): prompt = "[:foo][:foo]" - await metaprompt(prompt, Config(parameters={"foo": "bar"})) == "barbar" + assert ( + await metaprompt(prompt, Config(parameters={"foo": "bar"})) == "barbar" + ) @pytest.mark.asyncio async def test_assign1(): prompt = "[:foo=bar][:foo][:foo]" - await metaprompt(prompt) == "barbar" + assert await metaprompt(prompt) == "barbar" @pytest.mark.asyncio async def test_assign2(): prompt = "[:foo=bar][:foo=[:foo][:foo]][:foo]" - await metaprompt(prompt) == "barbar" + assert await metaprompt(prompt) == "barbar" + + +@pytest.mark.asyncio +async def test_if_1(): + prompt = "[:if false :then foo :else bar]" + assert await metaprompt(prompt) == " bar" + + +@pytest.mark.asyncio +async def test_if_2(): + prompt = "[:if true :then foo :else bar]" + assert await metaprompt(prompt) == " foo " + + +@pytest.mark.asyncio +async def test_if_3(): + prompt = "[:v1=tr][:v2=ue][:if [:v1][:v2] :then foo :else bar]" + assert await metaprompt(prompt) == " foo "