diff options
author | Ludovic Courtès <ludo@gnu.org> | 2012-02-03 16:35:06 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2012-02-03 16:35:06 +0100 |
commit | afd08fdf87caa499abf3423c663eb44be57cceb9 (patch) | |
tree | f461305f64808a40ad3a5120b33d54dd8f57a55c /test-suite/tests | |
parent | c76fdf69a833378ce18228d242e926009df9add1 (diff) | |
download | guile-afd08fdf87caa499abf3423c663eb44be57cceb9.tar.gz |
format: Add specifier ~h for localized number output.
* doc/ref/misc-modules.texi (Formatted Output): Document ~h. Recommend
use of ~h instead of ~:d.
* module/ice-9/format.scm (format): Add support for ~h.
* test-suite/tests/format.test ("~h localized number"): New test prefix.
* test-suite/tests/i18n.test (%american-english-locale-name,
%american-english-locale): New variables.
(under-american-english-locale-or-unresolved): New procedure.
("format ~h"): New test prefix.
Diffstat (limited to 'test-suite/tests')
-rw-r--r-- | test-suite/tests/format.test | 28 | ||||
-rw-r--r-- | test-suite/tests/i18n.test | 38 |
2 files changed, 62 insertions, 4 deletions
diff --git a/test-suite/tests/format.test b/test-suite/tests/format.test index 24ad8354c..a411b49e7 100644 --- a/test-suite/tests/format.test +++ b/test-suite/tests/format.test @@ -1,7 +1,7 @@ ;;;; 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, 2011 Free Software Foundation, Inc. +;;;; Copyright (C) 2001, 2003, 2004, 2006, 2010, 2011, 2012 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 @@ -19,6 +19,7 @@ (define-module (test-format) #:use-module (test-suite lib) + #:use-module (ice-9 i18n) #:use-module (ice-9 format)) @@ -97,6 +98,31 @@ (string=? "2.5" (format #f "~f" "02.5")))) ;;; +;;; ~h +;;; + +(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"))) + +;;; ;;; ~{ ;;; diff --git a/test-suite/tests/i18n.test b/test-suite/tests/i18n.test index f7824d39b..335f45017 100644 --- a/test-suite/tests/i18n.test +++ b/test-suite/tests/i18n.test @@ -18,9 +18,10 @@ ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA (define-module (test-suite i18n) - :use-module (ice-9 i18n) - :use-module (srfi srfi-1) - :use-module (test-suite lib)) + #:use-module (ice-9 i18n) + #:use-module (ice-9 format) + #:use-module (srfi srfi-1) + #:use-module (test-suite lib)) ;; Start from a pristine locale state. (setlocale LC_ALL "C") @@ -94,6 +95,9 @@ (define %greek-utf8-locale-name "el_GR.UTF-8") +(define %american-english-locale-name + "en_US") + (define %french-locale (false-if-exception (make-locale (list LC_CTYPE LC_COLLATE LC_NUMERIC LC_TIME) @@ -119,6 +123,11 @@ (make-locale LC_ALL %turkish-utf8-locale-name))) +(define %american-english-locale + (false-if-exception + (make-locale LC_ALL + %american-english-locale-name))) + (define (under-locale-or-unresolved locale thunk) ;; On non-GNU systems, an exception may be raised only when the locale is ;; actually used rather than at `make-locale'-time. Thus, we must guard @@ -153,6 +162,10 @@ (define (under-greek-utf8-locale-or-unresolved thunk) (under-locale-or-unresolved %greek-utf8-locale thunk)) +(define (under-american-english-locale-or-unresolved thunk) + (under-locale-or-unresolved %american-english-locale thunk)) + + (with-test-prefix "text collation (French)" (pass-if "string-locale<?" @@ -480,6 +493,25 @@ (string=? "1 234,5" (number->locale-string 1234.567 1 fr)))))))) +(with-test-prefix "format ~h" + + (with-test-prefix "French" + + (pass-if "12345.5678" + (under-french-locale-or-unresolved + (lambda () + (string=? "12 345,6789" + (format #f "~:h" 12345.6789 %french-locale)))))) + + (with-test-prefix "English" + + (pass-if "12345.5678" + (under-american-english-locale-or-unresolved + (lambda () + (string=? "12,345.6789" + (format #f "~:h" 12345.6789 + %american-english-locale))))))) + (with-test-prefix "monetary-amount->locale-string" (with-test-prefix "French" |