diff options
author | Ludovic Courtès <ludo@gnu.org> | 2011-02-08 23:14:00 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2011-02-08 23:14:00 +0100 |
commit | 1497e87a4f2eb414dcb2fde306d98013067dd410 (patch) | |
tree | 02296bd0f38424346880cee3c376c1f78ea6e127 | |
parent | 05e0e22bc58ec4f1d2f96238c3d0c13770f7c5dc (diff) | |
download | guile-1497e87a4f2eb414dcb2fde306d98013067dd410.tar.gz |
Make `(format #f ...)' always Unicode-capable.
* module/ice-9/format.scm (format): When DESTINATION is #f, use a
Unicode-capable output string port.
* test-suite/tests/format.test ("format basic output")["default to
Unicode-capable port"]: New test.
-rw-r--r-- | module/ice-9/format.scm | 5 | ||||
-rw-r--r-- | test-suite/tests/format.test | 14 |
2 files changed, 14 insertions, 5 deletions
diff --git a/module/ice-9/format.scm b/module/ice-9/format.scm index 7cd018306..c62348d9f 100644 --- a/module/ice-9/format.scm +++ b/module/ice-9/format.scm @@ -41,7 +41,10 @@ (let* ((port (cond - ((not destination) (open-output-string)) + ((not destination) + ;; Use a Unicode-capable output string port. + (with-fluids ((%default-port-encoding "UTF-8")) + (open-output-string))) ((boolean? destination) (current-output-port)) ; boolean but not false ((output-port? destination) destination) ((number? destination) diff --git a/test-suite/tests/format.test b/test-suite/tests/format.test index 25f98f400..24ad8354c 100644 --- a/test-suite/tests/format.test +++ b/test-suite/tests/format.test @@ -1,18 +1,18 @@ ;;;; 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 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 @@ -25,6 +25,12 @@ ;;; 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" |