srfi-14.test 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. ;;;; srfi-14.test -*- mode:scheme; coding: iso-8859-1 -*-
  2. ;;;; --- Test suite for Guile's SRFI-14 functions.
  3. ;;;; Martin Grabmueller, 2001-07-16
  4. ;;;;
  5. ;;;; Copyright (C) 2001, 2006, 2009, 2010, 2014 Free Software Foundation, Inc.
  6. ;;;;
  7. ;;;; This library is free software; you can redistribute it and/or
  8. ;;;; modify it under the terms of the GNU Lesser General Public
  9. ;;;; License as published by the Free Software Foundation; either
  10. ;;;; version 3 of the License, or (at your option) any later version.
  11. ;;;;
  12. ;;;; This library is distributed in the hope that it will be useful,
  13. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. ;;;; Lesser General Public License for more details.
  16. ;;;;
  17. ;;;; You should have received a copy of the GNU Lesser General Public
  18. ;;;; License along with this library; if not, write to the Free Software
  19. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. (define-module (test-suite test-srfi-14)
  21. :use-module (srfi srfi-14)
  22. :use-module (srfi srfi-1) ;; `every'
  23. :use-module (test-suite lib))
  24. (define exception:invalid-char-set-cursor
  25. (cons 'misc-error "^invalid character set cursor"))
  26. (define exception:non-char-return
  27. (cons 'misc-error "returned non-char"))
  28. (with-test-prefix "char set contents"
  29. (pass-if "empty set"
  30. (list= eqv?
  31. (char-set->list (char-set))
  32. '()))
  33. (pass-if "single char"
  34. (list= eqv?
  35. (char-set->list (char-set #\a))
  36. (list #\a)))
  37. (pass-if "contiguous chars"
  38. (list= eqv?
  39. (char-set->list (char-set #\a #\b #\c))
  40. (list #\a #\b #\c)))
  41. (pass-if "discontiguous chars"
  42. (list= eqv?
  43. (char-set->list (char-set #\a #\c #\e))
  44. (list #\a #\c #\e))))
  45. (with-test-prefix "char set additition"
  46. (pass-if "empty + x"
  47. (let ((cs (char-set)))
  48. (char-set-adjoin! cs #\x)
  49. (list= eqv?
  50. (char-set->list cs)
  51. (list #\x))))
  52. (pass-if "x + y"
  53. (let ((cs (char-set #\x)))
  54. (char-set-adjoin! cs #\y)
  55. (list= eqv?
  56. (char-set->list cs)
  57. (list #\x #\y))))
  58. (pass-if "x + w"
  59. (let ((cs (char-set #\x)))
  60. (char-set-adjoin! cs #\w)
  61. (list= eqv?
  62. (char-set->list cs)
  63. (list #\w #\x))))
  64. (pass-if "x + z"
  65. (let ((cs (char-set #\x)))
  66. (char-set-adjoin! cs #\z)
  67. (list= eqv?
  68. (char-set->list cs)
  69. (list #\x #\z))))
  70. (pass-if "x + v"
  71. (let ((cs (char-set #\x)))
  72. (char-set-adjoin! cs #\v)
  73. (list= eqv?
  74. (char-set->list cs)
  75. (list #\v #\x))))
  76. (pass-if "uv + w"
  77. (let ((cs (char-set #\u #\v)))
  78. (char-set-adjoin! cs #\w)
  79. (list= eqv?
  80. (char-set->list cs)
  81. (list #\u #\v #\w))))
  82. (pass-if "uv + t"
  83. (let ((cs (char-set #\u #\v)))
  84. (char-set-adjoin! cs #\t)
  85. (list= eqv?
  86. (char-set->list cs)
  87. (list #\t #\u #\v))))
  88. (pass-if "uv + x"
  89. (let ((cs (char-set #\u #\v)))
  90. (char-set-adjoin! cs #\x)
  91. (list= eqv?
  92. (char-set->list cs)
  93. (list #\u #\v #\x))))
  94. (pass-if "uv + s"
  95. (let ((cs (char-set #\u #\v)))
  96. (char-set-adjoin! cs #\s)
  97. (list= eqv?
  98. (char-set->list cs)
  99. (list #\s #\u #\v))))
  100. (pass-if "uvx + w"
  101. (let ((cs (char-set #\u #\v #\x)))
  102. (char-set-adjoin! cs #\w)
  103. (list= eqv?
  104. (char-set->list cs)
  105. (list #\u #\v #\w #\x))))
  106. (pass-if "uvx + y"
  107. (let ((cs (char-set #\u #\v #\x)))
  108. (char-set-adjoin! cs #\y)
  109. (list= eqv?
  110. (char-set->list cs)
  111. (list #\u #\v #\x #\y))))
  112. (pass-if "uvxy + w"
  113. (let ((cs (char-set #\u #\v #\x #\y)))
  114. (char-set-adjoin! cs #\w)
  115. (list= eqv?
  116. (char-set->list cs)
  117. (list #\u #\v #\w #\x #\y)))))
  118. (with-test-prefix "char set union"
  119. (pass-if "null U abc"
  120. (char-set= (char-set-union (char-set) (->char-set "abc"))
  121. (->char-set "abc")))
  122. (pass-if "ab U ab"
  123. (char-set= (char-set-union (->char-set "ab") (->char-set "ab"))
  124. (->char-set "ab")))
  125. (pass-if "ab U bc"
  126. (char-set= (char-set-union (->char-set "ab") (->char-set "bc"))
  127. (->char-set "abc")))
  128. (pass-if "ab U cd"
  129. (char-set= (char-set-union (->char-set "ab") (->char-set "cd"))
  130. (->char-set "abcd")))
  131. (pass-if "ab U de"
  132. (char-set= (char-set-union (->char-set "ab") (->char-set "de"))
  133. (->char-set "abde")))
  134. (pass-if "abc U bcd"
  135. (char-set= (char-set-union (->char-set "abc") (->char-set "bcd"))
  136. (->char-set "abcd")))
  137. (pass-if "abdf U abcdefg"
  138. (char-set= (char-set-union (->char-set "abdf") (->char-set "abcdefg"))
  139. (->char-set "abcdefg")))
  140. (pass-if "abef U cd"
  141. (char-set= (char-set-union (->char-set "abef") (->char-set "cd"))
  142. (->char-set "abcdef")))
  143. (pass-if "abgh U cd"
  144. (char-set= (char-set-union (->char-set "abgh") (->char-set "cd"))
  145. (->char-set "abcdgh")))
  146. (pass-if "bc U ab"
  147. (char-set= (char-set-union (->char-set "bc") (->char-set "ab"))
  148. (->char-set "abc")))
  149. (pass-if "cd U ab"
  150. (char-set= (char-set-union (->char-set "cd") (->char-set "ab"))
  151. (->char-set "abcd")))
  152. (pass-if "de U ab"
  153. (char-set= (char-set-union (->char-set "de") (->char-set "ab"))
  154. (->char-set "abde")))
  155. (pass-if "cd U abc"
  156. (char-set= (char-set-union (->char-set "cd") (->char-set "abc"))
  157. (->char-set "abcd")))
  158. (pass-if "cd U abcd"
  159. (char-set= (char-set-union (->char-set "cd") (->char-set "abcd"))
  160. (->char-set "abcd")))
  161. (pass-if "cde U abcdef"
  162. (char-set= (char-set-union (->char-set "cde") (->char-set "abcdef"))
  163. (->char-set "abcdef"))))
  164. (with-test-prefix "char set xor"
  165. (pass-if "null - xy"
  166. (char-set= (char-set-xor (char-set) (char-set #\x #\y))
  167. (char-set #\x #\y)))
  168. (pass-if "x - x"
  169. (char-set= (char-set-xor (char-set #\x) (char-set #\x))
  170. (char-set)))
  171. (pass-if "xy - x"
  172. (char-set= (char-set-xor (char-set #\x #\y) (char-set #\x))
  173. (char-set #\y)))
  174. (pass-if "xy - y"
  175. (char-set= (char-set-xor (char-set #\x #\y) (char-set #\y))
  176. (char-set #\x)))
  177. (pass-if "wxy - w"
  178. (char-set= (char-set-xor (char-set #\w #\x #\y) (char-set #\w))
  179. (char-set #\x #\y)))
  180. (pass-if "wxy - x"
  181. (char-set= (char-set-xor (char-set #\w #\x #\y) (char-set #\x))
  182. (char-set #\w #\y)))
  183. (pass-if "wxy - y"
  184. (char-set= (char-set-xor (char-set #\w #\x #\y) (char-set #\y))
  185. (char-set #\w #\x)))
  186. (pass-if "uvxy - u"
  187. (char-set= (char-set-xor (char-set #\u #\v #\x #\y) (char-set #\u))
  188. (char-set #\v #\x #\y)))
  189. (pass-if "uvxy - v"
  190. (char-set= (char-set-xor (char-set #\u #\v #\x #\y) (char-set #\v))
  191. (char-set #\u #\x #\y)))
  192. (pass-if "uvxy - x"
  193. (char-set= (char-set-xor (char-set #\u #\v #\x #\y) (char-set #\x))
  194. (char-set #\u #\v #\y)))
  195. (pass-if "uvxy - y"
  196. (char-set= (char-set-xor (char-set #\u #\v #\x #\y) (char-set #\y))
  197. (char-set #\u #\v #\x)))
  198. (pass-if "uwy - u"
  199. (char-set= (char-set-xor (char-set #\u #\w #\y) (char-set #\u))
  200. (char-set #\w #\y)))
  201. (pass-if "uwy - w"
  202. (char-set= (char-set-xor (char-set #\u #\w #\y) (char-set #\w))
  203. (char-set #\u #\y)))
  204. (pass-if "uwy - y"
  205. (char-set= (char-set-xor (char-set #\u #\w #\y) (char-set #\y))
  206. (char-set #\u #\w)))
  207. (pass-if "uvwy - v"
  208. (char-set= (char-set-xor (char-set #\u #\v #\w #\y) (char-set #\v))
  209. (char-set #\u #\w #\y))))
  210. (with-test-prefix "char-set?"
  211. (pass-if "success on empty set"
  212. (char-set? (char-set)))
  213. (pass-if "success on non-empty set"
  214. (char-set? char-set:printing))
  215. (pass-if "failure on empty set"
  216. (not (char-set? #t))))
  217. (with-test-prefix "char-set="
  218. (pass-if "success, no arg"
  219. (char-set=))
  220. (pass-if "success, one arg"
  221. (char-set= char-set:lower-case))
  222. (pass-if "success, two args"
  223. (char-set= char-set:upper-case char-set:upper-case))
  224. (pass-if "failure, first empty"
  225. (not (char-set= (char-set) (char-set #\a))))
  226. (pass-if "failure, second empty"
  227. (not (char-set= (char-set #\a) (char-set))))
  228. (pass-if "success, more args"
  229. (char-set= char-set:blank char-set:blank char-set:blank))
  230. (pass-if "failure, same length, different elements"
  231. (not (char-set= (char-set #\a #\b #\d) (char-set #\a #\c #\d)))))
  232. (with-test-prefix "char-set<="
  233. (pass-if "success, no arg"
  234. (char-set<=))
  235. (pass-if "success, one arg"
  236. (char-set<= char-set:lower-case))
  237. (pass-if "success, two args"
  238. (char-set<= char-set:upper-case char-set:upper-case))
  239. (pass-if "success, first empty"
  240. (char-set<= (char-set) (char-set #\a)))
  241. (pass-if "failure, second empty"
  242. (not (char-set<= (char-set #\a) (char-set))))
  243. (pass-if "success, more args, equal"
  244. (char-set<= char-set:blank char-set:blank char-set:blank))
  245. (pass-if "success, more args, not equal"
  246. (char-set<= char-set:blank
  247. (char-set-adjoin char-set:blank #\F)
  248. (char-set-adjoin char-set:blank #\F #\o))))
  249. (with-test-prefix "char-set-hash"
  250. (pass-if "empty set, bound"
  251. (let ((h (char-set-hash char-set:empty 31)))
  252. (and h (number? h) (exact? h) (>= h 0) (< h 31))))
  253. (pass-if "empty set, no bound"
  254. (let ((h (char-set-hash char-set:empty)))
  255. (and h (number? h) (exact? h) (>= h 0))))
  256. (pass-if "full set, bound"
  257. (let ((h (char-set-hash char-set:full 31)))
  258. (and h (number? h) (exact? h) (>= h 0) (< h 31))))
  259. (pass-if "full set, no bound"
  260. (let ((h (char-set-hash char-set:full)))
  261. (and h (number? h) (exact? h) (>= h 0))))
  262. (pass-if "other set, bound"
  263. (let ((h (char-set-hash (char-set #\f #\o #\b #\a #\r) 31)))
  264. (and h (number? h) (exact? h) (>= h 0) (< h 31))))
  265. (pass-if "other set, no bound"
  266. (let ((h (char-set-hash (char-set #\f #\o #\b #\a #\r))))
  267. (and h (number? h) (exact? h) (>= h 0)))))
  268. (with-test-prefix "char-set cursor"
  269. (pass-if-exception "invalid character cursor"
  270. exception:wrong-type-arg
  271. (let* ((cs (char-set #\B #\r #\a #\z))
  272. (cc (char-set-cursor cs)))
  273. (char-set-ref cs 1000)))
  274. (pass-if "success"
  275. (let* ((cs (char-set #\B #\r #\a #\z))
  276. (cc (char-set-cursor cs)))
  277. (char? (char-set-ref cs cc))))
  278. (pass-if "end of set fails"
  279. (let* ((cs (char-set #\a))
  280. (cc (char-set-cursor cs)))
  281. (not (end-of-char-set? cc))))
  282. (pass-if "end of set succeeds, empty set"
  283. (let* ((cs (char-set))
  284. (cc (char-set-cursor cs)))
  285. (end-of-char-set? cc)))
  286. (pass-if "end of set succeeds, non-empty set"
  287. (let* ((cs (char-set #\a))
  288. (cc (char-set-cursor cs))
  289. (cc (char-set-cursor-next cs cc)))
  290. (end-of-char-set? cc))))
  291. (with-test-prefix "char-set-fold"
  292. (pass-if "count members"
  293. (= (char-set-fold (lambda (c n) (+ n 1)) 0 (char-set #\a #\b)) 2))
  294. (pass-if "copy set"
  295. (= (char-set-size (char-set-fold (lambda (c cs) (char-set-adjoin cs c))
  296. (char-set) (char-set #\a #\b))) 2)))
  297. (define char-set:256
  298. (string->char-set (apply string (map integer->char (iota 256)))))
  299. (with-test-prefix "char-set-unfold"
  300. (pass-if "create char set"
  301. (char-set= char-set:256
  302. (char-set-unfold (lambda (s) (= s 256)) integer->char
  303. (lambda (s) (+ s 1)) 0)))
  304. (pass-if "create char set (base set)"
  305. (char-set= char-set:256
  306. (char-set-unfold (lambda (s) (= s 256)) integer->char
  307. (lambda (s) (+ s 1)) 0 char-set:empty))))
  308. (with-test-prefix "char-set-unfold!"
  309. (pass-if "create char set"
  310. (char-set= char-set:256
  311. (char-set-unfold! (lambda (s) (= s 256)) integer->char
  312. (lambda (s) (+ s 1)) 0
  313. (char-set-copy char-set:empty))))
  314. (pass-if "create char set"
  315. (char-set= char-set:256
  316. (char-set-unfold! (lambda (s) (= s 32)) integer->char
  317. (lambda (s) (+ s 1)) 0
  318. (char-set-copy char-set:256)))))
  319. (with-test-prefix "char-set-for-each"
  320. (pass-if "copy char set"
  321. (= (char-set-size (let ((cs (char-set)))
  322. (char-set-for-each
  323. (lambda (c) (char-set-adjoin! cs c))
  324. (char-set #\a #\b))
  325. cs))
  326. 2)))
  327. (with-test-prefix "char-set-map"
  328. (pass-if "upper case char set 1"
  329. (char-set= (char-set-map char-upcase
  330. (string->char-set "abcdefghijklmnopqrstuvwxyz"))
  331. (string->char-set "ABCDEFGHIJKLMNOPQRSTUVWXYZ")))
  332. (pass-if "upper case char set 2"
  333. (char-set= (char-set-map char-upcase
  334. (string->char-set "àáâãäåæçèéêëìíîïñòóôõöøùúûüýþ"))
  335. (string->char-set "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝÞ"))))
  336. (with-test-prefix "string->char-set"
  337. (pass-if "some char set"
  338. (let ((chars '(#\g #\u #\i #\l #\e)))
  339. (char-set= (list->char-set chars)
  340. (string->char-set (apply string chars))))))
  341. (with-test-prefix "char-set->string"
  342. (pass-if "some char set"
  343. (let ((cs (char-set #\g #\u #\i #\l #\e)))
  344. (string=? (char-set->string cs)
  345. "egilu"))))
  346. (with-test-prefix "list->char-set"
  347. (pass-if "list->char-set"
  348. (char-set= (list->char-set '(#\a #\b #\c))
  349. (->char-set "abc")))
  350. (pass-if "list->char-set!"
  351. (let* ((cs (char-set #\a #\z)))
  352. (list->char-set! '(#\m #\n) cs)
  353. (char-set= cs
  354. (char-set #\a #\m #\n #\z)))))
  355. (with-test-prefix "string->char-set"
  356. (pass-if "string->char-set"
  357. (char-set= (string->char-set "foobar")
  358. (string->char-set "barfoo")))
  359. (pass-if "string->char-set cs"
  360. (char-set= (string->char-set "foo" (string->char-set "bar"))
  361. (string->char-set "barfoo")))
  362. (pass-if "string->char-set!"
  363. (let ((cs (string->char-set "bar")))
  364. (string->char-set! "foo" cs)
  365. (char-set= cs
  366. (string->char-set "barfoo")))))
  367. (with-test-prefix "char-set-filter"
  368. (pass-if "filter w/o base"
  369. (char-set=
  370. (char-set-filter (lambda (c) (char=? c #\x))
  371. (->char-set "qrstuvwxyz"))
  372. (->char-set #\x)))
  373. (pass-if "filter w/ base"
  374. (char-set=
  375. (char-set-filter (lambda (c) (char=? c #\x))
  376. (->char-set "qrstuvwxyz")
  377. (->char-set "op"))
  378. (->char-set "opx")))
  379. (pass-if "filter!"
  380. (let ((cs (->char-set "abc")))
  381. (set! cs (char-set-filter! (lambda (c) (char=? c #\x))
  382. (->char-set "qrstuvwxyz")
  383. cs))
  384. (char-set= (string->char-set "abcx")
  385. cs))))
  386. (with-test-prefix "char-set-intersection"
  387. (pass-if "empty"
  388. (char-set= (char-set-intersection (char-set) (char-set))
  389. (char-set)))
  390. (pass-if "identical, one element"
  391. (char-set= (char-set-intersection (char-set #\a) (char-set #\a))
  392. (char-set #\a)))
  393. (pass-if "identical, two elements"
  394. (char-set= (char-set-intersection (char-set #\a #\b) (char-set #\a #\b))
  395. (char-set #\a #\b)))
  396. (pass-if "identical, two elements"
  397. (char-set= (char-set-intersection (char-set #\a #\c) (char-set #\a #\c))
  398. (char-set #\a #\c)))
  399. (pass-if "one vs null"
  400. (char-set= (char-set-intersection (char-set #\a) (char-set))
  401. (char-set)))
  402. (pass-if "null vs one"
  403. (char-set= (char-set-intersection (char-set) (char-set #\a))
  404. (char-set)))
  405. (pass-if "no elements shared"
  406. (char-set= (char-set-intersection (char-set #\a #\c) (char-set #\b #\d))
  407. (char-set)))
  408. (pass-if "one elements shared"
  409. (char-set= (char-set-intersection (char-set #\a #\c #\d) (char-set #\b #\d))
  410. (char-set #\d))))
  411. (with-test-prefix "char-set-complement"
  412. (pass-if "complement of null"
  413. (char-set= (char-set-complement (char-set))
  414. (char-set-union (ucs-range->char-set 0 #xd800)
  415. (ucs-range->char-set #xe000 #x110000))))
  416. (pass-if "complement of null (2)"
  417. (char-set= (char-set-complement (char-set))
  418. (ucs-range->char-set 0 #x110000)))
  419. (pass-if "complement of #\\0"
  420. (char-set= (char-set-complement (char-set #\nul))
  421. (ucs-range->char-set 1 #x110000)))
  422. (pass-if "complement of U+10FFFF"
  423. (char-set= (char-set-complement (char-set (integer->char #x10ffff)))
  424. (ucs-range->char-set 0 #x10ffff)))
  425. (pass-if "complement of 'FOO'"
  426. (char-set= (char-set-complement (->char-set "FOO"))
  427. (char-set-union (ucs-range->char-set 0 (char->integer #\F))
  428. (ucs-range->char-set (char->integer #\G)
  429. (char->integer #\O))
  430. (ucs-range->char-set (char->integer #\P)
  431. #x110000))))
  432. (pass-if "complement of #\\a #\\b U+010300"
  433. (char-set= (char-set-complement (char-set #\a #\b (integer->char #x010300)))
  434. (char-set-union (ucs-range->char-set 0 (char->integer #\a))
  435. (ucs-range->char-set (char->integer #\c) #x010300)
  436. (ucs-range->char-set #x010301 #x110000)))))
  437. (with-test-prefix "ucs-range->char-set"
  438. (pass-if "char-set"
  439. (char-set= (ucs-range->char-set 65 68)
  440. (->char-set "ABC")))
  441. (pass-if "char-set w/ base"
  442. (char-set= (ucs-range->char-set 65 68 #f (->char-set "DEF"))
  443. (->char-set "ABCDEF")))
  444. (pass-if "char-set!"
  445. (let ((cs (->char-set "DEF")))
  446. (ucs-range->char-set! 65 68 #f cs)
  447. (char-set= cs
  448. (->char-set "ABCDEF")))))
  449. (with-test-prefix "char-set-count"
  450. (pass-if "null"
  451. (= 0 (char-set-count (lambda (c) #t) (char-set))))
  452. (pass-if "count"
  453. (= 5 (char-set-count (lambda (c) #t)
  454. (->char-set "guile")))))
  455. (with-test-prefix "char-set-contains?"
  456. (pass-if "#\\a not in null"
  457. (not (char-set-contains? (char-set) #\a)))
  458. (pass-if "#\\a is in 'abc'"
  459. (char-set-contains? (->char-set "abc") #\a)))
  460. (with-test-prefix "any / every"
  461. (pass-if "char-set-every #t"
  462. (char-set-every (lambda (c) #t)
  463. (->char-set "abc")))
  464. (pass-if "char-set-every #f"
  465. (not (char-set-every (lambda (c) (char=? c #\c))
  466. (->char-set "abc"))))
  467. (pass-if "char-set-any #t"
  468. (char-set-any (lambda (c) (char=? c #\c))
  469. (->char-set "abc")))
  470. (pass-if "char-set-any #f"
  471. (not (char-set-any (lambda (c) #f)
  472. (->char-set "abc")))))
  473. (with-test-prefix "char-set-delete"
  474. (pass-if "abc - a"
  475. (char-set= (char-set-delete (->char-set "abc") #\a)
  476. (char-set #\b #\c)))
  477. (pass-if "abc - d"
  478. (char-set= (char-set-delete (->char-set "abc") #\d)
  479. (char-set #\a #\b #\c)))
  480. (pass-if "delete! abc - a"
  481. (let ((cs (char-set #\a #\b #\c)))
  482. (char-set-delete! cs #\a)
  483. (char-set= cs (char-set #\b #\c)))))
  484. (with-test-prefix "char-set-difference"
  485. (pass-if "not different"
  486. (char-set= (char-set-difference (->char-set "foobar") (->char-set "foobar"))
  487. (char-set)))
  488. (pass-if "completely different"
  489. (char-set= (char-set-difference (->char-set "foo") (->char-set "bar"))
  490. (->char-set "foo")))
  491. (pass-if "partially different"
  492. (char-set= (char-set-difference (->char-set "breakfast") (->char-set "breakroom"))
  493. (->char-set "fst"))))
  494. (with-test-prefix "standard char sets (ASCII)"
  495. (pass-if "char-set:lower-case"
  496. (char-set<= (string->char-set "abcdefghijklmnopqrstuvwxyz")
  497. char-set:lower-case))
  498. (pass-if "char-set:upper-case"
  499. (char-set<= (string->char-set "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  500. char-set:upper-case))
  501. (pass-if "char-set:title-case"
  502. (char-set<= (string->char-set "")
  503. char-set:title-case))
  504. (pass-if "char-set:letter"
  505. (char-set<= (char-set-union
  506. (string->char-set "abcdefghijklmnopqrstuvwxyz")
  507. (string->char-set "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
  508. char-set:letter))
  509. (pass-if "char-set:digit"
  510. (char-set<= (string->char-set "0123456789")
  511. char-set:digit))
  512. (pass-if "char-set:hex-digit"
  513. (char-set<= (string->char-set "0123456789abcdefABCDEF")
  514. char-set:hex-digit))
  515. (pass-if "char-set:letter+digit"
  516. (char-set<= (char-set-union
  517. (string->char-set "abcdefghijklmnopqrstuvwxyz")
  518. (string->char-set "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  519. (string->char-set "0123456789"))
  520. char-set:letter+digit))
  521. (pass-if "char-set:punctuation"
  522. (char-set<= (string->char-set "!\"#%&'()*,-./:;?@[\\]_{}")
  523. char-set:punctuation))
  524. (pass-if "char-set:symbol"
  525. (char-set<= (string->char-set "$+<=>^`|~")
  526. char-set:symbol))
  527. (pass-if "char-set:graphic"
  528. (char-set<= (char-set-union
  529. (string->char-set "abcdefghijklmnopqrstuvwxyz")
  530. (string->char-set "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  531. (string->char-set "0123456789")
  532. (string->char-set "!\"#%&'()*,-./:;?@[\\]_{}")
  533. (string->char-set "$+<=>^`|~"))
  534. char-set:graphic))
  535. (pass-if "char-set:whitespace"
  536. (char-set<= (string->char-set
  537. (string
  538. (integer->char #x09)
  539. (integer->char #x0a)
  540. (integer->char #x0b)
  541. (integer->char #x0c)
  542. (integer->char #x0d)
  543. (integer->char #x20)))
  544. char-set:whitespace))
  545. (pass-if "char-set:printing"
  546. (char-set<= (char-set-union
  547. (string->char-set "abcdefghijklmnopqrstuvwxyz")
  548. (string->char-set "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  549. (string->char-set "0123456789")
  550. (string->char-set "!\"#%&'()*,-./:;?@[\\]_{}")
  551. (string->char-set "$+<=>^`|~")
  552. (string->char-set (string
  553. (integer->char #x09)
  554. (integer->char #x0a)
  555. (integer->char #x0b)
  556. (integer->char #x0c)
  557. (integer->char #x0d)
  558. (integer->char #x20))))
  559. char-set:printing))
  560. (pass-if "char-set:ASCII"
  561. (char-set= (ucs-range->char-set 0 128)
  562. char-set:ascii))
  563. (pass-if "char-set:iso-control"
  564. (char-set<= (string->char-set
  565. (apply string
  566. (map integer->char (append
  567. ;; U+0000 to U+001F
  568. (iota #x20)
  569. (list #x7f)))))
  570. char-set:iso-control)))
  571. ;;;
  572. ;;; Non-ASCII codepoints
  573. ;;;
  574. ;;; Here, we only test ISO-8859-1 (Latin-1), notably because behavior of
  575. ;;; SRFI-14 for implementations supporting this charset is well-defined.
  576. ;;;
  577. (define (every? pred lst)
  578. (not (not (every pred lst))))
  579. (when (defined? 'setlocale)
  580. (setlocale LC_ALL ""))
  581. (with-test-prefix "Latin-1 (8-bit charset)"
  582. (pass-if "char-set:lower-case"
  583. (char-set<= (string->char-set
  584. (string-append "abcdefghijklmnopqrstuvwxyz"
  585. "µßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ")
  586. char-set:lower-case)))
  587. (pass-if "char-set:upper-case"
  588. (char-set<= (string->char-set
  589. (string-append "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  590. "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ")
  591. char-set:lower-case)))
  592. (pass-if "char-set:title-case"
  593. (char-set<= (string->char-set "")
  594. char-set:title-case))
  595. (pass-if "char-set:letter"
  596. (char-set<= (string->char-set
  597. (string-append
  598. ;; Lowercase
  599. "abcdefghijklmnopqrstuvwxyz"
  600. "µßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ"
  601. ;; Uppercase
  602. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  603. "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ"
  604. ;; Uncased
  605. "ªº"))
  606. char-set:letter))
  607. (pass-if "char-set:digit"
  608. (char-set<= (string->char-set "0123456789")
  609. char-set:digit))
  610. (pass-if "char-set:hex-digit"
  611. (char-set<= (string->char-set "0123456789abcdefABCDEF")
  612. char-set:hex-digit))
  613. (pass-if "char-set:letter+digit"
  614. (char-set<= (char-set-union
  615. char-set:letter
  616. char-set:digit)
  617. char-set:letter+digit))
  618. (pass-if "char-set:punctuation"
  619. (char-set<= (string->char-set
  620. (string-append "!\"#%&'()*,-./:;?@[\\]_{}"
  621. "¡§«¶·»¿"))
  622. char-set:punctuation))
  623. (pass-if "char-set:symbol"
  624. (char-set<= (string->char-set
  625. (string-append "$+<=>^`|~"
  626. "¢£¤¥¦¨©¬®¯°±´¸×÷"))
  627. char-set:symbol))
  628. ;; Note that SRFI-14 itself is inconsistent here. Characters that
  629. ;; are non-digit numbers (such as category No) are clearly 'graphic'
  630. ;; but don't occur in the letter, digit, punct, or symbol charsets.
  631. (pass-if "char-set:graphic"
  632. (char-set<= (char-set-union
  633. char-set:letter
  634. char-set:digit
  635. char-set:punctuation
  636. char-set:symbol)
  637. char-set:graphic))
  638. (pass-if "char-set:whitespace"
  639. (char-set<= (string->char-set
  640. (string
  641. (integer->char #x09)
  642. (integer->char #x0a)
  643. (integer->char #x0b)
  644. (integer->char #x0c)
  645. (integer->char #x0d)
  646. (integer->char #x20)
  647. (integer->char #xa0)))
  648. char-set:whitespace))
  649. (pass-if "char-set:printing"
  650. (char-set<= (char-set-union char-set:graphic char-set:whitespace)
  651. char-set:printing))
  652. (pass-if "char-set:iso-control"
  653. (char-set<= (string->char-set
  654. (apply string
  655. (map integer->char (append
  656. ;; U+0000 to U+001F
  657. (iota #x20)
  658. (list #x7f)
  659. ;; U+007F to U+009F
  660. (map (lambda (x) (+ #x80 x))
  661. (iota #x20))))))
  662. char-set:iso-control)))