From: Michael D. Lowis Date: Tue, 10 Jul 2012 06:04:08 +0000 (-0400) Subject: Added testes for exponent recognition X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=54adfe2c77d5a85d1575a5384eac0100abe38b8d;p=archive%2Fdlang-scm.git Added testes for exponent recognition --- diff --git a/source/lexer.scm b/source/lexer.scm index cfea702..9bda857 100644 --- a/source/lexer.scm +++ b/source/lexer.scm @@ -79,9 +79,10 @@ (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 diff --git a/tests/test_lexer.scm b/tests/test_lexer.scm index 460f0dc..8b2be37 100644 --- a/tests/test_lexer.scm +++ b/tests/test_lexer.scm @@ -96,6 +96,51 @@ ; 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 ;------------------------------------------------------------------------------