diff --git a/collects/tests/syntax-color/scheme-lexer.ss b/collects/tests/syntax-color/scheme-lexer.ss new file mode 100644 index 0000000000..908eb845ad --- /dev/null +++ b/collects/tests/syntax-color/scheme-lexer.ss @@ -0,0 +1,446 @@ +;; Not tested: +;; Non-character input data (i.e. specials) +;; The R5RS part of numbers +;; +;; Not supported +;; Keywords +;; Honu (#hx, #sx, #honu) +;; #reader + +(require (lib "scheme-lexer.ss" "syntax-color")) + +(define (char kind) + (case kind + ((white-space) #\space) + ((symbol) #\i) + ((constant) #\c) + ((comment) #\;) + ((string) #\s) + ((parenthesis) #\p) + ((other) #\o) + ((no-color) #\n) + ((error) #\x) + (else + (error 'char "Given ~a" kind)))) + +(define (chunks x) + (cond + ((null? x) 0) + ((null? (cdr x)) 1) + ((char=? (car x) (cadr x)) + (chunks (cdr x))) + (else (add1 (chunks (cdr x)))))) + +(define (lex f p) + (define-values (lexeme kind paren? start end) + (f p)) + (cond + ((eq? 'eof kind) null) + (else + (cons (make-string (- end start) (char kind)) + (lex f p))))) + +(define (test input expected . num-toks) + (let* ((l (lex scheme-lexer (open-input-string input))) + (s (apply string-append l))) + (unless (string=? s expected) + (printf "input : ~a~n" input) + (printf "output : ~s~n" s) + (printf "expected: ~s~n~n" expected)) + (let ((e-n + (cond + ((not (null? num-toks)) (car num-toks)) + (else (chunks (string->list expected))))) + (a-n (length l))) + (unless (= e-n a-n) + (printf "input : ~a~n" input) + (printf "expected: ~a tokens~n" e-n) + (printf "got : ~a tokens~n~n" a-n))))) + +;; Delimiters +(test " " " ") +(test "\t" " ") +(test "\n" " ") +(test "\"" "x") +(test "," "o") +(test "'" "c") +(test "`" "c") +(test ";" ";") +(test "(" "p") +(test ")" "p") +(test "[" "p") +(test "]" "p") +(test "{" "p") +(test "}" "p") + +;; # +(test "#fq" "cci") +(test "#Fq" "cci") +(test "#tq" "cci") +(test "#Tq" "cci") +(test "#012423(a" "ppppppppi") +(test "#1{a" "pppi") +(test "#1[a" "pppi") +(test "#(a" "ppi") +(test "#{a" "ppi") +(test "#[a" "ppi") +(test "#&a" "cci") +(test "#'a" "cci") +(test "#`a" "cci") +(test "#,a" "ooi") +(test "#,@a" "oooi") +(test "#CsA" "oooi") +(test "#cIA" "oooi") +(test "#hash(a" "ppppppi") +(test "#hasheq(a" "ppppppppi") +(test "#hash[a" "ppppppi") +(test "#hasheq[a" "ppppppppi") +(test "#hash{a" "ppppppi") +(test "#hasheq{a" "ppppppppi") +(test "#135#a" "oooooi") +(test "#453=a" "oooooi") +(test #<