0fd4b6f99c7952e05d00351475a8e8084505c80b
[8sync.git] / tests / test-rmeta-slot.scm
1 ;;; 8sync --- Asynchronous programming for Guile
2 ;;; Copyright (C) 2017 Christopher Allan Webber <cwebber@dustycloud.org>
3 ;;;
4 ;;; This file is part of 8sync.
5 ;;;
6 ;;; 8sync is free software: you can redistribute it and/or modify it
7 ;;; under the terms of the GNU Lesser General Public License as
8 ;;; published by the Free Software Foundation, either version 3 of the
9 ;;; License, or (at your option) any later version.
10 ;;;
11 ;;; 8sync 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
14 ;;; GNU 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 8sync.  If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (tests test-rmeta-slot)
20   #:use-module (srfi srfi-64)
21   #:use-module (8sync rmeta-slot)
22   #:use-module (oop goops)
23   #:use-module (tests utils))
24
25 (test-begin "test-rmeta-slot")
26
27 ;; Define a class
28 (define-class <kah-lassy> ()
29   (entries #:allocation #:each-subclass
30            #:init-value
31            (make-rmeta-slot
32             `((foo . "bar")
33               (baz . "basil")))))
34
35 (test-equal "bar"
36     (class-rmeta-ref <kah-lassy> 'entries 'foo))
37 (test-equal "basil"
38     (class-rmeta-ref <kah-lassy> 'entries 'baz))
39
40 ;; Define a subclass
41
42 (define-class <sub-lassy> (<kah-lassy>)
43   (entries #:allocation #:each-subclass
44            #:init-value
45            (make-rmeta-slot
46             `((foo . "foo2")
47               (peanut . "gallery")))))
48
49 ;; Access values, and inheritance is preserved
50 (test-equal "foo2"
51   (class-rmeta-ref <sub-lassy> 'entries 'foo))
52 (test-equal "gallery"
53   (class-rmeta-ref <sub-lassy> 'entries 'peanut))
54 (test-equal "basil"
55   (class-rmeta-ref <sub-lassy> 'entries 'baz))
56
57 ;; Not defined
58 (test-equal #f
59   (class-rmeta-ref <sub-lassy> 'entries 'not-defined))
60 ;; Not defined, with default
61 (test-equal "no-way"
62   (class-rmeta-ref <sub-lassy> 'entries 'not-defined
63                    #:dflt "no-way"))
64
65 (test-end "test-rmeta-slot")
66 (test-exit)