add fluid tests
[bpt/guile.git] / test-suite / tests / fluids.test
1 ;;;; -*- scheme -*-
2 ;;;; fluids.test --- test suite for fluid values
3 ;;;;
4 ;;;; Copyright (C) 2010 Free Software Foundation, Inc.
5 ;;;;
6 ;;;; This library is free software; you can redistribute it and/or
7 ;;;; modify it under the terms of the GNU Lesser General Public
8 ;;;; License as published by the Free Software Foundation; either
9 ;;;; version 3 of the License, or (at your option) any later version.
10 ;;;;
11 ;;;; This library is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;;; Lesser General Public License for more details.
15 ;;;;
16 ;;;; You should have received a copy of the GNU Lesser General Public
17 ;;;; License along with this library; if not, write to the Free Software
18 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20 (define-module (test-suite test-fluids)
21 :use-module (test-suite lib))
22
23
24 (define a (make-fluid))
25 (define b (make-fluid))
26 (define c #f)
27
28 (with-test-prefix "initial fluid values"
29 (pass-if "fluid-ref uninitialized fluid is #f"
30 (not (fluid-ref a))))
31
32 (with-test-prefix "with-fluids with non-fluid"
33 (pass-if-exception "exception raised if nonfluid passed to with-fluids"
34 exception:wrong-type-arg
35 (with-fluids ((c #t))
36 c))
37
38 (expect-fail "fluids not modified if nonfluid passed to with-fluids"
39 (catch 'wrong-type-arg
40 (lambda ()
41 (with-fluids ((a #t)
42 (c #t))
43 #f))
44 (lambda _
45 (not (fluid-ref a))))))
46
47 (with-test-prefix "with-fluids with duplicate fluid"
48 (pass-if "last value wins"
49 (with-fluids ((a 1)
50 (a 2))
51 (eqv? (fluid-ref a) 2)))
52
53 (pass-if "original value restored"
54 (and (with-fluids ((a 1)
55 (a 2))
56 (eqv? (fluid-ref a) 2))
57 (eqv? (fluid-ref a) #f))))