test-keyword.stk 3.92 KB
Newer Older
eg's avatar
eg committed
1 2
;;;;
;;;; test-keyword.stk	-- ss
3 4 5 6
;;;;
;;;; Copyright © 2005 Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
;;;;
;;;;
eg's avatar
eg committed
7 8 9 10
;;;; 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 of the License, or
;;;; (at your option) any later version.
11
;;;;
eg's avatar
eg committed
12 13 14 15
;;;; This program 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.
16
;;;;
eg's avatar
eg committed
17 18
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program; if not, write to the Free Software
19
;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
eg's avatar
eg committed
20
;;;; USA.
21
;;;;
eg's avatar
eg committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
;;;;           Author: Erick Gallesio [eg@essi.fr]
;;;;    Creation date:  3-May-2005 14:29 (eg)
;;;; Last file update:  3-May-2005 18:21 (eg)
;;;;

;;;; Most of theses tests were stolen in Gauche Scheme distribution


(test-section "Keywords")

;;----------------------------------------------------------------
(test-subsection "keywords")

(test "reader" #t (keyword? :abc))
(test "keyword?" #f (keyword? 'abc))
(test "make-keyword" #t (keyword? (make-keyword 'abc)))
(test "keyword->string" "abc" (keyword->string (make-keyword 'abc)))
(test "eq?.1" #t (eq? :a :a))
(test "eq?.2" #f (eq? :a 'a))
(test "eqv?.3" #t (eqv? :a :a))
(test "eqv?.4" #f (eqv? :a 'a))

;;----------------------------------------------------------------
(test-subsection "key-get")

(define *key-value-list* (list :a 33 :b "foo" :c :d :d 'ook :a 99))

(test "key-get.1" "foo"
       (key-get *key-value-list* :b))
(test "key-get.2" 33
       (key-get *key-value-list* :a))
(test "key-get.3" 'ook
       (key-get  *key-value-list* :d))
(test "key-get.4" *test-failed*
       (key-get *key-value-list* :z))
(test "key-get.5" 88
       (key-get *key-value-list* :z 88))
(test "key-get.6" *test-failed*
       (key-get :z (cdr *key-value-list*)))

;;----------------------------------------------------------------
(test-subsection "key-set!")

(test "key-set!.1" '(33 100 :d)
      (begin
	(key-set! *key-value-list* :b 100)
	(list (key-get *key-value-list* :a)
	      (key-get *key-value-list* :b)
	      (key-get *key-value-list* :c))))

(test "key-set!.2" 'foo
      (begin
	(key-set! *key-value-list* :foo 'foo)
	(key-get *key-value-list* :foo)))
76

eg's avatar
eg committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
;;----------------------------------------------------------------
(test-subsection "key-delete")

(test "key-delete.1" '((:a 3 :b 5) (:a 3))
       (let* ((x (list :a 3 :b 5))
              (y (key-delete x :b)))
         (list x y)))
(test "key-delete.2" '((:a 3 :b 5) (:b 5))
       (let* ((x (list :a 3 :b 5))
              (y (key-delete x :a)))
         (list x y)))
(test "key-delete.3" '((:a 3 :b 5) (:a 3 :b 5))
       (let* ((x (list :a 3 :b 5))
              (y (key-delete x :c)))
         (list x y)))
(test "key-delete.4" '((:a 3) ())
       (let* ((x (list :a 3))
              (y (key-delete x :a)))
         (list x y)))
(test "key-delete.5" '(() ())
       (let* ((x ())
              (y (key-delete x :a)))
         (list x y)))

;;----------------------------------------------------------------
(test-subsection "key-delete!")

(test "key-delete!.1" '((:a 3) (:a 3))
       (let* ((x (list :a 3 :b 5))
              (y (key-delete! x :b)))
         (list x y)))
(test "key-delete!.2" '((:a 3 :b 5) (:b 5))
       (let* ((x (list :a 3 :b 5))
              (y (key-delete! x :a)))
         (list x y)))
(test "key-delete!.3" '((:a 3 :b 5) (:a 3 :b 5))
       (let* ((x (list :a 3 :b 5))
              (y (key-delete! x :c)))
         (list x y)))
(test "key-delete!.4" '((:a 3) ())
       (let* ((x (list :a 3))
              (y (key-delete! x :a)))
         (list x y)))
(test "key-delete!.5" '(() ())
       (let* ((x ())
              (y (key-delete! x :a)))
         (list x y)))


(test-section-end)