encoding-iso88597.test 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. ;;;; encoding-iso88697.test --- test suite for Guile's string encodings -*- mode: scheme; coding: iso-8859-7 -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2009, 2010, 2014 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This library is free software; you can redistribute it and/or
  6. ;;;; modify it under the terms of the GNU Lesser General Public
  7. ;;;; License as published by the Free Software Foundation; either
  8. ;;;; version 3 of the License, or (at your option) any later version.
  9. ;;;;
  10. ;;;; This library is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ;;;; Lesser General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU Lesser General Public
  16. ;;;; License along with this library; if not, write to the Free Software
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. (define-module (test-strings)
  19. #:use-module (test-suite lib)
  20. #:use-module (srfi srfi-1))
  21. ;; Create a string from integer char values, eg. (string-ints 65) => "A"
  22. (define (string-ints . args)
  23. (apply string (map integer->char args)))
  24. (when (defined? 'setlocale)
  25. (setlocale LC_ALL ""))
  26. (define ascii-a (integer->char 65)) ; LATIN CAPITAL LETTER A
  27. (define a-acute (integer->char #x00c1)) ; LATIN CAPITAL LETTER A WITH ACUTE
  28. (define alpha (integer->char #x03b1)) ; GREEK SMALL LETTER ALPHA
  29. (define cherokee-a (integer->char #x13a0)) ; CHEROKEE LETTER A
  30. (with-test-prefix "characters"
  31. (pass-if "input A"
  32. (char=? ascii-a #\A))
  33. (pass-if "input alpha"
  34. (char=? alpha #\á))
  35. (pass-if "display A"
  36. (let ((pt (open-output-string)))
  37. (set-port-encoding! pt "ISO-8859-7")
  38. (set-port-conversion-strategy! pt 'escape)
  39. (display ascii-a pt)
  40. (string=? "A"
  41. (get-output-string pt))))
  42. (pass-if "display A acute"
  43. (let ((pt (open-output-string)))
  44. (set-port-encoding! pt "ISO-8859-7")
  45. (set-port-conversion-strategy! pt 'escape)
  46. (display a-acute pt)
  47. (string-ci=? "\\xc1"
  48. (get-output-string pt))))
  49. (pass-if "display alpha"
  50. (let ((pt (open-output-string)))
  51. (set-port-encoding! pt "ISO-8859-7")
  52. (set-port-conversion-strategy! pt 'escape)
  53. (display alpha pt)
  54. (string-ci=? "á"
  55. (get-output-string pt))))
  56. (pass-if "display Cherokee A"
  57. (let ((pt (open-output-string)))
  58. (set-port-encoding! pt "ISO-8859-7")
  59. (set-port-conversion-strategy! pt 'escape)
  60. (display cherokee-a pt)
  61. (string-ci=? "\\u13a0"
  62. (get-output-string pt))))
  63. (pass-if "write A"
  64. (let ((pt (open-output-string)))
  65. (set-port-encoding! pt "ISO-8859-7")
  66. (set-port-conversion-strategy! pt 'escape)
  67. (write ascii-a pt)
  68. (string=? "#\\A"
  69. (get-output-string pt))))
  70. (pass-if "write alpha"
  71. (let ((pt (open-output-string)))
  72. (set-port-encoding! pt "ISO-8859-7")
  73. (set-port-conversion-strategy! pt 'escape)
  74. (write alpha pt)
  75. (string=? "#\\á"
  76. (get-output-string pt)))))
  77. (define s1 "Ðåñß")
  78. (define s2 "ôçò")
  79. (define s3 "êñéôéêÞò")
  80. (define s4 "êáé")
  81. (with-test-prefix "string length"
  82. (pass-if "s1"
  83. (eqv? (string-length s1) 4))
  84. (pass-if "s2"
  85. (eqv? (string-length s2) 3))
  86. (pass-if "s3"
  87. (eqv? (string-length s3) 8))
  88. (pass-if "s4"
  89. (eqv? (string-length s4) 3)))
  90. (with-test-prefix "internal encoding"
  91. (pass-if "s1"
  92. (string=? s1 (string-ints #x03a0 #x03b5 #x03c1 #x03af)))
  93. (pass-if "s2"
  94. (string=? s2 (string-ints #x03c4 #x03b7 #x03c2)))
  95. (pass-if "s3"
  96. (string=? s3 (string-ints #x03ba #x03c1 #x03b9 #x03c4 #x03b9 #x03ba #x03ae #x03c2)))
  97. (pass-if "s4"
  98. (string=? s4 (string-ints #x03ba #x03b1 #x03b9))))
  99. (with-test-prefix "chars"
  100. (pass-if "s1"
  101. (list= eqv? (string->list s1)
  102. (list #\Ð #\å #\ñ #\ß)))
  103. (pass-if "s2"
  104. (list= eqv? (string->list s2)
  105. (list #\ô #\ç #\ò)))
  106. (pass-if "s3"
  107. (list= eqv? (string->list s3)
  108. (list #\ê #\ñ #\é #\ô #\é #\ê #\Þ #\ò)))
  109. (pass-if "s4"
  110. (list= eqv? (string->list s4)
  111. (list #\ê #\á #\é))))
  112. (with-test-prefix "symbols == strings"
  113. (pass-if "Ðåñß"
  114. (eq? (string->symbol s1) 'Ðåñß))
  115. (pass-if "ôçò"
  116. (eq? (string->symbol s2) 'ôçò))
  117. (pass-if "êñéôéêÞò"
  118. (eq? (string->symbol s3) 'êñéôéêÞò))
  119. (pass-if "êáé"
  120. (eq? (string->symbol s4) 'êáé)))
  121. (with-test-prefix "non-ascii variable names"
  122. (pass-if "1"
  123. (let ((á 1)
  124. (ñ 2))
  125. (eqv? (+ á ñ) 3))))
  126. (with-test-prefix "output errors"
  127. (pass-if-exception "char #x0400"
  128. exception:encoding-error
  129. (let ((pt (open-output-string)))
  130. (set-port-encoding! pt "ISO-8859-7")
  131. (set-port-conversion-strategy! pt 'error)
  132. (display (string-ints #x0400) pt))))