srfi-14-check.scm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Mike Sperber, Olin Shivers
  3. ; SRFI 14 test suite
  4. ;; adapted from Olin's test suite
  5. (define (vowel? c)
  6. (member c '(#\a #\e #\i #\o #\u)))
  7. (define-test-suite srfi-14-tests)
  8. (define-test-case char-set? srfi-14-tests
  9. (check (not (char-set? 5)))
  10. (check (char-set? (char-set #\a #\e #\i #\o #\u))))
  11. (define-test-case char-set= srfi-14-tests
  12. (check (char-set=))
  13. (check (char-set= (char-set)))
  14. (check (string->char-set "ioeauaiii")
  15. (=> char-set=)
  16. (char-set #\a #\e #\i #\o #\u))
  17. (check (not (char-set= (string->char-set "ioeauaiii")
  18. (char-set #\e #\i #\o #\u)))))
  19. (define-test-case char-set<= srfi-14-tests
  20. (check (char-set<=))
  21. (check (char-set<= (char-set)))
  22. (check (char-set<= (char-set #\a #\e #\i #\o #\u)
  23. (string->char-set "ioeauaiii")))
  24. (check (char-set<= (char-set #\e #\i #\o #\u)
  25. (string->char-set "ioeauaiii"))))
  26. (define-test-case char-set-hash srfi-14-tests
  27. (check-that (char-set-hash char-set:graphic 100)
  28. (all-of (is (lambda (x) (>= x 0)))
  29. (is (lambda (x) (<= x 99))))))
  30. (define-test-case char-set-fold srfi-14-tests
  31. (check (char-set-fold (lambda (c i) (+ i 1)) 0
  32. (char-set #\e #\i #\o #\u #\e #\e))
  33. => 4))
  34. ; The following test is ASCII/Latin-1 only, and fails with Unicode
  35. ; (char-set= (string->char-set "eiaou2468013579999")
  36. ; (char-set-unfold null? car cdr '(#\a #\e #\i #\o #\u #\u #\u)
  37. ; char-set:digit))
  38. (define-test-case char-set-unfold srfi-14-tests
  39. (check-that (char-set-unfold null? car cdr '(#\a #\e #\i #\o #\u)
  40. (string->char-set "0123456789"))
  41. (is char-set=
  42. (string->char-set "eiaou246801357999"))))
  43. (define-test-case char-set-unfold! srfi-14-tests
  44. (check-that (char-set-unfold! null? car cdr '(#\a #\e #\i #\o #\u)
  45. (string->char-set "0123456789"))
  46. (opposite (is char-set=
  47. (string->char-set "eiaou246801357")))))
  48. (define-test-case char-set-for-each srfi-14-tests
  49. (let ((cs (string->char-set "0123456789")))
  50. (char-set-for-each (lambda (c) (set! cs (char-set-delete cs c)))
  51. (string->char-set "02468000"))
  52. (check-that cs (is char-set= (string->char-set "97531"))))
  53. (let ((cs (string->char-set "0123456789")))
  54. (char-set-for-each (lambda (c) (set! cs (char-set-delete cs c)))
  55. (string->char-set "02468"))
  56. (check-that cs (opposite (is char-set= (string->char-set "7531"))))))
  57. (define-test-case char-set-map srfi-14-tests
  58. (check-that (char-set-map char-upcase (string->char-set "aeiou"))
  59. (is char-set=
  60. (string->char-set "IOUAEEEE")))
  61. (check-that (char-set-map char-upcase (string->char-set "aeiou"))
  62. (opposite (is char-set=
  63. (string->char-set "OUAEEEE")))))
  64. (define-test-case char-set-copy srfi-14-tests
  65. (check-that (char-set-copy (string->char-set "aeiou"))
  66. (is char-set= (string->char-set "aeiou"))))
  67. (define-test-case char-set srfi-14-tests
  68. (check-that (char-set #\x #\y) (is char-set= (string->char-set "xy")))
  69. (check-that (char-set #\x #\y #\z) (opposite (is char-set= (string->char-set "xy")))))
  70. (define-test-case list->char-set srfi-14-tests
  71. (check-that (list->char-set '(#\x #\y)) (is char-set= (string->char-set "xy")))
  72. (check-that (list->char-set '(#\x #\y)) (opposite (is char-set= (string->char-set "axy"))))
  73. (check-that (list->char-set '(#\x #\y) (string->char-set "12345"))
  74. (is char-set= (string->char-set "xy12345")))
  75. (check-that (list->char-set '(#\x #\y) (string->char-set "12345"))
  76. (opposite (is char-set= (string->char-set "y12345")))))
  77. (define-test-case list->char-set! srfi-14-tests
  78. (check-that (list->char-set! '(#\x #\y) (string->char-set "12345"))
  79. (is char-set= (string->char-set "xy12345")))
  80. (check-that (list->char-set! '(#\x #\y) (string->char-set "12345"))
  81. (opposite (is char-set= (string->char-set "y12345")))))
  82. (define-test-case char-set-filter srfi-14-tests
  83. (check-that (char-set-filter vowel? char-set:ascii (string->char-set "12345"))
  84. (is char-set= (string->char-set "aeiou12345")))
  85. (check-that (char-set-filter vowel? char-set:ascii (string->char-set "12345"))
  86. (opposite (is char-set= (string->char-set "aeou12345")))))
  87. (define-test-case char-set-filter! srfi-14-tests
  88. (check-that (char-set-filter! vowel? char-set:ascii (string->char-set "12345"))
  89. (is char-set= (string->char-set "aeiou12345")))
  90. (check-that (char-set-filter! vowel? char-set:ascii (string->char-set "12345"))
  91. (opposite (is char-set= (string->char-set "aeou12345")))))
  92. (define-test-case ucs-range->char-set srfi-14-tests
  93. (check-that (ucs-range->char-set 97 103 #t (string->char-set "12345"))
  94. (is char-set= (string->char-set "abcdef12345")))
  95. (check-that (ucs-range->char-set 97 103 #t (string->char-set "12345"))
  96. (opposite (is char-set= (string->char-set "abcef12345")))))
  97. (define-test-case ucs-range_>char-set! srfi-14-tests
  98. (check-that (ucs-range->char-set! 97 103 #t (string->char-set "12345"))
  99. (is char-set= (string->char-set "abcdef12345")))
  100. (check-that (ucs-range->char-set! 97 103 #t (string->char-set "12345"))
  101. (opposite (is char-set= (string->char-set "abcef12345")))))
  102. (define-test-case x->char-set srfi-14-tests
  103. (check-that (x->char-set #\x) (is char-set= (x->char-set "x")))
  104. (check-that (x->char-set #\x) (is char-set= (x->char-set (char-set #\x))))
  105. (check-that (x->char-set "y")
  106. (opposite (is char-set= (x->char-set #\x)))))
  107. (define-test-case char-set-size srfi-14-tests
  108. (check (char-set-size (char-set-intersection char-set:ascii char-set:digit))
  109. => 10))
  110. (define-test-case char-set-count srfi-14-tests
  111. (check (char-set-count vowel? char-set:ascii)
  112. => 5))
  113. (define-test-case char-set->list srfi-14-tests
  114. (check (char-set->list (char-set #\x)) => '(#\x))
  115. (check-that (char-set->list (char-set #\x)) (opposite (is '(#\X)))))
  116. (define-test-case char-set->string srfi-14-tests
  117. (check (char-set->string (char-set #\x)) => "x")
  118. (check-that (char-set->string (char-set #\x)) (opposite (is "X" ))))
  119. (define-test-case char-set-contains? srfi-14-tests
  120. (check (char-set-contains? (x->char-set "xyz") #\x))
  121. (check (not (char-set-contains? (x->char-set "xyz") #\a))))
  122. (define-test-case char-set-every srfi-14-tests
  123. (check (char-set-every char-lower-case? (x->char-set "abcd")))
  124. (check-that (char-set-every char-lower-case? (x->char-set "abcD")) (is-false)))
  125. (define-test-case char-set-any srfi-14-tests
  126. (check (char-set-any char-lower-case? (x->char-set "abcd")))
  127. (check-that (char-set-any char-lower-case? (x->char-set "ABCD")) (is-false)))
  128. (define-test-case cursors srfi-14-tests
  129. (check-that
  130. (let ((cs (x->char-set "abcd")))
  131. (let lp ((cur (char-set-cursor cs)) (ans '()))
  132. (if (end-of-char-set? cur) (list->char-set ans)
  133. (lp (char-set-cursor-next cs cur)
  134. (cons (char-upcase (char-set-ref cs cur)) ans)))))
  135. (is char-set=
  136. (x->char-set "ABCD"))))
  137. (define-test-case char-set-adjoin srfi-14-tests
  138. (check-that (char-set-adjoin (x->char-set "123") #\x #\a)
  139. (is char-set= (x->char-set "123xa")))
  140. (check-that (x->char-set "123x")
  141. (opposite (is char-set= (char-set-adjoin (x->char-set "123") #\x #\a)))))
  142. (define-test-case char-set-adjoin! srfi-14-tests
  143. (check-that (char-set-adjoin! (x->char-set "123") #\x #\a)
  144. (is char-set= (x->char-set "123xa")))
  145. (check-that (x->char-set "123x")
  146. (opposite (is char-set= (char-set-adjoin! (x->char-set "123") #\x #\a)))))
  147. (define-test-case char-set-delete srfi-14-tests
  148. (check-that (char-set-delete (x->char-set "123") #\2 #\a #\2)
  149. (is char-set= (x->char-set "13")))
  150. (check-that (char-set-delete (x->char-set "123") #\2 #\a #\2)
  151. (opposite (is char-set= (x->char-set "13a")))))
  152. (define-test-case char-set-delete! srfi-14-tests
  153. (check-that (char-set-delete! (x->char-set "123") #\2 #\a #\2)
  154. (is char-set= (x->char-set "13")))
  155. (check-that (char-set-delete! (x->char-set "123") #\2 #\a #\2)
  156. (opposite (is char-set= (x->char-set "13a")))))
  157. (define-test-case char-set-intersection srfi-14-tests
  158. (check-that
  159. (char-set-intersection char-set:hex-digit (char-set-complement char-set:digit))
  160. (is char-set=
  161. (x->char-set "abcdefABCDEF"))))
  162. (define-test-case char-set-intersection! srfi-14-tests
  163. (check-that
  164. (char-set-intersection! (char-set-complement! (x->char-set "0123456789"))
  165. char-set:hex-digit)
  166. (is char-set=
  167. (x->char-set "abcdefABCDEF"))))
  168. (define-test-case char-set-union srfi-14-tests
  169. (check-that
  170. (char-set-union char-set:hex-digit
  171. (x->char-set "abcdefghijkl"))
  172. (is char-set=
  173. (x->char-set "abcdefABCDEFghijkl0123456789"))))
  174. (define-test-case char-set-union! srfi-14-tests
  175. (check-that
  176. (char-set-union! (x->char-set "abcdefghijkl")
  177. char-set:hex-digit)
  178. (is char-set=
  179. (x->char-set "abcdefABCDEFghijkl0123456789"))))
  180. (define-test-case char-set-difference srfi-14-tests
  181. (check-that
  182. (char-set-difference (x->char-set "abcdefghijklmn")
  183. char-set:hex-digit)
  184. (is char-set=
  185. (x->char-set "ghijklmn"))))
  186. (define-test-case char-set-difference! srfi-14-tests
  187. (check-that
  188. (char-set-difference! (x->char-set "abcdefghijklmn")
  189. char-set:hex-digit)
  190. (is char-set=
  191. (x->char-set "ghijklmn"))))
  192. (define-test-case char-set-xor srfi-14-tests
  193. (check-that
  194. (char-set-xor (x->char-set "0123456789")
  195. char-set:hex-digit)
  196. (is char-set=
  197. (x->char-set "abcdefABCDEF"))))
  198. (define-test-case char-set-xor! srfi-14-tests char-set=
  199. (check-that (char-set-xor! (x->char-set "0123456789")
  200. char-set:hex-digit)
  201. (is char-set= (x->char-set "abcdefABCDEF"))))
  202. (define-test-case char-set-diff+intersection srfi-14-tests
  203. (call-with-values (lambda ()
  204. (char-set-diff+intersection char-set:hex-digit
  205. char-set:letter))
  206. (lambda (d i)
  207. (check-that d (is char-set= (x->char-set "0123456789")))
  208. (check-that i (is char-set= (x->char-set "abcdefABCDEF")))))
  209. (call-with-values (lambda ()
  210. (char-set-diff+intersection (char-set-union char-set:letter
  211. char-set:digit)
  212. char-set:letter))
  213. (lambda (d i)
  214. (check-that d (is char-set= char-set:digit))
  215. (check-that i (is char-set= char-set:letter)))))
  216. (define-test-case char-set-diff+intersection! srfi-14-tests
  217. (call-with-values (lambda ()
  218. (char-set-diff+intersection! (char-set-copy char-set:hex-digit)
  219. (char-set-copy char-set:letter)))
  220. (lambda (d i)
  221. (check-that d (is char-set= (x->char-set "0123456789")))
  222. (check-that i (is char-set= (x->char-set "abcdefABCDEF")))))
  223. (call-with-values (lambda ()
  224. (char-set-diff+intersection! (char-set-union char-set:letter
  225. char-set:digit)
  226. (char-set-copy char-set:letter)))
  227. (lambda (d i)
  228. (check-that d (is char-set= char-set:digit))
  229. (check-that i (is char-set= char-set:letter)))))
  230. ; The following stuff was adapted from the suite Matthew Flatt wrote
  231. ; for PLT Scheme
  232. (define-test-case char-set:lower-case srfi-14-tests
  233. (check (char-set-contains? char-set:lower-case #\a))
  234. (check (not (char-set-contains? char-set:lower-case #\A)))
  235. (check (char-set-contains? char-set:lower-case (scalar-value->char #x00E0)))
  236. (check (not (char-set-contains? char-set:lower-case (scalar-value->char #x00C2))))
  237. (check (char-set-contains? char-set:lower-case (scalar-value->char #x00B5))))
  238. (define-test-case char-set:upper-case srfi-14-tests
  239. (check (char-set-contains? char-set:upper-case #\A))
  240. (check (not (char-set-contains? char-set:upper-case #\a)))
  241. (check (char-set-contains? char-set:upper-case (scalar-value->char #x00C2)))
  242. (check (not (char-set-contains? char-set:upper-case (scalar-value->char #x00E0)))))
  243. (define-test-case char-set:title-case srfi-14-tests
  244. (check (char-set-contains? char-set:title-case (scalar-value->char #x01C5)))
  245. (check (char-set-contains? char-set:title-case (scalar-value->char #x1FA8)))
  246. (check (not (char-set-contains? char-set:title-case #\a)))
  247. (check (not (char-set-contains? char-set:title-case #\A))))
  248. (define-test-case char-set:letter srfi-14-tests
  249. (check (char-set-contains? char-set:letter #\a))
  250. (check (char-set-contains? char-set:letter #\A))
  251. (check (not (char-set-contains? char-set:letter #\1)))
  252. (check (char-set-contains? char-set:letter (scalar-value->char #x00AA)))
  253. (check (char-set-contains? char-set:letter (scalar-value->char #x00BA))))
  254. (define-test-case char-set:lower-case/2 srfi-14-tests
  255. (check (not (char-set-every (lambda (c) (char-set-contains? char-set:lower-case c)) char-set:letter)))
  256. (check (char-set-any (lambda (c) (char-set-contains? char-set:lower-case c)) char-set:letter)))
  257. (define-test-case char-set:upper-case/2 srfi-14-tests
  258. (check (not (char-set-every (lambda (c) (char-set-contains? char-set:upper-case c)) char-set:letter)))
  259. (check (char-set-any (lambda (c) (char-set-contains? char-set:upper-case c)) char-set:letter)))
  260. ;; Not true?
  261. ;; (test #t char-set<= char-set:letter (char-set-union char-set:lower-case char-set:upper-case char-set:title-case))
  262. (define-test-case char-set:digit srfi-14-tests
  263. (check (char-set-contains? char-set:digit #\1))
  264. (check (not (char-set-contains? char-set:digit #\a))))
  265. (define-test-case char-set:hex-digit srfi-14-tests
  266. (check (char-set-contains? char-set:hex-digit #\1))
  267. (check (char-set-contains? char-set:hex-digit #\a))
  268. (check (char-set-contains? char-set:hex-digit #\A))
  269. (check (not (char-set-contains? char-set:hex-digit #\g))))
  270. (define-test-case char-set:letter+digit srfi-14-tests equal?
  271. (check (char-set-contains? char-set:letter+digit #\1))
  272. (check (char-set-contains? char-set:letter+digit #\a))
  273. (check (char-set-contains? char-set:letter+digit #\z))
  274. (check (char-set-contains? char-set:letter+digit #\A))
  275. (check (char-set-contains? char-set:letter+digit #\Z)))
  276. (define-test-case char-set:letter/size srfi-14-tests
  277. (check (char-set-size char-set:letter) => 92496))
  278. (define-test-case char-set:letter/2 srfi-14-tests
  279. (check-that (char-set-union char-set:letter char-set:digit)
  280. (is char-set=
  281. char-set:letter+digit))
  282. (check (not (char-set-every (lambda (c) (char-set-contains? char-set:letter c)) char-set:letter+digit)))
  283. (check (not (char-set-every (lambda (c) (char-set-contains? char-set:digit c)) char-set:letter+digit)))
  284. (check (char-set-any (lambda (c) (char-set-contains? char-set:letter c)) char-set:letter+digit)))
  285. (define-test-case char-set:letter+digit/2 srfi-14-tests
  286. (check (char-set-every (lambda (c) (char-set-contains? char-set:letter+digit c)) char-set:letter))
  287. (check (char-set-every (lambda (c) (char-set-contains? char-set:letter+digit c)) char-set:digit)))
  288. (define char-set:latin-1 (ucs-range->char-set 0 256))
  289. (define-test-case char-set:latin-1 srfi-14-tests
  290. (check-that
  291. (char-set-intersection (char-set-union char-set:letter char-set:digit char-set:punctuation char-set:symbol)
  292. char-set:latin-1)
  293. (is char-set=
  294. (char-set-intersection char-set:graphic char-set:latin-1))))
  295. (define-test-case char-set:printing srfi-14-tests
  296. (check-that (char-set-union char-set:graphic char-set:whitespace)
  297. (is char-set= char-set:printing)))
  298. (define-test-case char-set:whitespace srfi-14-tests
  299. (check (char-set-contains? char-set:whitespace (scalar-value->char #x0009)))
  300. (check (char-set-contains? char-set:whitespace (scalar-value->char #x000D)))
  301. (check (not (char-set-contains? char-set:whitespace #\a))))
  302. (define-test-case char-set:iso-control srfi-14-tests
  303. (check-that (char-set-union (ucs-range->char-set #x0000 #x0020)
  304. (ucs-range->char-set #x007F #x00A0))
  305. (is char-set=
  306. char-set:iso-control)))
  307. (define-test-case char-set:punctuation srfi-14-tests
  308. (check (char-set-contains? char-set:punctuation #\!))
  309. (check (char-set-contains? char-set:punctuation (scalar-value->char #x00A1)))
  310. (check (not (char-set-contains? char-set:punctuation #\a))))
  311. (define-test-case char-set:symbol srfi-14-tests
  312. (check (char-set-contains? char-set:symbol #\$))
  313. (check (char-set-contains? char-set:symbol (scalar-value->char #x00A2)))
  314. (check (not (char-set-contains? char-set:symbol #\a))))
  315. (define-test-case char-set:blank srfi-14-tests
  316. (check (char-set-contains? char-set:blank #\space))
  317. (check (char-set-contains? char-set:blank (scalar-value->char #x3000)))
  318. (check (not (char-set-contains? char-set:blank #\a))))
  319. ;; General procedures ----------------------------------------
  320. (define-test-case char-set=/2 srfi-14-tests
  321. (check (char-set= char-set:letter char-set:letter char-set:letter))
  322. (check (not (char-set= char-set:letter char-set:digit)))
  323. (check (not (char-set= char-set:letter char-set:letter char-set:digit)))
  324. (check (not (char-set= char-set:letter char-set:digit char-set:letter))))
  325. (define-test-case char-set<=/2 srfi-14-tests
  326. (check (char-set<= char-set:graphic char-set:printing))
  327. (check (not (char-set<= char-set:printing char-set:graphic)))
  328. (check (char-set<= char-set:graphic char-set:printing char-set:full))
  329. (check (not (char-set<= char-set:graphic char-set:full char-set:printing))))
  330. (define-test-case char-set-hash/2 srfi-14-tests
  331. (check (char-set-hash char-set:graphic)
  332. =>
  333. (char-set-hash char-set:graphic)))
  334. ;; Iterating over character sets ----------------------------------------
  335. ;; The number 290 comes from "grep Nd UnicodeData.txt | wc -l"
  336. (define-test-case char-set-size/2 srfi-14-tests
  337. (check (char-set-size char-set:digit)
  338. => 290))
  339. (define-test-case cursors/2 srfi-14-tests
  340. (check-that (list->char-set
  341. (let loop ((c (char-set-cursor char-set:digit)) (l '()))
  342. (if (end-of-char-set? c)
  343. l
  344. (loop (char-set-cursor-next char-set:digit c)
  345. (cons (char-set-ref char-set:digit c)
  346. l)))))
  347. (is char-set= char-set:digit)))
  348. (define (add1 x) (+ 1 x))
  349. (define-test-case char-set-unfold/2 srfi-14-tests
  350. (check-that
  351. (char-set-unfold (lambda (x) (= x 20)) scalar-value->char add1 10)
  352. (is char-set= (ucs-range->char-set 10 20)))
  353. (check-that
  354. (char-set-unfold (lambda (x) (= x 20)) scalar-value->char add1 10 (char-set (scalar-value->char #x14)))
  355. (is char-set=
  356. (ucs-range->char-set 10 21))))
  357. (define-test-case char-set-unfold!/2 srfi-14-tests
  358. (check-that
  359. (char-set-unfold! (lambda (x) (= x 20)) scalar-value->char add1 10
  360. (char-set-copy char-set:empty))
  361. (is char-set= (ucs-range->char-set 10 20))))
  362. (define-test-case char-set-for-each/2 srfi-14-tests
  363. (check-that
  364. (let ((cs char-set:empty))
  365. (char-set-for-each
  366. (lambda (c)
  367. (set! cs (char-set-adjoin cs c)))
  368. char-set:digit)
  369. cs)
  370. (is char-set= char-set:digit)))
  371. (define-test-case char-set-map/2 srfi-14-tests equal?
  372. (check-that (char-set-map
  373. (lambda (c) c)
  374. char-set:digit)
  375. (is char-set= char-set:digit))
  376. (check-that (char-set-map
  377. (lambda (c) c)
  378. char-set:digit)
  379. (is char-set= char-set:digit))
  380. (check-that (char-set-union
  381. (char-set-map
  382. (lambda (c) c)
  383. char-set:digit)
  384. (char-set #\A))
  385. (is char-set= (char-set-adjoin char-set:digit #\A))))
  386. ;; Creating character sets ----------------------------------------
  387. (define-test-case char-set-copy/2 srfi-14-tests
  388. (check-that (char-set-copy char-set:digit)
  389. (is char-set= char-set:digit)))
  390. (define-test-case abc srfi-14-tests
  391. (let ((abc (char-set #\a #\b #\c)))
  392. (check-that (char-set #\c #\a #\b)
  393. (is char-set=
  394. abc))
  395. (check-that (string->char-set "cba") (is char-set= abc))
  396. (check-that (string->char-set! "cba" (char-set-copy char-set:empty)) (is char-set= abc))
  397. (check-that (string->char-set "cb" (char-set #\a)) (is char-set= abc))
  398. (check-that (char-set-filter (lambda (c) (char=? c #\b)) abc) (is char-set= (char-set #\b)))
  399. (check-that (char-set-filter (lambda (c) (char=? c #\b)) abc char-set:empty) (is char-set= (char-set #\b)))
  400. (check-that (char-set-filter! (lambda (c) (char=? c #\b)) (char-set-copy abc) (char-set-copy char-set:empty))
  401. (is char-set= (char-set #\b)))
  402. (check-that (x->char-set "abc") (is char-set= abc))
  403. (check-that (x->char-set abc) (is char-set= abc))
  404. (check-that (x->char-set #\a) (is char-set= (char-set #\a)))))
  405. (define-test-case ucs-range->char/2 srfi-14-tests
  406. (check-that
  407. (char-set-union (ucs-range->char-set 0 #xD800)
  408. (ucs-range->char-set #xE000 #x20000))
  409. (is char-set= (ucs-range->char-set 0 #x20000)))
  410. (check-that
  411. (ucs-range->char-set 0 #xD800)
  412. (is char-set= (ucs-range->char-set 0 #xD801)))
  413. (check-that
  414. (ucs-range->char-set 0 #xD800)
  415. (is char-set= (ucs-range->char-set 0 #xDFFF)))
  416. (check-that
  417. char-set:empty
  418. (is char-set= (ucs-range->char-set #xD800 #xD810)))
  419. (check-that
  420. char-set:empty
  421. (is char-set= (ucs-range->char-set #xD810 #xE000)))
  422. (check-that
  423. (ucs-range->char-set #xD810 #xE001)
  424. (is char-set= (ucs-range->char-set #xE000 #xE001)))
  425. (check-that
  426. (char-set (scalar-value->char #xD7FF) (scalar-value->char #xE000))
  427. (is char-set= (ucs-range->char-set #xD7FF #xE001))))
  428. ;; Querying character sets ------------------------------
  429. (define-test-case char-set-count/2 srfi-14-tests
  430. (check
  431. (char-set-count (lambda (x)
  432. (and (char<=? #\0 x)
  433. (char<=? x #\2)))
  434. char-set:digit)
  435. => 3))
  436. (define-test-case list->char-set/2 srfi-14-tests
  437. (check-that (list->char-set (char-set->list char-set:digit))
  438. (is char-set= char-set:digit))
  439. (check-that (list->char-set (char-set->list char-set:digit) char-set:empty)
  440. (is char-set= char-set:digit))
  441. (check-that (list->char-set! (char-set->list char-set:digit) (char-set-copy char-set:empty))
  442. (is char-set= char-set:digit))
  443. (check-that (string->char-set (char-set->string char-set:digit))
  444. (is char-set= char-set:digit)))