Skip to content

Commit

Permalink
no recursion errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kavigupta committed Sep 10, 2024
1 parent 0a511a8 commit 45553b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
19 changes: 16 additions & 3 deletions tests/parser_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def test_parse_basic(self):
[Pair("+", Pair("2", Pair(Pair("3", nil), nil)))],
)
self.assertEqual(
parse("1 (2)", ParserConfig({}, False)), ["1", Pair("2", nil)],
parse("1 (2)", ParserConfig({}, False)),
["1", Pair("2", nil)],
)

def test_unmatched_parens(self):
Expand All @@ -38,10 +39,12 @@ def test_unmatched_parens(self):

def test_dots_are_cons(self):
self.assertEqual(
parse("(1 . 2)", ParserConfig({}, True)), [Pair("1", "2")],
parse("(1 . 2)", ParserConfig({}, True)),
[Pair("1", "2")],
)
self.assertEqual(
parse("(1 . (2))", ParserConfig({}, True)), [Pair("1", Pair("2", nil))],
parse("(1 . (2))", ParserConfig({}, True)),
[Pair("1", Pair("2", nil))],
)

def test_prefixing(self):
Expand All @@ -64,3 +67,13 @@ def test_multi_char_prefix(self):
)
],
)

def test_parse_extremely_long(self):
count = 10**4
structure = nil
for _ in range(count):
structure = Pair(nil, structure)
self.assertEqual(
parse("(" + "()" * count + ")", ParserConfig({}, False)),
[structure],
)
10 changes: 10 additions & 0 deletions tests/renderer_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,13 @@ def test_nil_as_word_large(self):
),
)
self.assertFalse("()" in text)

def test_render_extremely_long(self):
count = 10**4
structure = nil
for _ in range(count):
structure = Pair(nil, structure)
self.assertEqual(
"(\n" + " ()\n" * count + ")",
Renderer(columns=1).render(structure),
)

0 comments on commit 45553b4

Please sign in to comment.