GOOPS cosmetics
[bpt/guile.git] / test-suite / tests / format.test
index 25f98f4..cc31942 100644 (file)
@@ -1,30 +1,54 @@
 ;;;; format.test --- test suite for Guile's CL-ish format  -*- scheme -*-
 ;;;; Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de> --- June 2001
 ;;;;
-;;;;   Copyright (C) 2001, 2003, 2004, 2006, 2010 Free Software Foundation, Inc.
-;;;; 
+;;;; Copyright (C) 2001, 2003, 2004, 2006, 2010, 2011, 2012,
+;;;;   2014 Free Software Foundation, Inc.
+;;;;
 ;;;; This library is free software; you can redistribute it and/or
 ;;;; modify it under the terms of the GNU Lesser General Public
 ;;;; License as published by the Free Software Foundation; either
 ;;;; version 3 of the License, or (at your option) any later version.
-;;;; 
+;;;;
 ;;;; This library is distributed in the hope that it will be useful,
 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 ;;;; Lesser General Public License for more details.
-;;;; 
+;;;;
 ;;;; You should have received a copy of the GNU Lesser General Public
 ;;;; License along with this library; if not, write to the Free Software
 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 (define-module (test-format)
   #:use-module (test-suite lib)
+  #:use-module (ice-9 i18n)
   #:use-module (ice-9 format))
 
 
+(with-test-prefix "simple-format"
+  (pass-if-exception "current-output-port is closed"
+      exception:wrong-type-arg
+    ;; This used to segfault in Guile <= 2.0.10.
+    (let ((old (current-output-port))
+          (new (%make-void-port "w")))
+      (dynamic-wind
+        (lambda ()
+          (set-current-output-port new)
+          (close-port new))
+        (lambda ()
+          (simple-format #t "hello, closed port!")
+          #t)
+        (lambda ()
+          (set-current-output-port old))))))
+
 ;;; FORMAT Basic Output
 
 (with-test-prefix "format basic output"
+  (pass-if "default to Unicode-capable port"
+    ;; `(format #f ...)' should be able to deal with Unicode characters.
+    (with-fluids ((%default-port-encoding "ISO-8859-1"))
+      (let ((alpha (integer->char #x03b1)))  ; GREEK SMALL LETTER ALPHA
+        (= 1 (string-length (format #f (string alpha)))))))
+
   (pass-if "format ~% produces a new line"
           (string=? (format #f "~%") "\n"))
   (pass-if "format ~& starts a fresh line"
   (pass-if "string 02.5"
     (string=? "2.5" (format #f "~f" "02.5"))))
 
+;;;
+;;; ~h
+;;;
+
+(when (defined? 'setlocale)
+  (setlocale LC_ALL "C"))
+
+(with-test-prefix "~h localized number"
+
+  (pass-if "1234.5"
+    (string=? (format #f "~h" 1234.5) "1234.5"))
+
+  (pass-if "padding"
+    (string=? (format #f "~6h" 123.2) " 123.2"))
+
+  (pass-if "padchar"
+    (string=? (format #f "~8,,'*h" 123.2) "***123.2"))
+
+  (pass-if "decimals"
+    (string=? (format #f "~,2h" 123.4567)
+              "123.45"))
+
+  (pass-if "locale"
+    (string=? (format #f "~,3:h, ~a" 1234.5678
+                      %global-locale "approximately")
+              "1234.567, approximately")))
+
 ;;;
 ;;; ~{
 ;;;