Commits

Ronny Pfannschmidt committed b136aa1

better example test, add equal compare

  • Participants
  • Parent commits da7839f

Comments (0)

Files changed (2)

File testing/test_parse_examples.py

 import py
 from whenever import parse
+examples = py.path.local(__file__).join('../../examples/')
 
-def test_parse_example():
-    file = py.path.local(__file__).join('../../examples/fib.when')
-    parse(str(file))
+def pytest_generate_tests(metafunc):
+    for path in examples.visit('*.when'):
+        metafunc.addcall(id=path.basename, funcargs={'path': path})
+
+def test_parse_example(path):
+    parse(str(path))

File whenever/__init__.py

 from pypy.rlib.streamio import open_file_as_stream
 
 from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function
-
+from pypy.rlib.parsing.deterministic import LexerError
+from pypy.rlib.parsing.parsing import ParseError
 
 
 def parse(filename):
     print commands
     try:
         return int(number_str), parse_command(commands[:-1])
-    except Exception, e:
+    except LexerError, e:
+        print e.args[0], e.nice_error_message()
+        print commands
+        print ' '*e.args[2].i + '^'
+        raise
+    except ParseError, e:
         print e.args[0], e.nice_error_message()
         print commands
         print ' '*e.args[0].i + '^'
 STAR: "\*";
 FUNC: "N";
 
+EQ: "==";
 LT: "<";
 GT: ">";
 LTE: "<=";
 addition: (number [PLUS])* number;
 expr: addition|number;
 
-comparisation: LT | GT | LTE | GTE;
+comparisation: EQ | LT | GT | LTE | GTE;
 compare: expr comparisation expr;