Merge branch 'boehm-demers-weiser-gc' into bdw-gc-static-alloc
[bpt/guile.git] / test-suite / tests / format.test
1 ;;;; format.test --- test suite for Guile's CL-ish format -*- scheme -*-
2 ;;;; Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de> --- June 2001
3 ;;;;
4 ;;;; Copyright (C) 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
5 ;;;;
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.
10 ;;;;
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.
15 ;;;;
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
19
20 (define-module (test-format)
21 #:use-module (test-suite lib)
22 #:use-module (ice-9 format))
23
24
25 ;;; FORMAT Basic Output
26
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"
33 (string=?
34 (with-output-to-string
35 (lambda ()
36 (display "xyz")
37 (format #t "~&abc")
38 (format #f "~&") ; shall have no effect
39 (format #t "~&~&")))
40 "xyz\nabc\n"))
41 (pass-if "format ~F (format-out-substr) maintains the column correctly"
42 (= (string-length (format "~@F~20T" 1)) 20)))
43
44 ;;;
45 ;;; misc
46 ;;;
47
48 (with-test-prefix "format"
49
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")))
56
57 ;;;
58 ;;; ~d
59 ;;;
60
61 (with-test-prefix "~d decimal integer"
62
63 (with-test-prefix "~@d"
64
65 (pass-if "-1"
66 (string=? (format #f "~@d" -1) "-1"))
67
68 ;; in guile 1.6.4 and earlier, ~@d gave "0" but we think "+0" is what the
69 ;; common lisp spec intendes
70 (pass-if "+0"
71 (string=? (format #f "~@d" 0) "+0"))
72
73 (pass-if "+1"
74 (string=? (format #f "~@d" 1) "+1"))))
75
76 ;;;
77 ;;; ~f
78 ;;;
79
80 (with-test-prefix "~f fixed-point"
81
82 (pass-if "1.5"
83 (string=? "1.5" (format #f "~f" 1.5)))
84
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"))))
89
90 ;;;
91 ;;; ~{
92 ;;;
93
94 (with-test-prefix "~{ iteration"
95
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)))