X-Git-Url: https://jxself.org/git/?p=8sync.git;a=blobdiff_plain;f=tests%2Ftest-rmeta-slot.scm;fp=tests%2Ftest-rmeta-slot.scm;h=0fd4b6f99c7952e05d00351475a8e8084505c80b;hp=0000000000000000000000000000000000000000;hb=41b32934e39cb7b778e12bf8c61630acc38d2a72;hpb=f0c6e9e653ca414cf881296cc9511cd7d404c797 diff --git a/tests/test-rmeta-slot.scm b/tests/test-rmeta-slot.scm new file mode 100644 index 0000000..0fd4b6f --- /dev/null +++ b/tests/test-rmeta-slot.scm @@ -0,0 +1,66 @@ +;;; 8sync --- Asynchronous programming for Guile +;;; Copyright (C) 2017 Christopher Allan Webber +;;; +;;; This file is part of 8sync. +;;; +;;; 8sync is free software: you can redistribute it and/or modify it +;;; under the terms of the GNU Lesser General Public License as +;;; published by the Free Software Foundation, either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; 8sync 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 Lesser General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public +;;; License along with 8sync. If not, see . + +(define-module (tests test-rmeta-slot) + #:use-module (srfi srfi-64) + #:use-module (8sync rmeta-slot) + #:use-module (oop goops) + #:use-module (tests utils)) + +(test-begin "test-rmeta-slot") + +;; Define a class +(define-class () + (entries #:allocation #:each-subclass + #:init-value + (make-rmeta-slot + `((foo . "bar") + (baz . "basil"))))) + +(test-equal "bar" + (class-rmeta-ref 'entries 'foo)) +(test-equal "basil" + (class-rmeta-ref 'entries 'baz)) + +;; Define a subclass + +(define-class () + (entries #:allocation #:each-subclass + #:init-value + (make-rmeta-slot + `((foo . "foo2") + (peanut . "gallery"))))) + +;; Access values, and inheritance is preserved +(test-equal "foo2" + (class-rmeta-ref 'entries 'foo)) +(test-equal "gallery" + (class-rmeta-ref 'entries 'peanut)) +(test-equal "basil" + (class-rmeta-ref 'entries 'baz)) + +;; Not defined +(test-equal #f + (class-rmeta-ref 'entries 'not-defined)) +;; Not defined, with default +(test-equal "no-way" + (class-rmeta-ref 'entries 'not-defined + #:dflt "no-way")) + +(test-end "test-rmeta-slot") +(test-exit)