print-structure.lsp 1.25 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed May 26 22:19:52 2004
;;;; Contains: Printing tests for structures

(in-package :cl-test)

(compile-and-load "printer-aux.lsp")

(defstruct print-struct-1
  foo bar)

(deftest print-structure.1
  (let ((s (make-print-struct-1 :foo 1 :bar 2)))
    (with-standard-io-syntax
     (let ((*package* (find-package "CL-TEST")))
       (let ((str (write-to-string s :readably nil :case :upcase :escape nil)))
sds's avatar
sds committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
         (assert (string= (subseq str 0 3) "#S("))
         (let ((vals (read-from-string (subseq str 2))))
           (assert (listp vals))
           (assert (= (length vals) 5))
           (assert (eq (car vals) 'print-struct-1))
           (assert (symbolp (cadr vals)))
           (assert (symbolp (cadddr vals)))
           (cond
            ((string= (symbol-name (cadr vals)) "FOO")
             (assert (string= (symbol-name (cadddr vals)) "BAR"))
             (assert (= (caddr vals) 1))
             (assert (= (car (cddddr vals)) 2)))
            (t
             (assert (string= (symbol-name (cadr vals)) "BAR"))
             (assert (string= (symbol-name (cadddr vals)) "FOO"))
             (assert (= (caddr vals) 2))
             (assert (= (car (cddddr vals)) 1))))
           nil)))))
pfdietz's avatar
pfdietz committed
36
  nil)