Commit | Line | Data |
---|---|---|
025f75b4 MV |
1 | ;;;; format.test --- test suite for Guile's CL-ish format -*- scheme -*- |
2 | ;;;; Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de> --- June 2001 | |
3 | ;;;; | |
1497e87a LC |
4 | ;;;; Copyright (C) 2001, 2003, 2004, 2006, 2010, 2011 Free Software Foundation, Inc. |
5 | ;;;; | |
53befeb7 NJ |
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. | |
1497e87a | 10 | ;;;; |
53befeb7 | 11 | ;;;; This library is distributed in the hope that it will be useful, |
025f75b4 | 12 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
53befeb7 NJ |
13 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | ;;;; Lesser General Public License for more details. | |
1497e87a | 15 | ;;;; |
53befeb7 NJ |
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 | |
025f75b4 | 19 | |
8ab3d8a0 KR |
20 | (define-module (test-format) |
21 | #:use-module (test-suite lib) | |
22 | #:use-module (ice-9 format)) | |
23 | ||
025f75b4 MV |
24 | |
25 | ;;; FORMAT Basic Output | |
26 | ||
27 | (with-test-prefix "format basic output" | |
1497e87a LC |
28 | (pass-if "default to Unicode-capable port" |
29 | ;; `(format #f ...)' should be able to deal with Unicode characters. | |
30 | (with-fluids ((%default-port-encoding "ISO-8859-1")) | |
31 | (let ((alpha (integer->char #x03b1))) ; GREEK SMALL LETTER ALPHA | |
32 | (= 1 (string-length (format #f (string alpha))))))) | |
33 | ||
025f75b4 | 34 | (pass-if "format ~% produces a new line" |
2ce77e6c | 35 | (string=? (format #f "~%") "\n")) |
025f75b4 | 36 | (pass-if "format ~& starts a fresh line" |
2ce77e6c | 37 | (string=? (format #f "~&abc~&~&") "abc\n")) |
025f75b4 MV |
38 | (pass-if "format ~& is stateless but works properly across outputs via port-column" |
39 | (string=? | |
40 | (with-output-to-string | |
41 | (lambda () | |
42 | (display "xyz") | |
43 | (format #t "~&abc") | |
44 | (format #f "~&") ; shall have no effect | |
45 | (format #t "~&~&"))) | |
6c61859f MV |
46 | "xyz\nabc\n")) |
47 | (pass-if "format ~F (format-out-substr) maintains the column correctly" | |
2ce77e6c | 48 | (= (string-length (format #f "~@F~20T" 1)) 20))) |
4fb31801 | 49 | |
d8b189d2 KR |
50 | ;;; |
51 | ;;; misc | |
52 | ;;; | |
53 | ||
54 | (with-test-prefix "format" | |
55 | ||
56 | ;; in guile 1.6.4 and earlier, excess arguments were an error, but this | |
57 | ;; changed to follow the common lisp spec | |
58 | (pass-if "excess arguments ignored A" | |
59 | (string=? (format #f "" 1 2 3 4) "")) | |
60 | (pass-if "excess arguments ignored B" | |
61 | (string=? (format #f "~a ~a" 1 2 3 4) "1 2"))) | |
62 | ||
992b375d KR |
63 | ;;; |
64 | ;;; ~d | |
65 | ;;; | |
66 | ||
67 | (with-test-prefix "~d decimal integer" | |
68 | ||
69 | (with-test-prefix "~@d" | |
70 | ||
71 | (pass-if "-1" | |
72 | (string=? (format #f "~@d" -1) "-1")) | |
d8b189d2 | 73 | |
992b375d KR |
74 | ;; in guile 1.6.4 and earlier, ~@d gave "0" but we think "+0" is what the |
75 | ;; common lisp spec intendes | |
76 | (pass-if "+0" | |
77 | (string=? (format #f "~@d" 0) "+0")) | |
78 | ||
79 | (pass-if "+1" | |
80 | (string=? (format #f "~@d" 1) "+1")))) | |
81 | ||
8ab3d8a0 KR |
82 | ;;; |
83 | ;;; ~f | |
84 | ;;; | |
85 | ||
86 | (with-test-prefix "~f fixed-point" | |
87 | ||
88 | (pass-if "1.5" | |
89 | (string=? "1.5" (format #f "~f" 1.5))) | |
90 | ||
625b43ac AW |
91 | (pass-if "3/2" |
92 | (string=? "1.5" (format #f "~f" 3/2))) | |
93 | ||
8ab3d8a0 KR |
94 | ;; in guile prior to 1.6.9 and 1.8.1, leading zeros were incorrectly |
95 | ;; stripped, moving the decimal point and giving "25.0" here | |
96 | (pass-if "string 02.5" | |
97 | (string=? "2.5" (format #f "~f" "02.5")))) | |
98 | ||
4fb31801 KR |
99 | ;;; |
100 | ;;; ~{ | |
101 | ;;; | |
102 | ||
103 | (with-test-prefix "~{ iteration" | |
104 | ||
105 | ;; In Guile 1.6.4 and earlier, the maximum iterations parameter defaulted | |
106 | ;; to 100, but it's now like Common Lisp where the default is no limit | |
107 | (pass-if "no arbitrary iteration limit" | |
2ce77e6c | 108 | (= (string-length (format #f "~{~a~}" (make-list 200 #\b))) 200))) |