]> git.mdlowis.com Git - archive/dlang-scm.git/commitdiff
Added testes for exponent recognition
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 10 Jul 2012 06:04:08 +0000 (02:04 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 10 Jul 2012 06:04:08 +0000 (02:04 -0400)
source/lexer.scm
tests/test_lexer.scm

index cfea702cfcddbfb9b5d6159013e06e8d38eed0f4..9bda8576930f3c76c38418865160bcc9d0271f41 100644 (file)
 (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 "")))
+    (string
+      (if (char=? (buf-lookahead! in 1) #\e)
+        (char-match in #\e) (char-match in #\E)))
+    (dlang/integer in)))
 
 (define (dlang/character in)
   (token 'character
index 460f0dc49dd65a82ecf347429d251860e100a41c..8b2be37ba23f125d4ee4bfa9f1b268a61c2506ac 100644 (file)
 
 ; dlang/exponent
 ;------------------------------------------------------------------------------
+(def-test "dlang/exponent should recognize an exponent of length one"
+  (call-with-input-string "e0"
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (define result (dlang/exponent buffer))
+      (and (string? result)
+           (equal? "e0" result)))))
+
+(def-test "dlang/exponent should recognize an exponent of length two"
+  (call-with-input-string "e01"
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (define result (dlang/exponent buffer))
+      (and (string? result)
+           (equal? "e01" result)))))
+
+(def-test "dlang/exponent should recognize an exponent of length three"
+  (call-with-input-string "e012"
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (define result (dlang/exponent buffer))
+      (and (string? result)
+           (equal? "e012" result)))))
+
+(def-test "dlang/exponent should recognize an exponent with uppercase E"
+  (call-with-input-string "E012"
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (define result (dlang/exponent buffer))
+      (and (string? result)
+           (equal? "E012" result)))))
+
+(def-test "dlang/exponent should error when no integer portion in input"
+  (call-with-input-string "e "
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (check-error "Expected an integer"
+        (dlang/exponent buffer)))))
+
+(def-test "dlang/exponent should error when EOF"
+  (call-with-input-string ""
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (check-error "Expected 'E', received EOF instead"
+        (dlang/exponent buffer)))))
 
 ; dlang/character
 ;------------------------------------------------------------------------------