]> git.mdlowis.com Git - archive/dlang-scm.git/commitdiff
Added tests for parse-utils
authorMike D. Lowis <mike@mdlowis.com>
Fri, 27 Jul 2012 18:51:41 +0000 (14:51 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Fri, 27 Jul 2012 18:51:41 +0000 (14:51 -0400)
source/parse-utils.scm
tests/test_parse_utils.scm

index 7828996171e239737e2162a3d3177a4181c0c6dc..7b1362fc440e04d6622b8749d38dfcc7ed4081a2 100644 (file)
 (define (char-match buf expect)
   (define actual (buf-lookahead! buf 1))
   (if (eof-object? actual)
-    (abort (string-append "Expected '" (string expect) "', received EOF instead"))
+    (abort
+      (string-append "Expected '" (string expect) "', received EOF instead"))
     (if (equal? expect actual)
       (buf-consume! buf)
       (abort
         (string-append
-          "Expected '" (string expect) "', received '" (string actual) "' instead"))))
+          "Expected '" (string expect)
+          "', received '" (string actual) "' instead"))))
   actual)
 
 (define (token-match buf expect)
index 5cc804fdd2b3b5162ee65c76f97245191ec79da0..62d6a34ac5d248d46406a00cab0ae95d10e0f49c 100644 (file)
@@ -1,3 +1,93 @@
 (include "test.scm")
 (declare (unit test_parse_utils))
 
+; Tests for function definitions
+;------------------------------------------------------------------------------
+(def-test "functions for token creation and usage should be created"
+  (and (procedure? make-token)
+       (procedure? token)
+       (procedure? token-text)
+       (procedure? token-type)))
+
+(def-test "functions for syntree creation and usage should be created"
+  (and (procedure? make-syntree)
+       (procedure? syntree)
+       (procedure? syntree-text)
+       (procedure? syntree-type)
+       (procedure? syntree-children)))
+
+; syntree=?
+;------------------------------------------------------------------------------
+(def-test "syntree=? should return true if trees are equal"
+  (syntree=?
+    (syntree 'foo "" '())
+    (syntree 'foo "" '())))
+
+(def-test "syntree=? should return false if types differ"
+  (not
+    (syntree=?
+      (syntree 'foo "" '())
+      (syntree 'bar "" '()))))
+
+(def-test "syntree=? should return false if text differs"
+  (not
+    (syntree=?
+      (syntree 'foo "a" '())
+      (syntree 'foo "b" '()))))
+
+(def-test "syntree=? should return false if children differ"
+  (not
+    (syntree=?
+      (syntree 'foo "" '())
+      (syntree 'foo "" '(1)))))
+
+; syntree-children=?
+;------------------------------------------------------------------------------
+(def-test "syntree=? should return true is lists and elements are equal"
+  (syntree-children=?
+    (list (syntree 'foo "bar" '()))
+    (list (syntree 'foo "bar" '()))))
+
+(def-test "syntree=? should return true if both lists are null"
+  (syntree-children=? '() '()))
+
+(def-test "syntree=? should return false if only one of the lists is null"
+  (not (syntree-children=? '() '(1))))
+
+(def-test "syntree=? should return false if elements differ"
+  (not
+    (syntree-children=?
+      (list (syntree 'foo "" '()))
+      (list (syntree 'bar "" '())))))
+
+; char-match
+;------------------------------------------------------------------------------
+
+; token-match
+;------------------------------------------------------------------------------
+
+; token-matches?
+;------------------------------------------------------------------------------
+
+; keyword-match
+;------------------------------------------------------------------------------
+
+; token->syntree
+;------------------------------------------------------------------------------
+(def-test "token->syntree should convert a token to a syntree"
+  (syntree=?
+    (token->syntree (token 'foo "bar"))
+    (syntree 'foo "bar" '())))
+
+; test-apply
+;------------------------------------------------------------------------------
+
+; collect-char
+;------------------------------------------------------------------------------
+
+; consume-all
+;------------------------------------------------------------------------------
+
+; collect
+;------------------------------------------------------------------------------
+