Remove locale u8vector functions
[bpt/guile.git] / test-suite / tests / elisp.test
index a7a4c4a..fd028da 100644 (file)
@@ -1,44 +1,30 @@
 ;;;; elisp.test --- tests guile's elisp support     -*- scheme -*-
-;;;; Copyright (C) 2002 Free Software Foundation, Inc.
+;;;; Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
 ;;;;
-;;;; This program 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, or (at your option)
-;;;; any later version.
-;;;;
-;;;; This program is distributed in the hope that it will be useful,
+;;;; This library is free software; you can redistribute it and/or
+;;;; modify it under the terms of the GNU Lesser General Public
+;;;; License as published by the Free Software Foundation; either
+;;;; version 3 of the License, or (at your option) any later version.
+;;;; 
+;;;; This library 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 this software; see the file COPYING.  If not, write to
-;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
-;;;; Boston, MA 02111-1307 USA
-;;;;
-;;;; As a special exception, the Free Software Foundation gives permission
-;;;; for additional uses of the text contained in its release of GUILE.
-;;;;
-;;;; The exception is that, if you link the GUILE library with other files
-;;;; to produce an executable, this does not by itself cause the
-;;;; resulting executable to be covered by the GNU General Public License.
-;;;; Your use of that executable is in no way restricted on account of
-;;;; linking the GUILE library code into it.
-;;;;
-;;;; This exception does not however invalidate any other reasons why
-;;;; the executable file might be covered by the GNU General Public License.
-;;;;
-;;;; This exception applies only to the code released by the
-;;;; Free Software Foundation under the name GUILE.  If you copy
-;;;; code from other Free Software Foundation releases into a copy of
-;;;; GUILE, as the General Public License permits, the exception does
-;;;; not apply to the code that you add in this way.  To avoid misleading
-;;;; anyone as to the status of such modified files, you must delete
-;;;; this exception notice from them.
-;;;;
-;;;; If you write modifications of your own for GUILE, it is your choice
-;;;; whether to permit this exception to apply to your modifications.
-;;;; If you do not wish that, delete this exception notice.
+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;;;; Lesser General Public License for more details.
+;;;; 
+;;;; You should have received a copy of the GNU Lesser General Public
+;;;; License along with this library; if not, write to the Free Software
+;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+(define-module (test-suite test-elisp)
+  :use-module (test-suite lib)
+  :use-module (ice-9 weak-vector))
+
+(define *old-stack-level* (and=> (memq 'stack (debug-options)) cadr))
+(if *old-stack-level*
+    (debug-set! stack (* 2 *old-stack-level*)))
+
+(define *old-%load-should-autocompile* %load-should-autocompile)
+(set! %load-should-autocompile #f)
 
 ;;;
 ;;; elisp
           (equal? (member "c" `("a" "b" "c" "d" . ,%nil)) `("c" "d" . ,%nil)))
 
        (pass-if "list->vector"
-          (equal? #(1 2 3) (list->vector `(1 2 3 . ,%nil))))
+          (equal? '#(1 2 3) (list->vector `(1 2 3 . ,%nil))))
 
        (pass-if "list->vector"
-          (equal? #(1 2 3) (list->vector `(1 2 3 . ,%nil))))
+          (equal? '#(1 2 3) (list->vector `(1 2 3 . ,%nil))))
 
        (pass-if "list->weak-vector"
           (equal? (weak-vector 1 2 3) (list->weak-vector `(1 2 3 . ,%nil))))
 
       ))
 
+(if (defined? '%nil)
+    (use-modules (lang elisp interface)))
+
+(if (defined? '%nil)
+
+    (with-test-prefix "elisp"
+
+      (define (elisp-pass-if expr expected)
+       (pass-if (with-output-to-string
+                 (lambda ()
+                   (write expr)))
+                (let ((calc (with-output-to-string
+                             (lambda ()
+                               (write (eval-elisp expr))))))
+                  (string=? calc expected))))
+      
+      (define (elisp-pass-if/maybe-error key expr expected)
+       (pass-if (with-output-to-string (lambda () (write expr)))
+                (string=?
+                  (catch key
+                         (lambda ()
+                           (with-output-to-string
+                             (lambda () (write (eval-elisp expr)))))
+                         (lambda (k . args)
+                           (format (current-error-port)
+                                   "warning: caught ~a: ~a\n" k args)
+                           (throw 'unresolved)))
+                  expected)))
+
+      (elisp-pass-if '(and #f) "#f")
+      (elisp-pass-if '(and #t) "#t")
+      (elisp-pass-if '(and nil) "#nil")
+      (elisp-pass-if '(and t) "#t")
+      (elisp-pass-if '(and) "#t")
+      (elisp-pass-if '(cond (nil t) (t 3)) "3")
+      (elisp-pass-if '(cond (nil t) (t)) "#t")
+      (elisp-pass-if '(cond (nil)) "#nil")
+      (elisp-pass-if '(cond) "#nil")
+      (elisp-pass-if '(if #f 'a 'b) "b")
+      (elisp-pass-if '(if #t 'a 'b) "a")
+      (elisp-pass-if '(if '() 'a 'b) "b")
+      (elisp-pass-if '(if nil 'a 'b) "b")
+      (elisp-pass-if '(if nil 1 2 3 4) "4")
+      (elisp-pass-if '(if nil 1 2) "2")
+      (elisp-pass-if '(if nil 1) "#nil")
+      (elisp-pass-if '(if t 1 2) "1")
+      (elisp-pass-if '(if t 1) "1")
+      (elisp-pass-if '(let (a) a) "#nil")
+      (elisp-pass-if '(let* (a) a) "#nil")
+      (elisp-pass-if '(let* ((a 1) (b (* a 2))) b) "2")
+      (elisp-pass-if '(memq '() '(())) "(())")
+      (elisp-pass-if '(memq '() '(nil)) "(#nil)")
+      (elisp-pass-if '(memq '() '(t)) "#nil")
+      (elisp-pass-if '(memq nil '(())) "(())")
+      (elisp-pass-if '(memq nil '(nil)) "(#nil)")
+      (elisp-pass-if '(memq nil (list nil)) "(#nil)")
+      (elisp-pass-if '(null '#f) "#t")
+      (elisp-pass-if '(null '()) "#t")
+      (elisp-pass-if '(null 'nil) "#t")
+      (elisp-pass-if '(null nil) "#t")
+      (elisp-pass-if '(or 1 2 3) "1")
+      (elisp-pass-if '(or nil t nil) "#t")
+      (elisp-pass-if '(or nil) "#nil")
+      (elisp-pass-if '(or t nil t) "#t")
+      (elisp-pass-if '(or t) "#t")
+      (elisp-pass-if '(or) "#nil")
+      (elisp-pass-if '(prog1 1 2 3) "1")
+      (elisp-pass-if '(prog2 1 2 3) "2")
+      (elisp-pass-if '(progn 1 2 3) "3")
+      (elisp-pass-if '(while nil 1) "#nil")
+      
+      (elisp-pass-if '(defun testf (x y &optional o &rest r) (list x y o r)) "testf")
+      (elisp-pass-if '(testf 1 2) "(1 2 #nil #nil)")
+      (elisp-pass-if '(testf 1 2 3 4 5 56) "(1 2 3 (4 5 56))")
+      ;; NB `lambda' in Emacs is self-quoting, but that's only after
+      ;; loading the macro definition of lambda in subr.el.
+      (elisp-pass-if '(function (lambda (x y &optional o &rest r) (list x y o r))) "(lambda (x y &optional o &rest r) (list x y o r))")
+      (elisp-pass-if '(funcall (lambda (x y &optional o &rest r) (list x y o r)) 1 2 3 4) "(1 2 3 (4))")
+
+      (elisp-pass-if '(apply (lambda (x y &optional o &rest r) (list x y o r)) 1 2 3 nil)
+                     "(1 2 3 #nil)")
+      
+      (elisp-pass-if '(setq x 3) "3")
+      (elisp-pass-if '(defvar x 4) "x")
+      (elisp-pass-if 'x "3")
+
+      ))
+
+(set! %load-should-autocompile *old-%load-should-autocompile*)
+(debug-set! stack *old-stack-level*)
+
 ;;; elisp.test ends here