format-tilde.lsp 2 KB
Newer Older
1 2 3 4 5 6
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed Jul 28 00:27:00 2004
;;;; Contains: Tests of format directive ~~

(in-package :cl-test)
7
(compile-and-load "printer-aux.lsp")
8

9 10
(def-format-test format.~.1
  "~~" nil "~")
11 12 13

(deftest format.~.2
  (loop for i from 0 to 100
sds's avatar
sds committed
14 15 16 17 18
        for s = (make-string i :initial-element #\~)
        for format-string = (format nil "~~~D~~" i)
        for s2 = (format nil format-string)
        unless (string= s s2)
        collect (list i s s2))
19 20 21 22
  nil)

(deftest formatter.~.2
  (loop for i from 0 to 100
sds's avatar
sds committed
23 24 25 26 27 28
        for s = (make-string i :initial-element #\~)
        for format-string = (format nil "~~~D~~" i)
        for fn = (eval `(formatter ,format-string))
        for s2 = (formatter-call-to-string fn)
        unless (string= s s2)
        collect (list i s s2))
29 30
  nil)

31 32
(def-format-test format.~.3
  "~v~" (0) "")
33 34 35

(deftest format.~.4
  (loop for i from 0 to 100
sds's avatar
sds committed
36 37 38 39
        for s = (make-string i :initial-element #\~)
        for s2 = (format nil "~V~" i)
        unless (string= s s2)
        collect (list i s s2))
40 41
  nil)

42 43 44
(deftest formatter.~.4
  (let ((fn (formatter "~v~")))
    (loop for i from 0 to 100
sds's avatar
sds committed
45 46 47 48
          for s = (make-string i :initial-element #\~)
          for s2 = (formatter-call-to-string fn i)
          unless (string= s s2)
          collect (list i s s2)))
49 50
  nil)

51 52
(deftest format.~.5
  (loop for i from 0 to (min (- call-arguments-limit 3) 100)
sds's avatar
sds committed
53 54 55 56 57
        for s = (make-string i :initial-element #\~)
        for args = (make-list i)
        for s2 = (apply #'format nil "~#~" args)
        unless (string= s s2)
        collect (list i s s2))
58
  nil)
59 60 61 62

(deftest formatter.~.5
  (let ((fn (formatter "~#~")))
    (loop for i from 0 to (min (- call-arguments-limit 3) 100)
sds's avatar
sds committed
63 64 65 66 67 68 69
          for s = (make-string i :initial-element #\~)
          for args = (make-list i)
          for s2 = (with-output-to-string
                     (stream)
                     (assert (equal (apply fn stream args) args)))
          unless (string= s s2)
          collect (list i s s2)))
70
  nil)