You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beautiful-racket/beautiful-racket-demo/basic-demo/lexer-test.rkt

66 lines
1.9 KiB
Racket

8 years ago
#lang br
(require "lexer.rkt" brag/support rackunit)
(define (lex str)
(apply-lexer basic-lexer str))
(check-equal? (lex "") empty)
(check-equal?
(lex " ")
(list (srcloc-token (token " " #:skip? #t)
(srcloc 'string 1 0 1 1))))
8 years ago
(check-equal?
(lex "rem ignored\n")
(list (srcloc-token (token 'REM "rem ignored")
(srcloc 'string 1 0 1 11))
8 years ago
(srcloc-token (token 'NEWLINE "\n")
(srcloc 'string 1 11 12 1))))
8 years ago
(check-equal?
(lex "print")
(list (srcloc-token (token "print" "print")
(srcloc 'string 1 0 1 5))))
8 years ago
(check-equal?
(lex "goto")
(list (srcloc-token (token "goto" "goto")
(srcloc 'string 1 0 1 4))))
8 years ago
(check-equal?
(lex "end")
(list (srcloc-token (token "end" "end")
(srcloc 'string 1 0 1 3))))
8 years ago
(check-equal?
(lex "+")
(list (srcloc-token (token "+" "+")
(srcloc 'string 1 0 1 1))))
(check-equal?
(lex ";")
(list (srcloc-token (token ";" ";")
(srcloc 'string 1 0 1 1))))
(check-equal?
(lex ":")
(list (srcloc-token (token ":" ":")
(srcloc 'string 1 0 1 1))))
8 years ago
(check-equal?
(lex "12")
(list (srcloc-token (token 'INTEGER 12)
(srcloc 'string 1 0 1 2))))
8 years ago
(check-equal?
(lex "1.2")
(list (srcloc-token (token 'DECIMAL 1.2)
(srcloc 'string 1 0 1 3))))
8 years ago
(check-equal?
(lex "12.")
(list (srcloc-token (token 'DECIMAL 12.)
(srcloc 'string 1 0 1 3))))
8 years ago
(check-equal?
(lex ".12")
(list (srcloc-token (token 'DECIMAL .12)
(srcloc 'string 1 0 1 3))))
8 years ago
(check-equal?
(lex "\"foo\"")
(list (srcloc-token (token 'STRING "foo")
(srcloc 'string 1 0 1 5))))
8 years ago
(check-equal?
(lex "'foo'")
(list (srcloc-token (token 'STRING "foo")
(srcloc 'string 1 0 1 5))))
8 years ago
(check-exn exn:fail:read? (lambda () (lex "x")))