guix: Use guile-3.0.
[8sync.git] / tests / test-rmeta-slot.scm
1 ;;; 8sync --- Asynchronous programming for Guile
2 ;;; Copyright (C) 2017 Christopher Allan Webber <cwebber@dustycloud.org>
3 ;;; Copyright (C) 2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
4 ;;;
5 ;;; This file is part of 8sync.
6 ;;;
7 ;;; 8sync is free software: you can redistribute it and/or modify it
8 ;;; under the terms of the GNU Lesser General Public License as
9 ;;; published by the Free Software Foundation, either version 3 of the
10 ;;; License, or (at your option) any later version.
11 ;;;
12 ;;; 8sync is distributed in the hope that it will be useful,
13 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;;; GNU Lesser General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU Lesser General Public
18 ;;; License along with 8sync.  If not, see <http://www.gnu.org/licenses/>.
19
20 (define-module (tests test-rmeta-slot)
21   #:use-module (srfi srfi-64)
22   #:use-module (8sync rmeta-slot)
23   #:use-module (oop goops)
24   #:use-module (tests utils))
25
26 (test-begin "test-rmeta-slot")
27
28 ;; Define a class
29 (define-class <kah-lassy> ()
30   (entries #:allocation #:each-subclass
31            #:init-thunk
32            (build-rmeta-slot
33             `((foo . "bar")
34               (baz . "basil")))))
35
36 (test-equal "bar"
37     (class-rmeta-ref <kah-lassy> 'entries 'foo))
38 (test-equal "basil"
39     (class-rmeta-ref <kah-lassy> 'entries 'baz))
40
41 ;; Define a subclass
42
43 (define-class <sub-lassy> (<kah-lassy>)
44   (entries #:allocation #:each-subclass
45            #:init-thunk
46            (build-rmeta-slot
47             `((foo . "foo2")
48               (peanut . "gallery")))))
49
50 ;; Access values, and inheritance is preserved
51 (test-equal "foo2"
52   (class-rmeta-ref <sub-lassy> 'entries 'foo))
53 (test-equal "gallery"
54   (class-rmeta-ref <sub-lassy> 'entries 'peanut))
55 (test-equal "basil"
56   (class-rmeta-ref <sub-lassy> 'entries 'baz))
57
58 ;; Not defined
59 (test-equal #f
60   (class-rmeta-ref <sub-lassy> 'entries 'not-defined))
61 ;; Not defined, with default
62 (test-equal "no-way"
63   (class-rmeta-ref <sub-lassy> 'entries 'not-defined
64                    #:dflt "no-way"))
65
66 (test-exit)
67 (test-end "test-rmeta-slot")