;;; -*-lisp-*- ;;; ;;; Test lexical analyser ;;; ;;; (c) 2010 Straylight/Edgeware ;;; ;;;----- Licensing notice --------------------------------------------------- ;;; ;;; This file is part of the Sensible Object Design, an object system for C. ;;; ;;; SOD is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 2 of the License, or ;;; (at your option) any later version. ;;; ;;; SOD is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with SOD; if not, write to the Free Software Foundation, ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. (cl:in-package #:sod-test) (defclass lexer-test (test-case) ()) (add-test *sod-test-suite* (get-suite lexer-test)) ;;;-------------------------------------------------------------------------- ;;; Simple lexical analysis tests. (defun list-tokens (string) (let ((lexer (make-instance 'sod-token-scanner :char-scanner (make-string-scanner string) :filename ""))) (with-parser-context (token-scanner-context :scanner lexer) (parse (list () (if (scanner-at-eof-p lexer) (values '(:eof) nil nil) (multiple-value-prog1 (values (cons (token-type lexer) (token-value lexer)) t t) (scanner-step lexer)))))))) (defmacro assert-tokens (string &rest list) `(assert-equal (list-tokens ,string) ',list)) (def-test-method simple-lexer ((test lexer-test) :run nil) (assert-tokens "foo - bar" (:id . "foo") (#\- . nil) (:id . "bar"))) ;;;----- That's all, folks --------------------------------------------------