chars.test 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. ;;;; chars.test --- Characters. -*- coding: utf-8; mode: scheme; -*-
  2. ;;;; Greg J. Badros <gjb@cs.washington.edu>
  3. ;;;;
  4. ;;;; Copyright (C) 2000, 2006, 2009, 2010, 2013 Free Software Foundation, Inc.
  5. ;;;;
  6. ;;;; This library is free software; you can redistribute it and/or
  7. ;;;; modify it under the terms of the GNU Lesser General Public
  8. ;;;; License as published by the Free Software Foundation; either
  9. ;;;; version 3 of the License, or (at your option) any later version.
  10. ;;;;
  11. ;;;; This library 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 GNU
  14. ;;;; Lesser General Public License for more details.
  15. ;;;;
  16. ;;;; You should have received a copy of the GNU Lesser General Public
  17. ;;;; License along with this library; if not, write to the Free Software
  18. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. (use-modules (test-suite lib))
  20. (define exception:wrong-type-to-apply
  21. (cons 'misc-error "^Wrong type to apply:"))
  22. (define exception:unknown-character-name
  23. (cons #t "unknown character"))
  24. (define exception:out-of-range-octal
  25. (cons #t "out-of-range"))
  26. (with-test-prefix "basic char handling"
  27. (with-test-prefix "evaluator"
  28. ;; The following test makes sure that the evaluator distinguishes between
  29. ;; evaluator-internal instruction codes and characters.
  30. (pass-if-exception "evaluating chars"
  31. exception:wrong-type-arg
  32. (eval '(#\0) (interaction-environment))))
  33. (with-test-prefix "comparisons"
  34. ;; char=?
  35. (pass-if "char=? #\\A #\\A"
  36. (char=? #\A #\A))
  37. (pass-if "char=? #\\A #\\a"
  38. (not (char=? #\A #\a)))
  39. (pass-if "char=? #\\A #\\B"
  40. (not (char=? #\A #\B)))
  41. (pass-if "char=? #\\B #\\A"
  42. (not (char=? #\A #\B)))
  43. ;; char<?
  44. (pass-if "char<? #\\A #\\A"
  45. (not (char<? #\A #\A)))
  46. (pass-if "char<? #\\A #\\a"
  47. (char<? #\A #\a))
  48. (pass-if "char<? #\\A #\\B"
  49. (char<? #\A #\B))
  50. (pass-if "char<? #\\B #\\A"
  51. (not (char<? #\B #\A)))
  52. ;; char<=?
  53. (pass-if "char<=? #\\A #\\A"
  54. (char<=? #\A #\A))
  55. (pass-if "char<=? #\\A #\\a"
  56. (char<=? #\A #\a))
  57. (pass-if "char<=? #\\A #\\B"
  58. (char<=? #\A #\B))
  59. (pass-if "char<=? #\\B #\\A"
  60. (not (char<=? #\B #\A)))
  61. ;; char>?
  62. (pass-if "char>? #\\A #\\A"
  63. (not (char>? #\A #\A)))
  64. (pass-if "char>? #\\A #\\a"
  65. (not (char>? #\A #\a)))
  66. (pass-if "char>? #\\A #\\B"
  67. (not (char>? #\A #\B)))
  68. (pass-if "char>? #\\B #\\A"
  69. (char>? #\B #\A))
  70. ;; char>=?
  71. (pass-if "char>=? #\\A #\\A"
  72. (char>=? #\A #\A))
  73. (pass-if "char>=? #\\A #\\a"
  74. (not (char>=? #\A #\a)))
  75. (pass-if "char>=? #\\A #\\B"
  76. (not (char>=? #\A #\B)))
  77. (pass-if "char>=? #\\B #\\A"
  78. (char>=? #\B #\A))
  79. ;; char-ci=?
  80. (pass-if "char-ci=? #\\A #\\A"
  81. (char-ci=? #\A #\A))
  82. (pass-if "char-ci=? #\\A #\\a"
  83. (char-ci=? #\A #\a))
  84. (pass-if "char-ci=? #\\A #\\B"
  85. (not (char-ci=? #\A #\B)))
  86. (pass-if "char-ci=? #\\B #\\A"
  87. (not (char-ci=? #\A #\B)))
  88. ;; char-ci<?
  89. (pass-if "char-ci<? #\\A #\\A"
  90. (not (char-ci<? #\A #\A)))
  91. (pass-if "char-ci<? #\\A #\\a"
  92. (not (char-ci<? #\A #\a)))
  93. (pass-if "char-ci<? #\\A #\\B"
  94. (char-ci<? #\A #\B))
  95. (pass-if "char-ci<? #\\B #\\A"
  96. (not (char-ci<? #\B #\A)))
  97. ;; char-ci<=?
  98. (pass-if "char-ci<=? #\\A #\\A"
  99. (char-ci<=? #\A #\A))
  100. (pass-if "char-ci<=? #\\A #\\a"
  101. (char-ci<=? #\A #\a))
  102. (pass-if "char-ci<=? #\\A #\\B"
  103. (char-ci<=? #\A #\B))
  104. (pass-if "char-ci<=? #\\B #\\A"
  105. (not (char-ci<=? #\B #\A)))
  106. ;; char-ci>?
  107. (pass-if "char-ci>? #\\A #\\A"
  108. (not (char-ci>? #\A #\A)))
  109. (pass-if "char-ci>? #\\A #\\a"
  110. (not (char-ci>? #\A #\a)))
  111. (pass-if "char-ci>? #\\A #\\B"
  112. (not (char-ci>? #\A #\B)))
  113. (pass-if "char-ci>? #\\B #\\A"
  114. (char-ci>? #\B #\A))
  115. ;; char-ci>=?
  116. (pass-if "char-ci>=? #\\A #\\A"
  117. (char-ci>=? #\A #\A))
  118. (pass-if "char-ci>=? #\\A #\\a"
  119. (char-ci>=? #\A #\a))
  120. (pass-if "char-ci>=? #\\A #\\B"
  121. (not (char-ci>=? #\A #\B)))
  122. (pass-if "char-ci>=? #\\B #\\A"
  123. (char-ci>=? #\B #\A)))
  124. (with-test-prefix "categories"
  125. (pass-if "char-alphabetic?"
  126. (and (char-alphabetic? #\a)
  127. (char-alphabetic? #\A)
  128. (not (char-alphabetic? #\1))
  129. (not (char-alphabetic? #\+))))
  130. (pass-if "char-numeric?"
  131. (and (not (char-numeric? #\a))
  132. (not (char-numeric? #\A))
  133. (char-numeric? #\1)
  134. (not (char-numeric? #\+))))
  135. (pass-if "char-whitespace?"
  136. (and (not (char-whitespace? #\a))
  137. (not (char-whitespace? #\A))
  138. (not (char-whitespace? #\1))
  139. (char-whitespace? #\space)
  140. (not (char-whitespace? #\+))))
  141. (pass-if "char-upper-case?"
  142. (and (not (char-upper-case? #\a))
  143. (char-upper-case? #\A)
  144. (not (char-upper-case? #\1))
  145. (not (char-upper-case? #\+))))
  146. (pass-if "char-lower-case?"
  147. (and (char-lower-case? #\a)
  148. (not (char-lower-case? #\A))
  149. (not (char-lower-case? #\1))
  150. (not (char-lower-case? #\+))))
  151. (pass-if "char-is-both? works"
  152. (and
  153. (not (char-is-both? #\?))
  154. (not (char-is-both? #\newline))
  155. (char-is-both? #\a)
  156. (char-is-both? #\Z)
  157. (not (char-is-both? #\1))))
  158. (pass-if "char-general-category"
  159. (and (eq? (char-general-category #\a) 'Ll)
  160. (eq? (char-general-category #\A) 'Lu)
  161. (eq? (char-general-category #\762) 'Lt))))
  162. (with-test-prefix "integer"
  163. (pass-if "char->integer"
  164. (eqv? (char->integer #\A) 65))
  165. (pass-if "integer->char"
  166. (eqv? (integer->char 65) #\A))
  167. (pass-if-exception "integer->char out of range, -1" exception:out-of-range
  168. (integer->char -1))
  169. (pass-if-exception "integer->char out of range, surrrogate"
  170. exception:out-of-range
  171. (integer->char #xd800))
  172. (pass-if-exception "integer->char out of range, too big"
  173. exception:out-of-range
  174. (integer->char #x110000))
  175. (pass-if-exception "octal out of range, surrrogate"
  176. exception:out-of-range-octal
  177. (with-input-from-string "#\\154000" read))
  178. (pass-if-exception "octal out of range, too big"
  179. exception:out-of-range-octal
  180. (with-input-from-string "#\\4200000" read)))
  181. (with-test-prefix "case"
  182. (pass-if "char-upcase"
  183. (eqv? (char-upcase #\a) #\A))
  184. (pass-if "char-downcase"
  185. (eqv? (char-downcase #\A) #\a))
  186. (pass-if "char-titlecase"
  187. (and (eqv? (char-titlecase #\a) #\A)
  188. (eqv? (char-titlecase #\763) #\762))))
  189. (with-test-prefix "charnames"
  190. (pass-if "R5RS character names"
  191. (and (eqv? #\space (integer->char #x20))
  192. (eqv? #\newline (integer->char #x0A))))
  193. (pass-if "R6RS character names"
  194. (and (eqv? #\nul (integer->char #x00))
  195. (eqv? #\alarm (integer->char #x07))
  196. (eqv? #\backspace (integer->char #x08))
  197. (eqv? #\tab (integer->char #x09))
  198. (eqv? #\linefeed (integer->char #x0A))
  199. (eqv? #\newline (integer->char #x0A))
  200. (eqv? #\vtab (integer->char #x0B))
  201. (eqv? #\page (integer->char #x0C))
  202. (eqv? #\return (integer->char #x0D))
  203. (eqv? #\esc (integer->char #x1B))
  204. (eqv? #\space (integer->char #x20))
  205. (eqv? #\delete (integer->char #x7F))))
  206. (pass-if "R5RS character names are case insensitive"
  207. (and (eqv? #\space #\ )
  208. (eqv? #\SPACE #\ )
  209. (eqv? #\Space #\ )
  210. (eqv? #\newline (integer->char 10))
  211. (eqv? #\NEWLINE (integer->char 10))
  212. (eqv? #\Newline (integer->char 10))))
  213. (pass-if "C0 control names are case insensitive"
  214. (and (eqv? #\nul #\000)
  215. (eqv? #\soh #\001)
  216. (eqv? #\stx #\002)
  217. (eqv? #\NUL #\000)
  218. (eqv? #\SOH #\001)
  219. (eqv? #\STX #\002)
  220. (eqv? #\Nul #\000)
  221. (eqv? #\Soh #\001)
  222. (eqv? #\Stx #\002)))
  223. (pass-if "alt charnames are case insensitive"
  224. (eqv? #\null #\nul)
  225. (eqv? #\NULL #\nul)
  226. (eqv? #\Null #\nul))
  227. (pass-if-exception "bad charname" exception:unknown-character-name
  228. (with-input-from-string "#\\blammo" read))
  229. (pass-if "R5RS character names are preferred write format"
  230. (string=?
  231. (with-output-to-string (lambda () (write #\space)))
  232. "#\\space"))
  233. (pass-if "C0 control character names are preferred write format"
  234. (string=?
  235. (with-output-to-string (lambda () (write #\soh)))
  236. "#\\soh"))
  237. (pass-if "combining accent is pretty-printed"
  238. (let ((accent (integer->char #x030f))) ; COMBINING DOUBLE GRAVE ACCENT
  239. (string=?
  240. (with-output-to-string (lambda () (write accent)))
  241. "#\\◌̏")))
  242. (pass-if "combining X is pretty-printed"
  243. (let ((x (integer->char #x0353))) ; COMBINING X BELOW
  244. (string=?
  245. (with-output-to-string (lambda () (write x)))
  246. "#\\◌͓")))))