Add `number->locale-string' tests.
authorLudovic Courtès <ludo@gnu.org>
Fri, 6 Aug 2010 13:36:51 +0000 (15:36 +0200)
committerLudovic Courtès <ludo@gnu.org>
Sun, 15 Aug 2010 14:43:39 +0000 (16:43 +0200)
* test-suite/tests/i18n.test ("number->locale-string"): New test prefix.

test-suite/tests/i18n.test

index 1cb48e7..f0c9757 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; i18n.test --- Exercise the i18n API.  -*- coding: utf-8; mode: scheme; -*-
 ;;;;
-;;;; Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc.
+;;;; Copyright (C) 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
 ;;;; Ludovic Courtès
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
                     (string-ci=? result "Tuesday"))))
            (lambda ()
              (setlocale LC_ALL "C")))))))
+
+\f
+;;;
+;;; Numbers.
+;;;
+
+(with-test-prefix "number->locale-string"
+
+  ;; We assume the global locale is "C" at this point.
+
+  (with-test-prefix "C"
+
+    (pass-if "no thousand separator"
+      ;; Unlike in English, the "C" locale has no thousand separator.
+      ;; If this doesn't hold, the following tests will fail.
+      (string=? "" (locale-thousands-separator)))
+
+    (pass-if "integer"
+      (string=? "123456" (number->locale-string 123456)))
+
+    (pass-if "fraction"
+      (string=? "1234.567" (number->locale-string 1234.567)))
+
+    (pass-if "fraction, 1 digit"
+      (string=? "1234.5" (number->locale-string 1234.567 1))))
+
+  (with-test-prefix "French"
+
+    (under-french-locale-or-unresolved
+     (lambda ()
+       (let ((fr (make-locale LC_ALL %french-locale-name)))
+
+        (pass-if "integer"
+          (string=? "123 456" (number->locale-string 123456 #t fr)))
+
+        (pass-if "fraction"
+          (string=? "1 234,567" (number->locale-string 1234.567 #t fr)))
+
+        (pass-if "fraction, 1 digit"
+          (string=? "1 234,5"
+                    (number->locale-string 1234.567 1 fr))))))))