print-structure.lsp 1.45 KB
Newer Older
pfdietz's avatar
pfdietz committed
1
2
3
4
5
6
7
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed May 26 22:19:52 2004
;;;; Contains: Printing tests for structures

(in-package :cl-test)

8

pfdietz's avatar
pfdietz committed
9
10
11
12
13
14
(defstruct print-struct-1
  foo bar)

(deftest print-structure.1
  (let ((s (make-print-struct-1 :foo 1 :bar 2)))
    (with-standard-io-syntax
15
      (let ((*tst-pkg* (find-package "CL-TEST"))
16
            (*kwd-pkg* (find-package "KEYWORD")))
pfdietz's avatar
pfdietz committed
17
       (let ((str (write-to-string s :readably nil :case :upcase :escape nil)))
sds's avatar
sds committed
18
19
20
21
22
         (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))
23
24
           (assert (symbolp (second vals)))
           (assert (symbolp (fourth vals)))
25
           (assert (eql *tst-pkg* (symbol-package (first vals))))
26
27
           (assert (eql *kwd-pkg* (symbol-package (second vals))))
           (assert (eql *kwd-pkg* (symbol-package (fourth vals))))
sds's avatar
sds committed
28
           (cond
29
30
31
32
            ((string= (symbol-name (second vals)) "FOO")
             (assert (string= (symbol-name (fourth vals)) "BAR"))
             (assert (= (third vals) 1))
             (assert (= (fifth vals) 2)))
sds's avatar
sds committed
33
            (t
34
35
36
37
             (assert (string= (symbol-name (second vals)) "BAR"))
             (assert (string= (symbol-name (fourth vals)) "FOO"))
             (assert (= (third vals) 2))
             (assert (= (fifth vals) 1))))
sds's avatar
sds committed
38
           nil)))))
pfdietz's avatar
pfdietz committed
39
  nil)