guile-srfi-123

guile-srfi-123 is an SRFI-123 implementation for Guile. (More on SRFI-123 on https://srfi.schemers.org/srfi-123/)
git clone https://kaka.farm/~git/guile-srfi-123
Log | Files | Refs

run-tests-goops.scm (5466B)


      1 ;;; run-tests-goops.scm --- Part of the guile-srfi-123 generic accessor and modifier operators library.
      2 
      3 ;; Copyright © 2025  Yuval Langer <yuval.langer@gmail.com>
      4 ;; Copyright © 2015  Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com>
      5 
      6 ;; This program is free software: you can redistribute it and/or modify
      7 ;; it under the terms of the GNU Affero 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 ;; This program 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 Affero General Public License for more details.
     15 
     16 ;; You should have received a copy of the GNU Affero General Public License
     17 ;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
     18 
     19 ;; Permission is hereby granted, free of charge, to any person obtaining
     20 ;; a copy of this software and associated documentation files (the
     21 ;; "Software"), to deal in the Software without restriction, including
     22 ;; without limitation the rights to use, copy, modify, merge, publish,
     23 ;; distribute, sublicense, and/or sell copies of the Software, and to
     24 ;; permit persons to whom the Software is furnished to do so, subject to
     25 ;; the following conditions:
     26 
     27 ;; The above copyright notice and this permission notice shall be
     28 ;; included in all copies or substantial portions of the Software.
     29 
     30 ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     31 ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     32 ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     33 ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
     34 ;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     35 ;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     36 ;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     37 
     38 (use-modules
     39  ((scheme base) #:select (bytevector))
     40 
     41  (rnrs exceptions)
     42  (rnrs hashtables)
     43  (rnrs records inspection)
     44  (rnrs records procedural)
     45  (rnrs records syntactic)
     46 
     47  (srfi srfi-4)
     48  (srfi srfi-64)
     49  (srfi srfi-111)
     50  (srfi srfi-123 goops)
     51  )
     52 
     53 (define using-broken-srfi99 #f)
     54 
     55 (define-record-type foo
     56   (fields
     57    (mutable a)
     58    (immutable b))
     59   )
     60 
     61 (define (run-tests)
     62   (let ((runner (test-runner-create)))
     63     (parameterize ((test-runner-current runner))
     64       (test-begin "SRFI-123-GOOPS")
     65 
     66       (test-begin "ref")
     67       (test-assert "bytevector" (= 1 (ref (bytevector 0 1 2) 1)))
     68       (test-assert "hashtable" (let ((table (make-eqv-hashtable)))
     69                                  (hashtable-set! table 'foo 0)
     70                                  (= 0 (ref table 'foo))))
     71       (test-assert "hashtable default" (let ((table (make-eqv-hashtable)))
     72                                          (= 1 (ref table 0 1))))
     73       (test-assert "pair" (= 1 (ref (cons 0 1) 'cdr)))
     74       (test-assert "list" (= 1 (ref (list 0 1 2) 1)))
     75       (test-assert "string" (char=? #\b (ref "abc" 1)))
     76       (test-assert "vector" (= 1 (ref (vector 0 1 2) 1)))
     77       (test-assert "record" (= 1 (ref (make-foo 0 1) 'b)))
     78       (values)
     79       (test-assert "srfi-4" (= 1 (ref (s16vector 0 1 2) 1)))
     80       (values)
     81       (test-assert "srfi-111" (= 1 (ref (box 1) '*)))
     82       (test-end "ref")
     83 
     84       (test-assert "ref*" (= 1 (ref* '(_ #(_ (0 . 1) _) _) 1 1 'cdr)))
     85 
     86       (test-begin "ref setter")
     87       (test-assert "bytevector" (let ((bv (bytevector 0 1 2)))
     88                                   (set! (ref bv 1) 3)
     89                                   (= 3 (ref bv 1))))
     90       (test-assert "hashtable" (let ((ht (make-eqv-hashtable)))
     91                                  (set! (ref ht 'foo) 0)
     92                                  (= 0 (ref ht 'foo))))
     93       (test-assert "pair" (let ((p (cons 0 1)))
     94                             (set! (ref p 'cdr) 2)
     95                             (= 2 (ref p 'cdr))))
     96       (test-assert "list" (let ((l (list 0 1 2)))
     97                             (set! (ref l 1) 3)
     98                             (= 3 (ref l 1))))
     99       (test-assert "string" (let ((s (string #\a #\b #\c)))
    100                               (set! (ref s 1) #\d)
    101                               (char=? #\d (ref s 1))))
    102       (test-assert "vector" (let ((v (vector 0 1 2)))
    103                               (set! (ref v 1) 3)
    104                               (= 3 (ref v 1))))
    105       (test-assert "record" (let ((r (make-foo 0 1)))
    106                               (set! (ref r 'a) 2)
    107                               (= 2 (ref r 'a))))
    108       (when using-broken-srfi99
    109         (test-expect-fail 1))
    110       (test-assert "bad record assignment"
    111         (not (guard (err (else #f)) (set! (ref (make-foo 0 1) 'b) 2) #t)))
    112       (values)
    113       (test-assert "srfi-4" (let ((s16v (s16vector 0 1 2)))
    114                               (set! (ref s16v 1) 3)
    115                               (= 3 (ref s16v 1))))
    116       (values)
    117       (test-assert "srfi-111" (let ((b (box 0)))
    118                                 (set! (ref b '*) 1)
    119                                 (= 1 (ref b '*))))
    120       (test-end "ref setter")
    121 
    122       (test-assert "ref* setter"
    123         (let ((obj (list '_ (vector '_ (cons 0 1) '_) '_)))
    124           (set! (ref* obj 1 1 'cdr) 2)
    125           (= 2 (ref* obj 1 1 'cdr))))
    126 
    127       (test-end "SRFI-123-GOOPS")
    128       (and (= 0 (test-runner-xpass-count runner))
    129            (= 0 (test-runner-fail-count runner))))))
    130 
    131 (if (run-tests)
    132     (exit 0)
    133     (exit 1))