From ac0a597742d30e32315aade49003690062724272 Mon Sep 17 00:00:00 2001 From: Konrad Hinsen Date: Thu, 11 Apr 2013 09:54:59 +0200 Subject: [PATCH] Tests for float and complex constants --- tests/lex/test_lex.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/lex/test_lex.py b/tests/lex/test_lex.py index 45922b9..676c109 100644 --- a/tests/lex/test_lex.py +++ b/tests/lex/test_lex.py @@ -20,6 +20,8 @@ from hy.models.expression import HyExpression from hy.models.integer import HyInteger +from hy.models.float import HyFloat +from hy.models.complex import HyComplex from hy.models.symbol import HySymbol from hy.models.string import HyString from hy.models.dict import HyDict @@ -77,6 +79,25 @@ def test_lex_expression_integer(): assert objs == [HyExpression([HySymbol("foo"), HyInteger(2)])] +def test_lex_expression_float(): + """ Make sure expressions can produce floats """ + objs = tokenize("(foo 2.)") + assert objs == [HyExpression([HySymbol("foo"), HyFloat(2.)])] + objs = tokenize("(foo -0.5)") + assert objs == [HyExpression([HySymbol("foo"), HyFloat(-0.5)])] + objs = tokenize("(foo 1.e7)") + assert objs == [HyExpression([HySymbol("foo"), HyFloat(1.e7)])] + +def test_lex_expression_complex(): + """ Make sure expressions can produce complex """ + objs = tokenize("(foo 2.j)") + assert objs == [HyExpression([HySymbol("foo"), HyComplex(2.j)])] + objs = tokenize("(foo -0.5j)") + assert objs == [HyExpression([HySymbol("foo"), HyComplex(-0.5j)])] + objs = tokenize("(foo 1.e7j)") + assert objs == [HyExpression([HySymbol("foo"), HyComplex(1.e7j)])] + + def test_lex_line_counting(): """ Make sure we can count lines / columns """ entry = tokenize("(foo (one two))")[0]