From 457d84e3f73c78361cc43dba966d28a45eb8e99a Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Sat, 15 Dec 2012 17:31:23 -0500 Subject: [PATCH] Adding in better tests & a fix. --- hy/lex/states.py | 2 +- tests/lexer/test_basic_lexing.py | 46 +++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/hy/lex/states.py b/hy/lex/states.py index b7cd24c..6d12468 100644 --- a/hy/lex/states.py +++ b/hy/lex/states.py @@ -19,7 +19,7 @@ class State(object): self.sub_machine.process(x) idle = type(self.sub_machine.state) == Idle if idle: - self.nodes.append(self.sub_machine.nodes) + self.nodes += self.sub_machine.nodes self.sub_machine = None return diff --git a/tests/lexer/test_basic_lexing.py b/tests/lexer/test_basic_lexing.py index 6b04bad..2aa9d15 100644 --- a/tests/lexer/test_basic_lexing.py +++ b/tests/lexer/test_basic_lexing.py @@ -2,10 +2,14 @@ from hy.lex.tokenize import tokenize def test_simple_tokenize(): + """Checking we can still handle something simple.""" + assert [["+", "1", "1"]] == tokenize("(+ 1 1)") def test_double_tokenize(): + """Checking if we can lex two things at once.""" + assert [ ["+", "1", "2"], ["-", "1", "1"] @@ -13,8 +17,44 @@ def test_double_tokenize(): def test_simple_recurse(): + """ Test recursion """ assert [ - '+', '1', [ - '+', '1', '1' + ['fn', + 'one', + ['fn', 'two'], ] - ] == tokenize("(+ 1 (+ 1 1))") + ] == tokenize("(fn one (fn two))") + + +def test_mid_recurse(): + """ Test some crazy recursion """ + + assert [ + ['fn', + 'one', + ['fn', 'two'], + ['fn', 'three'], + ] + ] == tokenize("(fn one (fn two)(fn three))") + + +def test_full_recurse(): + """ Test something we could see for real """ + assert [ + ['fn', + 'el', + ['+', + '1', + '2', + ['==', + '1', + '20' + ], + ['-', + '1', + '1' + ], + ] + ], + ['fn1', 'foo', 'bar'] + ] == tokenize("(fn el (+ 1 2 (== 1 20) (- 1 1)))(fn1 foo bar)")