~ubuntu-branches/ubuntu/hardy/sigscheme/hardy-proposed

« back to all changes in this revision

Viewing changes to test/test-srfi34-2.scm

  • Committer: Bazaar Package Importer
  • Author(s): NIIBE Yutaka
  • Date: 2006-05-23 21:46:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060523214641-6ix4gz34wpiehub8
Tags: 0.5.0-2
* debian/control (Build-Depends): Added ruby.
  Thanks to Frederik Schueler.  Closes: #368571
* debian/rules (clean): invoke 'distclean' instead of 'clean'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;;  FileName : test-srfi34-2.scm
 
2
;;  About    : unit test for SRFI-34 taken from "Examples" section of SRFI-34
 
3
;;
 
4
;;  Copyright (C) 2005-2006 YamaKen <yamaken AT bp.iij4u.or.jp>
 
5
;;
 
6
;;  All rights reserved.
 
7
;;
 
8
;;  Redistribution and use in source and binary forms, with or without
 
9
;;  modification, are permitted provided that the following conditions
 
10
;;  are met:
 
11
;;
 
12
;;  1. Redistributions of source code must retain the above copyright
 
13
;;     notice, this list of conditions and the following disclaimer.
 
14
;;  2. Redistributions in binary form must reproduce the above copyright
 
15
;;     notice, this list of conditions and the following disclaimer in the
 
16
;;     documentation and/or other materials provided with the distribution.
 
17
;;  3. Neither the name of authors nor the names of its contributors
 
18
;;     may be used to endorse or promote products derived from this software
 
19
;;     without specific prior written permission.
 
20
;;
 
21
;;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 
22
;;  IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 
23
;;  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
24
;;  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
 
25
;;  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
26
;;  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
27
;;  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
28
;;  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
29
;;  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 
30
;;  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
31
;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
32
 
 
33
(load "./test/unittest.scm")
 
34
 
 
35
(cond-expand
 
36
 (sigscheme
 
37
  (use srfi-34))
 
38
 (else #t))
 
39
 
 
40
;; All tests in this file are passed against r2143 (new repository)
 
41
 
 
42
;;(set! *test-track-progress* #t)
 
43
 
 
44
;; these tests are ported from "Examples" section of SRFI-34
 
45
 
 
46
(define print-expected
 
47
  (lambda (expected)
 
48
    (display " expected print: ")
 
49
    (display expected)
 
50
    (newline)
 
51
    (display "   actual print: ")))
 
52
 
 
53
;;PRINTS: condition: an-error
 
54
(print-expected "condition: an-error")
 
55
(assert-equal? "Examples of SRFI-34 document #1"
 
56
               'exception
 
57
               (call-with-current-continuation
 
58
                (lambda (k)
 
59
                  (with-exception-handler (lambda (x)
 
60
                                            (display "condition: ")
 
61
                                            (write x)
 
62
                                            (newline)
 
63
                                            (k 'exception))
 
64
                    (lambda ()
 
65
                      (+ 1 (raise 'an-error)))))))
 
66
 
 
67
;;PRINTS: something went wrong
 
68
;; Then behaves in an unspecified way. Although the behavior when a handler
 
69
;; returned is not specified in SRFI-34, SigScheme should produce an error to
 
70
;; prevent being misused by users.
 
71
(print-expected "something went wrong")
 
72
(assert-error "Examples of SRFI-34 document #2"
 
73
              (lambda ()
 
74
                (call-with-current-continuation
 
75
                 (lambda (k)
 
76
                   (with-exception-handler (lambda (x)
 
77
                                             (display "something went wrong")
 
78
                                             (newline)
 
79
                                             'dont-care)
 
80
                     (lambda ()
 
81
                       (+ 1 (raise 'an-error))))))))
 
82
 
 
83
;;PRINTS: condition: an-error
 
84
(print-expected "condition: an-error")
 
85
(assert-equal? "Examples of SRFI-34 document #3"
 
86
               'exception
 
87
               (guard (condition
 
88
                       (else
 
89
                        (display "condition: ")
 
90
                        (write condition)
 
91
                        (newline)
 
92
                        'exception))
 
93
                 (+ 1 (raise 'an-error))))
 
94
 
 
95
;;PRINTS: something went wrong
 
96
(print-expected "something went wrong")
 
97
(assert-equal? "Examples of SRFI-34 document #4"
 
98
               'dont-care
 
99
               (guard (condition
 
100
                       (else
 
101
                        (display "something went wrong")
 
102
                        (newline)
 
103
                        'dont-care))
 
104
                 (+ 1 (raise 'an-error))))
 
105
 
 
106
(assert-equal? "Examples of SRFI-34 document #5"
 
107
               'positive
 
108
               (call-with-current-continuation
 
109
                (lambda (k)
 
110
                  (with-exception-handler (lambda (x)
 
111
                                            (display "reraised ") (write x) (newline)
 
112
                                            (k 'zero))
 
113
                    (lambda ()
 
114
                      (guard (condition
 
115
                              ((positive? condition) 'positive)
 
116
                              ((negative? condition) 'negative))
 
117
                        (raise 1)))))))
 
118
 
 
119
(assert-equal? "Examples of SRFI-34 document #6"
 
120
               'negative
 
121
               (call-with-current-continuation
 
122
                (lambda (k)
 
123
                  (with-exception-handler (lambda (x)
 
124
                                            (display "reraised ") (write x) (newline)
 
125
                                            (k 'zero))
 
126
                    (lambda ()
 
127
                      (guard (condition
 
128
                              ((positive? condition) 'positive)
 
129
                              ((negative? condition) 'negative))
 
130
                        (raise -1)))))))
 
131
 
 
132
;;PRINTS: reraised 0
 
133
(print-expected "reraised 0")
 
134
(assert-equal? "Examples of SRFI-34 document #7"
 
135
               'zero
 
136
               (call-with-current-continuation
 
137
                (lambda (k)
 
138
                  (with-exception-handler (lambda (x)
 
139
                                            (display "reraised ") (write x) (newline)
 
140
                                            (k 'zero))
 
141
                    (lambda ()
 
142
                      (guard (condition
 
143
                              ((positive? condition) 'positive)
 
144
                              ((negative? condition) 'negative))
 
145
                        (raise 0)))))))
 
146
 
 
147
(assert-equal? "Examples of SRFI-34 document #8"
 
148
               42
 
149
               (guard (condition
 
150
                       ((assq 'a condition) => cdr)
 
151
                       ((assq 'b condition)))
 
152
                 (raise (list (cons 'a 42)))))
 
153
 
 
154
(assert-equal? "Examples of SRFI-34 document #9"
 
155
               '(b . 23)
 
156
               (guard (condition
 
157
                       ((assq 'a condition) => cdr)
 
158
                       ((assq 'b condition)))
 
159
                 (raise (list (cons 'b 23)))))
 
160
 
 
161
(total-report)