format.test 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ;;;; format.test --- test suite for Guile's CL-ish format -*- scheme -*-
  2. ;;;; Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de> --- June 2001
  3. ;;;;
  4. ;;;; Copyright (C) 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
  5. ;;;;
  6. ;;;; This program is free software; you can redistribute it and/or modify
  7. ;;;; it under the terms of the GNU General Public License as published by
  8. ;;;; the Free Software Foundation; either version 2, or (at your option)
  9. ;;;; any later version.
  10. ;;;;
  11. ;;;; This program is distributed in the hope that it will be useful,
  12. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;;; GNU General Public License for more details.
  15. ;;;;
  16. ;;;; You should have received a copy of the GNU General Public License
  17. ;;;; along with this software; see the file COPYING. If not, write to
  18. ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. ;;;; Boston, MA 02110-1301 USA
  20. (define-module (test-format)
  21. #:use-module (test-suite lib)
  22. #:use-module (ice-9 format))
  23. ;;; FORMAT Basic Output
  24. (with-test-prefix "format basic output"
  25. (pass-if "format ~% produces a new line"
  26. (string=? (format "~%") "\n"))
  27. (pass-if "format ~& starts a fresh line"
  28. (string=? (format "~&abc~&~&") "abc\n"))
  29. (pass-if "format ~& is stateless but works properly across outputs via port-column"
  30. (string=?
  31. (with-output-to-string
  32. (lambda ()
  33. (display "xyz")
  34. (format #t "~&abc")
  35. (format #f "~&") ; shall have no effect
  36. (format #t "~&~&")))
  37. "xyz\nabc\n"))
  38. (pass-if "format ~F (format-out-substr) maintains the column correctly"
  39. (= (string-length (format "~@F~20T" 1)) 20)))
  40. ;;;
  41. ;;; misc
  42. ;;;
  43. (with-test-prefix "format"
  44. ;; in guile 1.6.4 and earlier, excess arguments were an error, but this
  45. ;; changed to follow the common lisp spec
  46. (pass-if "excess arguments ignored A"
  47. (string=? (format #f "" 1 2 3 4) ""))
  48. (pass-if "excess arguments ignored B"
  49. (string=? (format #f "~a ~a" 1 2 3 4) "1 2")))
  50. ;;;
  51. ;;; ~d
  52. ;;;
  53. (with-test-prefix "~d decimal integer"
  54. (with-test-prefix "~@d"
  55. (pass-if "-1"
  56. (string=? (format #f "~@d" -1) "-1"))
  57. ;; in guile 1.6.4 and earlier, ~@d gave "0" but we think "+0" is what the
  58. ;; common lisp spec intendes
  59. (pass-if "+0"
  60. (string=? (format #f "~@d" 0) "+0"))
  61. (pass-if "+1"
  62. (string=? (format #f "~@d" 1) "+1"))))
  63. ;;;
  64. ;;; ~f
  65. ;;;
  66. (with-test-prefix "~f fixed-point"
  67. (pass-if "1.5"
  68. (string=? "1.5" (format #f "~f" 1.5)))
  69. ;; in guile prior to 1.6.9 and 1.8.1, leading zeros were incorrectly
  70. ;; stripped, moving the decimal point and giving "25.0" here
  71. (pass-if "string 02.5"
  72. (string=? "2.5" (format #f "~f" "02.5"))))
  73. ;;;
  74. ;;; ~{
  75. ;;;
  76. (with-test-prefix "~{ iteration"
  77. ;; In Guile 1.6.4 and earlier, the maximum iterations parameter defaulted
  78. ;; to 100, but it's now like Common Lisp where the default is no limit
  79. (pass-if "no arbitrary iteration limit"
  80. (= (string-length (format "~{~a~}" (make-list 200 #\b))) 200)))