Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for gensym hash consistency
Browse files Browse the repository at this point in the history
Test gensyms for reproducible builds

Test equal gensyms in same template

Test successive gensyms unequal

Test gensyms include __name__ in hash

Test subrepl tag
gilch committed Oct 4, 2024
1 parent 7d76257 commit b49448d
Showing 2 changed files with 63 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/test_cmd.py
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b49448d

Please sign in to comment.