(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 "")))
(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
;------------------------------------------------------------------------------