1 ;;;; format.test --- test suite for Guile's CL-ish format -*- scheme -*-
2 ;;;; Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de> --- June 2001
4 ;;;; Copyright (C) 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
6 ;;;; This library is free software; you can redistribute it and/or
7 ;;;; modify it under the terms of the GNU Lesser General Public
8 ;;;; License as published by the Free Software Foundation; either
9 ;;;; version 3 of the License, or (at your option) any later version.
11 ;;;; This library is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;;; Lesser General Public License for more details.
16 ;;;; You should have received a copy of the GNU Lesser General Public
17 ;;;; License along with this library; if not, write to the Free Software
18 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 (define-module (test-format)
21 #:use-module (test-suite lib)
22 #:use-module (ice-9 format))
25 ;;; FORMAT Basic Output
27 (with-test-prefix "format basic output"
28 (pass-if "format ~% produces a new line"
29 (string=? (format "~%") "\n"))
30 (pass-if "format ~& starts a fresh line"
31 (string=? (format "~&abc~&~&") "abc\n"))
32 (pass-if "format ~& is stateless but works properly across outputs via port-column"
34 (with-output-to-string
38 (format #f "~&") ; shall have no effect
41 (pass-if "format ~F (format-out-substr) maintains the column correctly"
42 (= (string-length (format "~@F~20T" 1)) 20)))
48 (with-test-prefix "format"
50 ;; in guile 1.6.4 and earlier, excess arguments were an error, but this
51 ;; changed to follow the common lisp spec
52 (pass-if "excess arguments ignored A"
53 (string=? (format #f "" 1 2 3 4) ""))
54 (pass-if "excess arguments ignored B"
55 (string=? (format #f "~a ~a" 1 2 3 4) "1 2")))
61 (with-test-prefix "~d decimal integer"
63 (with-test-prefix "~@d"
66 (string=? (format #f "~@d" -1) "-1"))
68 ;; in guile 1.6.4 and earlier, ~@d gave "0" but we think "+0" is what the
69 ;; common lisp spec intendes
71 (string=? (format #f "~@d" 0) "+0"))
74 (string=? (format #f "~@d" 1) "+1"))))
80 (with-test-prefix "~f fixed-point"
83 (string=? "1.5" (format #f "~f" 1.5)))
85 ;; in guile prior to 1.6.9 and 1.8.1, leading zeros were incorrectly
86 ;; stripped, moving the decimal point and giving "25.0" here
87 (pass-if "string 02.5"
88 (string=? "2.5" (format #f "~f" "02.5"))))
94 (with-test-prefix "~{ iteration"
96 ;; In Guile 1.6.4 and earlier, the maximum iterations parameter defaulted
97 ;; to 100, but it's now like Common Lisp where the default is no limit
98 (pass-if "no arbitrary iteration limit"
99 (= (string-length (format "~{~a~}" (make-list 200 #\b))) 200)))