format-percent.lsp 1.88 KB
Newer Older
1 2 3 4 5 6
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Jul 27 23:47:44 2004
;;;; Contains: Tests of format with ~% directive

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

9 10
(def-format-test format.%.1
  "~%" nil #.(string #\Newline))
11 12 13

(deftest format.%.2
  (loop for i from 0 to 100
sds's avatar
sds committed
14 15 16 17 18 19 20
        for s1 = (make-string i :initial-element #\Newline)
        for format-string = (format nil "~~~D%" i)
        for s2 = (format nil format-string)
        for fn = (eval `(formatter ,s2))
        for s3 = (formatter-call-to-string fn)
        unless (and (string= s1 s2) (string= s1 s3))
        collect i)
21 22
  nil)

23 24
(def-format-test format.%.3
  "~v%" (nil) #.(string #\Newline))
25

26 27
(def-format-test format.%.4
  "~V%" (1) #.(string #\Newline))
28 29 30

(deftest format.%.5
  (loop for i from 0 to 100
sds's avatar
sds committed
31 32 33 34
        for s1 = (make-string i :initial-element #\Newline)
        for s2 = (format nil "~v%" i)
        unless (string= s1 s2)
        collect i)
35 36
  nil)

37 38 39
(deftest formatter.%.5
  (let ((fn (formatter "~v%")))
    (loop for i from 0 to 100
sds's avatar
sds committed
40 41 42 43
          for s1 = (make-string i :initial-element #\Newline)
          for s2 = (formatter-call-to-string fn i)
          unless (string= s1 s2)
          collect i))
44 45
  nil)

46 47
(deftest format.%.6
  (loop for i from 0 to (min (- call-arguments-limit 3) 100)
sds's avatar
sds committed
48 49 50 51 52
        for args = (make-list i)
        for s1 = (make-string i :initial-element #\Newline)
        for s2 = (apply #'format nil "~#%" args)
        unless (string= s1 s2)
        collect i)
53
  nil)
54 55 56 57

(deftest formatter.%.6
  (let ((fn (formatter "~#%")))
    (loop for i from 0 to (min (- call-arguments-limit 3) 100)
sds's avatar
sds committed
58 59 60 61 62 63 64
          for args = (make-list i)
          for s1 = (make-string i :initial-element #\Newline)
          for s2 = (with-output-to-string
                     (stream)
                     (assert (equal (apply fn stream args) args)))
          unless (string= s1 s2)
          collect i))
65
  nil)