diff --git a/tests/test_cmd.py b/tests/test_cmd.py index 9cb69bc8..44cb928f 100644 --- a/tests/test_cmd.py +++ b/tests/test_cmd.py @@ -20,6 +20,21 @@ def test_c_args(): assert [out, err] == ["['-c', '1', '2', '3']\n", ""] +def test_reproducible_gensym(): + out, _err = once = cmd('python -m hissp -c "(print `$#G `($#G $#G))"') + assert "_Qz" in out + again = cmd('python -m hissp -c "(print `$#G `($#G $#G))"') + assert once == again + + +def test_unique_gensyms(): + once, _err = cmd('python -m hissp -c "(print `$#G `($#G $#G))"') + assert "_Qz" in once + again, _err = cmd('python -m hissp -c "0 (print `$#G `($#G $#G))"') + assert "_Qz" in again + assert once != again + + def test_ic_args(): out, err = cmd( 'lissp -i -c "(print sys..argv)(define answer 42)" 1 2 3', "answer\n" @@ -329,3 +344,37 @@ def test_interact_locals(): f"! {EXIT_MSG}", "> #> ", ) # fmt: skip + + +def test_subrepl(): + call_response( + "> #> ", "< hissp..subrepl#sys.\n", + "! >>> (lambda module=__import__('sys'):\n", + "! ... # hissp.._macro_.unless\n", + "! ... (lambda b, a: ()if b else a())(\n", + "! ... __name__==module.__name__,\n", + "! ... (lambda :\n", + "! ... (print(\n", + "! ... 'Entering',\n", + "! ... module.__name__),\n", + "! ... __import__('hissp').interact(\n", + "! ... __import__('builtins').vars(\n", + "! ... module)),\n", + "! ... print(\n", + "! ... 'back in',\n", + "! ... __name__)) [-1]\n", + "! ... ))\n", + "! ... )()\n", + "> Entering sys\n", + f"! {BANNER}", + "> #> ", "< (operator..is_ (vars) (vars sys.))\n", + "! >>> __import__('operator').is_(\n", + "! ... vars(),\n", + "! ... vars(\n", + "! ... __import__('sys')))\n", + "> True\n", + "> #> ", + f"! {EXIT_MSG}", + "> back in __main__\n", + "> #> ", + ) # fmt: skip diff --git a/tests/test_reader.py b/tests/test_reader.py index 95695697..8ebf6f59 100644 --- a/tests/test_reader.py +++ b/tests/test_reader.py @@ -169,6 +169,20 @@ def test_template(self): def test_is_string_code(self): self.assertFalse(reader.is_lissp_string("(1+1)")) + def test_gensym_equal(self): + self.assertEqual(*next(self.reader.reads(".#`($#G $#G)"))) + + def test_gensym_progression(self): + self.assertNotEqual(*self.reader.reads("`,$#G `,$#G")) + + def test_gensym_name(self): + code = "`,$#G" + main = next(self.reader.reads(code)) + name_reader = reader.Lissp(__name__, globals()) + name = next(name_reader.reads(code)) + self.assertNotEqual(main, name) + self.assertRegex(main + name, r"(?:_Qz[a-z0-7]+__G){2}") + EXPECTED = { # Numeric