]> git.mdlowis.com Git - archive/dlang-scm.git/commitdiff
Added tests for recognizing decimals
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 10 Jul 2012 05:29:04 +0000 (01:29 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 10 Jul 2012 05:29:04 +0000 (01:29 -0400)
source/lexer.scm
tests/test_lexer.scm

index fda961be8c1ff7c3051ae42072b48dcd36c7753e..cfea702cfcddbfb9b5d6159013e06e8d38eed0f4 100644 (file)
 
 (define (dlang/decimal in)
   (string-append
-    (match in #\.)
-    (dlang/digits in "")))
+    (string (char-match in #\.))
+    (dlang/integer in)))
 
 (define (dlang/exponent in)
   (string-append
+    ;(string (char-match-one-of in '(#\e #\E)))
     (if (char=? (buf-lookahead! in 1) #\e)
       (match in #\e) (match in #\E))
     (dlang/integer in "")))
index c0c1c76ed752f3e06641bf0156de8e0e92bd9fdc..460f0dc49dd65a82ecf347429d251860e100a41c 100644 (file)
@@ -48,7 +48,7 @@
         (dlang/integer buffer)))))
 
 (def-test "dlang/integer should error when EOF"
-  (call-with-input-string "abc"
+  (call-with-input-string ""
     (lambda (input)
       (define buffer (buf input read-char))
       (check-error "Expected an integer"
 
 ; dlang/decimal
 ;------------------------------------------------------------------------------
+(def-test "dlang/decimal should recognize an decimal of length one"
+  (call-with-input-string ".0"
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (define result (dlang/decimal buffer))
+      (and (string? result)
+           (equal? ".0" result)))))
+
+(def-test "dlang/decimal should recognize an decimal of length two"
+  (call-with-input-string ".01"
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (define result (dlang/decimal buffer))
+      (and (string? result)
+           (equal? ".01" result)))))
+
+(def-test "dlang/decimal should recognize an decimal of length three"
+  (call-with-input-string ".012"
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (define result (dlang/decimal buffer))
+      (and (string? result)
+           (equal? ".012" result)))))
+
+(def-test "dlang/decimal should error when no integer portion in input"
+  (call-with-input-string ". "
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (check-error "Expected an integer"
+        (dlang/decimal buffer)))))
+
+(def-test "dlang/decimal should error when EOF"
+  (call-with-input-string ""
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (check-error "Expected '.', received EOF instead"
+        (dlang/decimal buffer)))))
 
 ; dlang/exponent
 ;------------------------------------------------------------------------------