mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-29 19:30:36 +02:00
* module/srfi/srfi-38.scm: New file, partly based on the reference implementation and on Alex Shinn's public-domain implementation for Chicken. * module/Makefile.am (SRFI_SOURCES): Add srfi/srfi-38.scm. * test-suite/tests/srfi-38.test: New file, minimal test suite for SRFI 38. * test-suite/Makefile.am (SCM_TESTS): Added tests/srfi-38.test. * doc/ref/srfi-modules.texi: Add a node for SRFI 38. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
68 lines
2.2 KiB
Scheme
68 lines
2.2 KiB
Scheme
;;; srfi-38.test --- Tests for SRFI 38. -*- mode: scheme; -*-
|
|
|
|
;; Copyright (C) 2010 Free Software Foundation, Inc.
|
|
|
|
;; This library 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.
|
|
|
|
;; This library 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 this library. If not, see
|
|
;; <http://www.gnu.org/licenses/>.
|
|
|
|
;;; Code:
|
|
|
|
(define-module (test-srfi-38)
|
|
#:use-module (test-suite lib)
|
|
#:use-module (srfi srfi-38)
|
|
#:use-module (rnrs bytevectors))
|
|
|
|
(define (shared-structure->string object)
|
|
(call-with-output-string
|
|
(lambda (port)
|
|
(write-with-shared-structure object port))))
|
|
|
|
(define (roundtrip object)
|
|
(call-with-input-string (shared-structure->string object)
|
|
(lambda (port)
|
|
(read-with-shared-structure port))))
|
|
|
|
(with-test-prefix "pairs"
|
|
(let ((foo (cons 'value-1 #f)))
|
|
(set-cdr! foo foo)
|
|
(pass-if "writing"
|
|
(string=? "#1=(value-1 . #1#)"
|
|
(shared-structure->string foo)))
|
|
(pass-if "roundtrip"
|
|
(let ((result (roundtrip foo)))
|
|
(and (pair? result)
|
|
(eq? (car result) 'value-1)
|
|
(eq? (cdr result) result))))))
|
|
|
|
(with-test-prefix "bytevectors"
|
|
(let ((vec (vector 0 1 2 3))
|
|
(bv (u8-list->bytevector '(42 42))))
|
|
(vector-set! vec 0 bv)
|
|
(vector-set! vec 2 bv)
|
|
(pass-if "roundtrip"
|
|
(let ((result (roundtrip vec)))
|
|
(and (equal? '#(#vu8(42 42) 1 #vu8(42 42) 3)
|
|
result)
|
|
(eq? (vector-ref result 0)
|
|
(vector-ref result 2)))))))
|
|
|
|
(with-test-prefix "mixed"
|
|
(let* ((pair (cons 'a 'b))
|
|
(vec (vector 0 pair 2 pair #f)))
|
|
(vector-set! vec 4 vec)
|
|
(pass-if "roundtrip"
|
|
(let ((result (roundtrip vec)))
|
|
(and (eq? (vector-ref result 1)
|
|
(vector-ref result 3))
|
|
(eq? result (vector-ref result 4)))))))
|