1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 76 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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
;; A practical implementation for the Scheme programming language
;;
;; ,--^,
;; _ ___/ /|/
;; ,;'( )__, ) '
;; ;; // L__.
;; ' \\ / '
;; ^ ^
;;
;; Copyright (c) 1992-2004 Manuel Serrano
;;
;; Bug descriptions, use reports, comments or suggestions are
;; welcome. Send them to
;; bigloo@sophia.inria.fr
;; http://www.inria.fr/mimosa/fp/Bigloo
;;
;; 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. More precisely,
;;
;; - The compiler and the tools are distributed under the terms of the
;; GNU General Public License.
;;
;; - The Bigloo run-time system and the libraries are distributed under
;; the terms of the GNU Library General Public License. The source code
;; of the Bigloo runtime system is located in the ./runtime directory.
;; The source code of the FairThreads library is located in the
;; ./fthread directory.
;;
;; 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.
;;
;; You should have received a copy of the GNU General Public
;; License along with this program; if not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.
;*---------------------------------------------------------------------*/
;* serrano/prgm/project/bigloo/recette/case.scm */
;* */
;* Author : Manuel Serrano */
;* Creation : Wed Mar 18 15:16:39 1992 */
;* Last change : Mon May 19 06:11:19 2003 (serrano) */
;* */
;* On test le case. */
;*---------------------------------------------------------------------*/
;; ChangeLog
;;
;; 2005-08-18 kzk Copied from Bigloo 2.6e and adapted to SigScheme
(load "./test/unittest-bigloo.scm")
;*---------------------------------------------------------------------*/
;* test 1. */
;*---------------------------------------------------------------------*/
(define (test1 x)
(case x
((tutu) 'tutu)
((toto) 'toto)
(else
'dummy
'else)))
;*---------------------------------------------------------------------*/
;* test 2. */
;*---------------------------------------------------------------------*/
(define (test2 x)
(case (begin 1 2 x)
((tete tutu tyty) 1)
((toto) 2)
((tata) 3)))
;*---------------------------------------------------------------------*/
;* test 3. */
;*---------------------------------------------------------------------*/
(define (test3 x)
(case (begin 2 3 x)
((1 2 3 4) 1)
((5 6 7 8) 5)
(else 0)))
;*---------------------------------------------------------------------*/
;* test 4. */
;*---------------------------------------------------------------------*/
(define (test4 x)
(case x
((tutu 1) "tutu ou 1")
((2 3) "2 ou 3")
(else "else")))
;*---------------------------------------------------------------------*/
;* test 5. */
;* ------------------------------------------------------------- */
;* Ce test est important car il permet de tester la compilation */
;* des cases qui comportent des symboles qui ont meme nombre de */
;* hash */
;*---------------------------------------------------------------------*/
(define (test5 x)
(case x
((SHOW show)
'show)
((compute!)
'compute!)
(else
'else)))
;*---------------------------------------------------------------------*/
;* test 6. */
;*---------------------------------------------------------------------*/
(define (test6 x)
(case x
((#\o)
#\o)
((#\d)
#\d)
((#\x)
#\x)))
;*---------------------------------------------------------------------*/
;* test 7. ... */
;*---------------------------------------------------------------------*/
(define (test7 x)
;; set! et fibo on meme nombre de hash
(case x
((set!)
'set!)
(else
'else)))
;*---------------------------------------------------------------------*/
;* test.8 */
;* ------------------------------------------------------------- */
;* This test used to make the compiler crashes. */
;*---------------------------------------------------------------------*/
;(define-macro push!
; (lambda (stack o)
; `(begin
; (set! ,stack (cons ,o ,stack))
; ,o)))
;
;(define (test.8 data)
; (let ((elem-stack '()))
; (push! elem-stack
; (read/rp (regular-grammar ()
; (else 2))
; (open-input-string data)))
; elem-stack))
;*---------------------------------------------------------------------*/
;* test-case ... */
;*---------------------------------------------------------------------*/
(define (test-case)
(test "case symbol" (test1 'tutu) 'tutu)
(test "case symbol" (test1 'toto) 'toto)
(test "case symbol" (test1 'tata) 'else)
(test "case symbol" (test1 5) 'else)
(test "case symbol" (test2 'tutu) 1)
(test "case symbol" (test2 'toto) 2)
(test "case symbol" (test2 'tata) 3)
; (test "case symbol" (test2 5) #unspecified)
(test "case integer" (test3 (+ 1 2)) 1)
(test "case integer" (test3 'toto) 0)
(test "case mixte" (test4 'tutu) "tutu ou 1")
(test "case mixte" (test4 1) "tutu ou 1")
(test "case mixte "(test4 3) "2 ou 3")
(test "case mixte" (test4 'titi) "else")
(test "case hash" (test5 'show) 'show)
(test "case hash" (test5 'SHOW) 'show)
(test "case hash" (test5 'compute!) 'compute!)
(test "case hash" (test5 'toto) 'else)
; (test "case char" (test6 #\a) #unspecified)
(test "case char" (test6 #\x) #\x)
(test "case char" (test6 (string-ref "o" 0)) #\o)
(test "case hash" (test7 'fibo) 'else))
(test-case)
(total-report)
|