]> git.mdlowis.com Git - archive/dlang-scm.git/commitdiff
Added tests for error conditions in parsing rules
authorMike D. Lowis <mike@mdlowis.com>
Thu, 19 Jul 2012 20:58:42 +0000 (16:58 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Thu, 19 Jul 2012 20:58:42 +0000 (16:58 -0400)
source/parser.scm
tests/test_parser.scm

index 29734887ea9f3fbbab533aefeb506cfb397ac2d0..6c621472812ac36853de70b70554fe53aff3234a 100644 (file)
   node)
 
 (define (dlang/basic-expr in)
-  (define tok (buf-lookahead! in 1))
-  (if (equal? 'lpar (token-type tok))
+  (if (token-matches? in 'lpar)
     (dlang/operator-app in)
     (dlang/literal in)))
 
index 96eb831579fc1a9d162d1bcd8abb5123fe87bf33..da99c1ff459cacf67e5f80c2b4f20ac571c8bfe9 100644 (file)
             (syntree 'number "1.0" '())
             (syntree 'number "2.0" '())))))))
 
+(def-test "dlang/operator-app should error when first paren missing"
+  (call-with-input-string "1.0 * 2.0)"
+    (lambda (input)
+      (define lxr (make-lexer input))
+      (check-exception
+        "Expected a token of type 'lpar, received 'number instead"
+        (dlang/operator-app lxr)))))
+
+(def-test "dlang/operator-app should error when second paren missing"
+  (call-with-input-string "(1.0 * 2.0"
+    (lambda (input)
+      (define lxr (make-lexer input))
+      (check-exception "Expected a token of type 'rpar, received EOF instead"
+        (dlang/operator-app lxr)))))
+
+(def-test "dlang/operator-app should error operator is not an id"
+  (call-with-input-string "(1.0 2.0 3.0)"
+    (lambda (input)
+      (define lxr (make-lexer input))
+      (check-exception "Expected a token of type 'id, received 'number instead"
+        (dlang/operator-app lxr)))))
+
 ; dlang/operator
 ;------------------------------------------------------------------------------
 (def-test "dlang/operator should parse an Id"
             (syntree 'number "1.0" '())
             (syntree 'symbol "$c" '())))))))
 
+(def-test "dlang/arg-list should error when first paren missing"
+  (call-with-input-string ")"
+    (lambda (input)
+      (define lxr (make-lexer input))
+      (check-exception "Expected a token of type 'lpar, received 'rpar instead"
+        (dlang/arg-list lxr)))))
+
+(def-test "dlang/arg-list should error when second paren missing"
+  (call-with-input-string "("
+    (lambda (input)
+      (define lxr (make-lexer input))
+      (check-exception "Expected a literal"
+        (dlang/arg-list lxr)))))
+
+(def-test "dlang/arg-list should error when comma missing between args"
+  (call-with-input-string "(a b)"
+    (lambda (input)
+      (define lxr (make-lexer input))
+      (check-exception "Expected a token of type 'comma, received 'id instead"
+        (dlang/arg-list lxr)))))
+
 ; dlang/arg-list?
 ;------------------------------------------------------------------------------
 (def-test "dlang/arg-list? should return true if input contains an arg list"
           (list
             (syntree 'number "1.0" '())
             (syntree 'number "2.0" '())))))))
+
+(def-test "dlang/expr-block should error when no terminator found"
+  (call-with-input-string "1.0 2.0"
+    (lambda (input)
+      (define lxr (make-lexer input))
+      (check-exception "Expected a literal"
+        (dlang/expr-block lxr 'term)))))
+