-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-cset.scm
117 lines (87 loc) · 3.9 KB
/
test-cset.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
;; Test of the internal character-set API. This is here so we can switch
;; representation of csets more easily.
;;; Some of these are based on Olin Shivers' SRFI 14 tests
;; (use test extras utils irregex)
;; (load "irregex.scm")
(define (vowel? c) (member c '(#\a #\e #\i #\o #\u)))
(test-begin "test-cset")
(test-assert
(cset=? (plist->cset '(#\a #\a #\e #\e #\i #\i #\o #\o #\u #\u))
(string->cset "ioeauaiii")))
(test (plist->cset '(#\x #\y)) (string->cset "xy"))
(test-assert (not (cset=? (plist->cset '(#\x #\x #\y #\y #\z #\z))
(string->cset "xy"))))
(test-assert (not (cset=? (plist->cset '(#\x #\z))
(string->cset "xy"))))
(test-assert
(cset=? (string->cset "abcdef12345")
(cset-union (range->cset (integer->char 97) (integer->char 102))
(string->cset "12345"))))
(test-assert
(cset=? (range->cset #\d #\j)
(cset-union (plist->cset '(#\d #\f #\h #\j))
(string->cset "g"))))
(test-assert
(cset=? (range->cset #\d #\j)
(cset-union (string->cset "g")
(plist->cset '(#\d #\f #\h #\j)))))
(test-assert
(not (cset=? (string->cset "abcef12345") ; without the 'd'
(cset-union (range->cset (integer->char 97) (integer->char 102))
(string->cset "12345")))))
(test 10 (cset-size (cset-intersection (sre->cset 'ascii) (sre->cset 'digit))))
(test '(#\x #\x) (cset->plist (plist->cset '(#\x #\x))))
(test-assert (not (equal? '(#\X #\X) (cset->plist (plist->cset '(#\x #\x))))))
(test '(#\a #\d #\x #\z) (cset->plist (plist->cset '(#\a #\d #\x #\z))))
(test-assert (cset-contains? (string->cset "xyz") #\x))
(test-assert (not (cset-contains? (string->cset "xyz") #\a)))
(test-assert (cset-contains? (range->cset #\x #\z) #\x))
(test-assert (not (cset-contains? (range->cset #\x #\z) #\a)))
(let ((cs (plist->cset '(#\a #\c #\h #\j #\l #\l #\n #\n))))
(test-assert (cset-contains? cs #\a))
(test-assert (cset-contains? cs #\b))
(test-assert (cset-contains? cs #\c))
(test-assert (not (cset-contains? cs #\d)))
(test-assert (cset-contains? cs #\h))
(test-assert (cset-contains? cs #\i))
(test-assert (cset-contains? cs #\j))
(test-assert (not (cset-contains? cs #\k)))
(test-assert (cset-contains? cs #\l))
(test-assert (not (cset-contains? cs #\m)))
(test-assert (cset-contains? cs #\n)))
(let ((cs (plist->cset '(#\a #\c #\l #\l #\n #\n))))
(test-assert (cset-contains? cs #\a))
(test-assert (cset-contains? cs #\b))
(test-assert (cset-contains? cs #\c))
(test-assert (not (cset-contains? cs #\d)))
(test-assert (not (cset-contains? cs #\k)))
(test-assert (cset-contains? cs #\l))
(test-assert (not (cset-contains? cs #\m)))
(test-assert (cset-contains? cs #\n)))
(test-assert
(cset=? (plist->cset '(#\a #\c #\l #\l #\n #\n))
(cset-intersection (plist->cset '(#\a #\c #\l #\l #\n #\n))
(plist->cset '(#\a #\e #\h #\l #\n #\p)))))
(test-assert
(cset=? (plist->cset '(#\b #\b #\l #\l #\n #\n))
(cset-intersection (plist->cset '(#\a #\c #\h #\l #\n #\n))
(plist->cset '(#\b #\b #\l #\l #\n #\n)))))
(test-assert
(cset=? (cset-intersection (sre->cset 'hex-digit)
(cset-complement (sre->cset 'digit)))
(string->cset "abcdefABCDEF")))
(test-assert
(cset=? (cset-union (sre->cset 'hex-digit)
(string->cset "abcdefghijkl"))
(string->cset "abcdefABCDEFghijkl0123456789")))
(test-assert
(cset=? (cset-difference (string->cset "abcdefghijklmn")
(sre->cset 'hex-digit))
(string->cset "ghijklmn")))
(test-assert
(cset=? (string->cset "0123456789")
(cset-difference (sre->cset 'hex-digit) (sre->cset 'alpha))))
(test-assert
(cset=? (string->cset "abcdefABCDEF")
(cset-intersection (sre->cset 'hex-digit) (sre->cset 'alpha))))
(test-end)