set-macro-character.lsp 2.06 KB
Newer Older
pfdietz's avatar
pfdietz committed
1
2
3
4
5
6
7
8
9
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Jan  3 10:37:16 2005
;;;; Contains: Tests of SET-MACRO-CHARACTER

(in-package :cl-test)

(def-syntax-test set-macro-character.1
  (let ((*readtable* (copy-readtable))
sds's avatar
sds committed
10
        (*package* (find-package :cl-test)))
pfdietz's avatar
pfdietz committed
11
12
13
    (let ((v1 (read-from-string "?!")))
      (assert (eql v1 '?!))
      (flet ((%f (stream char)
sds's avatar
sds committed
14
15
16
17
18
19
20
21
22
23
                 (declare (ignore stream))
                 (assert (eql char #\?))
                 17))
        (let ((fn #'%f))
          (assert (equal (multiple-value-list
                          (set-macro-character #\? fn nil))
                         '(t)))
          (values
           (multiple-value-list (read-from-string "?!"))
           (multiple-value-list (read-from-string "!?")))))))
pfdietz's avatar
pfdietz committed
24
25
26
27
28
  (17 1)
  (! 1))

(def-syntax-test set-macro-character.2
  (let ((rt (copy-readtable))
sds's avatar
sds committed
29
        (*package* (find-package :cl-test)))
pfdietz's avatar
pfdietz committed
30
31
32
    (let ((v1 (read-from-string "?!")))
      (assert (eql v1 '?!))
      (flet ((%f (stream char)
sds's avatar
sds committed
33
34
35
36
37
38
39
40
41
42
43
                 (declare (ignore stream))
                 (assert (eql char #\?))
                 17))
        (let ((fn #'%f))
          (assert (equal (multiple-value-list
                          (set-macro-character #\? fn t rt))
                         '(t)))
          (let ((*readtable* rt))
            (values
             (multiple-value-list (read-from-string "?!"))
             (multiple-value-list (read-from-string "!?"))))))))
pfdietz's avatar
pfdietz committed
44
45
46
47
48
49
50
51
52
53
  (17 1)
  (!? 2))

(defun set-macro-character.3-test-fn (stream char)
  (declare (ignore stream))
  (assert (eql char #\?))
  :foo)

(def-syntax-test set-macro-character.3
  (let ((*readtable* (copy-readtable))
sds's avatar
sds committed
54
        (*package* (find-package :cl-test)))
pfdietz's avatar
pfdietz committed
55
    (let ((v1 (read-from-string "?!"))
sds's avatar
sds committed
56
          (fn 'set-macro-character.3-test-fn))
pfdietz's avatar
pfdietz committed
57
58
      (assert (eql v1 '?!))
      (assert (equal (multiple-value-list
sds's avatar
sds committed
59
60
                      (set-macro-character #\? fn nil))
                     '(t)))
pfdietz's avatar
pfdietz committed
61
62
63
64
65
      (values
       (multiple-value-list (read-from-string "?!"))
       (multiple-value-list (read-from-string "!?")))))
  (:foo 1)
  (! 1))