New feature: toggle visibility of mime buttons.
[more-wl.git] / tests / test-elmo-util.el
blob2d5a5e125081671f8e5d865be0a2aeaf46101629
1 (require 'lunit)
2 (require 'elmo-util)
4 (luna-define-class test-elmo-util (lunit-test-case))
6 ;; setup & teardown
7 (defvar test-elmo-temoporary-file)
9 (luna-define-method lunit-test-case-setup ((case test-elmo-util))
10 (setq test-elmo-temoporary-file
11 (make-temp-file temporary-file-directory)))
13 (luna-define-method lunit-test-case-teardown ((case test-elmo-util))
14 (when (file-exists-p test-elmo-temoporary-file)
15 (delete-file test-elmo-temoporary-file)))
18 (luna-define-method test-elmo-replace-string-as-filename-1 ((case test-elmo-util))
19 "Revert checking replace and recover."
20 (lunit-assert
21 (let ((str "/foo//./../bar/"))
22 (string= str
23 (elmo-recover-string-from-filename
24 (elmo-replace-string-as-filename str))))))
27 ;; object save & load
28 (luna-define-method test-elmo-object-save-1 ((case test-elmo-util))
29 "Check `print-length' let bindings."
30 (let ((list '(1 2 3 4 5 6 7 8 9 10 11 12))
31 (print-length 1))
32 (elmo-object-save test-elmo-temoporary-file list)
33 (lunit-assert
34 (equal list
35 (elmo-object-load test-elmo-temoporary-file)))))
37 (luna-define-method test-elmo-object-save-2 ((case test-elmo-util))
38 "Check `print-level' let bindings."
39 (let ((list '(1 (2 :foo (nil . :bar))))
40 (print-level 1))
41 (elmo-object-save test-elmo-temoporary-file list)
42 (lunit-assert
43 (equal list
44 (elmo-object-load test-elmo-temoporary-file)))))
46 (luna-define-method test-elmo-save-string-1 ((case test-elmo-util))
49 ;; list functions
50 (luna-define-method test-elmo-uniq-list-1 ((case test-elmo-util))
51 (lunit-assert
52 (eq nil (elmo-uniq-list nil)))
53 (lunit-assert
54 (equal '(1) (elmo-uniq-list '(1))))
55 (lunit-assert
56 (equal '(1) (elmo-uniq-list '(1 1))))
57 (lunit-assert
58 (equal '(1) (elmo-uniq-list '(1 1 1)))))
60 (luna-define-method test-elmo-uniq-list-2 ((case test-elmo-util))
61 (lunit-assert
62 (equal '(1 2 3 4 5 6 nil)
63 (elmo-uniq-list '(1 2 3 4 1 5 6 nil nil 1 1 2))))
64 (lunit-assert
65 (equal '("foo") (elmo-uniq-list '("foo" "foo")))))
67 (luna-define-method test-elmo-uniq-list-3 ((case test-elmo-util))
68 "Check using DELETE-FUNCTION"
69 (lunit-assert
70 (equal '("foo" "foo") (elmo-uniq-list '("foo" "foo") #'delq)))
71 (lunit-assert
72 (equal '(:foo) (elmo-uniq-list '(:foo :foo) #'delq))))
74 (luna-define-method test-elmo-list-insert-1 ((case test-elmo-util))
75 (lunit-assert
76 (equal '(1 2 3 4 5)
77 (elmo-list-insert '(1 2 3 5) 4 3)))
78 (lunit-assert
79 (equal '(1 2 3 5 9)
80 (elmo-list-insert '(1 2 3 5) 9 :notfound)))
81 ;;; memq vs. member
82 ;;; (equal '(1 2 "3" 5 4)
83 ;;; (elmo-list-insert '(1 2 "3" 5) 4 "3"))
86 (luna-define-method test-elmo-list-insert-2 ((case test-elmo-util))
87 "Check not copied"
88 (let* ((list1 '(1 2 3 4 5))
89 (list2 list1))
90 (elmo-list-insert list1 4 3)
91 (lunit-assert
92 (eq list1 list2))))
93 ;;; memq vs. member
94 ;;; (equal '(1 2 "3" 5 4)
95 ;;; (elmo-list-insert '(1 2 "3" 5) 4 "3"))
97 (defun test-elmo-same-list-p (list1 list2)
98 (let ((clist1 (copy-sequence list1))
99 (clist2 (copy-sequence list2)))
100 (while list2
101 (setq clist1 (delq (car list2) clist1))
102 (setq list2 (cdr list2)))
103 (while list1
104 (setq clist2 (delq (car list1) clist2))
105 (setq list1 (cdr list1)))
106 (equal (list clist1 clist2) '(nil nil))))
108 (defun test-elmo-same-diff-p (diff1 diff2)
109 (and (test-elmo-same-list-p (car diff1)
110 (car diff2))
111 (test-elmo-same-list-p (nth 1 diff1)
112 (nth 1 diff2))))
114 (luna-define-method test-elmo-list-diff ((case test-elmo-util))
115 (let ((list1 '(1 2 3))
116 (list2 '(1 2 3 4))
117 (list3 '(1 2 4))
118 (list4 '(4 5 6))
119 (list5 '(3 4 5 6)))
120 (lunit-assert
121 (test-elmo-same-diff-p '(nil nil)
122 (elmo-list-diff nil nil)))
123 (lunit-assert
124 (test-elmo-same-diff-p '(nil (1 2 3))
125 (elmo-list-diff nil list1)))
126 (lunit-assert
127 (test-elmo-same-diff-p '((1 2 3) nil)
128 (elmo-list-diff list1 nil)))
129 (lunit-assert
130 (test-elmo-same-diff-p '(nil nil)
131 (elmo-list-diff list1 list1)))
132 (lunit-assert
133 (test-elmo-same-diff-p '(nil (4))
134 (elmo-list-diff list1 list2)))
135 (lunit-assert
136 (test-elmo-same-diff-p '((3) (4))
137 (elmo-list-diff list1 list3)))
138 (lunit-assert
139 (test-elmo-same-diff-p '((1 2 3) (4 5 6))
140 (elmo-list-diff list1 list4)))
141 (lunit-assert
142 (test-elmo-same-diff-p '((1 2) (5 6))
143 (elmo-list-diff list3 list4)))
144 (lunit-assert
145 (test-elmo-same-diff-p '((1 2) (3 5 6))
146 (elmo-list-diff list3 list5)))))
148 (luna-define-method test-elmo-delete-char-1 ((case test-elmo-util))
149 (lunit-assert
150 (string= "f" (elmo-delete-char ?o "foo")))
151 (lunit-assert
152 (string= "f\nf" (elmo-delete-char ?o "foo\nfoo")))
153 (lunit-assert
154 (string= "" (elmo-delete-char ?o "oo")))
155 (lunit-assert
156 (string= "" (elmo-delete-char ?o ""))))
158 (luna-define-method test-elmo-concat-path-1 ((case test-elmo-util))
159 (lunit-assert
160 (string=
161 "/home/foo"
162 (elmo-concat-path "/home" "foo")))
163 (lunit-assert
164 (string=
165 (elmo-concat-path "/home/" "foo")
166 (elmo-concat-path "/home//" "foo"))))
169 (luna-define-method test-elmo-remove-passwd-1 ((case test-elmo-util))
170 "Check shred password."
171 (let* ((password "cGFzc3dk")
172 (elmo-passwd-alist (list (cons "key" password))))
173 (elmo-remove-passwd "key")
174 (lunit-assert
175 (string= "\0\0\0\0\0\0\0\0" password))))
177 (luna-define-method test-elmo-remove-passwd-2 ((case test-elmo-util))
178 "Check remove target pair only. Not rassoc."
179 (let ((password "cGFzc3dk")
180 (elmo-passwd-alist '(("foo" . "key")
181 ("key" . "ok")
182 ("bar" . "baz"))))
183 (elmo-remove-passwd "key")
184 (lunit-assert
185 (equal '(("foo" . "key")
186 ("bar" . "baz"))
187 elmo-passwd-alist))))
189 (luna-define-method test-elmo-remove-passwd-3 ((case test-elmo-util))
190 "Multiple same key."
191 (let ((password "cGFzc3dk")
192 (elmo-passwd-alist '(("foo" . "key")
193 ("key" . "ok")
194 ("key" . "ok2")
195 ("bar" . "baz"))))
196 (elmo-remove-passwd "key")
197 (lunit-assert
198 (equal '(("foo" . "key")
199 ("bar" . "baz"))
200 elmo-passwd-alist))))
202 (luna-define-method test-elmo-passwd-alist-clear-1 ((case test-elmo-util))
203 "Check shred ALL password."
204 (let* ((password1 "cGFzc3dk")
205 (password2 (copy-sequence password1))
206 (elmo-passwd-alist (list (cons "key1" password1)
207 (cons "key2" password2))))
208 (elmo-passwd-alist-clear)
209 (lunit-assert
210 (string= "\0\0\0\0\0\0\0\0" password1))
211 (lunit-assert
212 (string= "\0\0\0\0\0\0\0\0" password2))))
214 (luna-define-method test-elmo-address-quote-specials-1 ((case test-elmo-util))
216 (lunit-assert
217 (string= "\"dot.atom.text\""
218 (elmo-address-quote-specials "dot.atom.text")))
219 (lunit-assert
220 (string= "\"...\""
221 (elmo-address-quote-specials "..."))))
223 (luna-define-method test-elmo-address-quote-specials-2 ((case test-elmo-util))
225 (lunit-assert
226 (string=
227 "atext!#$%&'*+-/=?^_`{|}~"
228 (elmo-address-quote-specials "atext!#$%&'*+-/=?^_`{|}~"))))
230 (luna-define-method test-elmo-elmo-flatten-1 ((case test-elmo-util))
232 (lunit-assert
233 (equal
234 '(1 2 3 4 5)
235 (elmo-flatten '(1 2 (3 4 5))))))
237 (luna-define-method test-elmo-number-set-member-1 ((case test-elmo-util))
238 "Check edge."
239 (lunit-assert
240 (equal '((1 . 99))
241 (elmo-number-set-member 1 '((1 . 99)))))
242 (lunit-assert
243 (equal '((1 . 99))
244 (elmo-number-set-member 99 '((1 . 99))))))
246 (luna-define-method test-elmo-number-set-member-2 ((case test-elmo-util))
247 "Check edge."
248 (lunit-assert
249 (null (elmo-number-set-member 0 '((1 . 99)))))
250 (lunit-assert
251 (null (elmo-number-set-member 100 '((1 . 99))))))
253 (luna-define-method test-elmo-number-set-append-list-1 ((case test-elmo-util))
254 "Simple testcase."
255 (lunit-assert
256 (equal '((1 . 100))
257 (elmo-number-set-append-list '((1 . 99)) '(100)))))
259 (luna-define-method test-elmo-number-set-append-1 ((case test-elmo-util))
260 "Simple testcase."
261 (lunit-assert
262 (equal '((1 . 100))
263 (elmo-number-set-append '((1 . 99)) 100))))
265 (luna-define-method test-elmo-number-set-delete-1 ((case test-elmo-util))
266 "Check edge."
267 (lunit-assert
268 (equal '(2 3)
269 (elmo-number-set-delete '(1 2 3) 1))))
271 (luna-define-method test-elmo-number-set-delete-2 ((case test-elmo-util))
272 "Normal case."
273 (lunit-assert
274 (equal '(1 3)
275 (elmo-number-set-delete '(1 2 3) 2))))
277 (luna-define-method test-elmo-number-set-delete-3 ((case test-elmo-util))
278 "Check edge."
279 (lunit-assert
280 (equal '(1 2)
281 (elmo-number-set-delete '(1 2 3) 3))))
283 (luna-define-method test-elmo-number-set-delete-4 ((case test-elmo-util))
284 "Check edge."
285 (lunit-assert
286 (equal '((2 . 100))
287 (elmo-number-set-delete '((1 . 100)) 1))))
289 (luna-define-method test-elmo-number-set-delete-5 ((case test-elmo-util))
290 "Check edge."
291 (lunit-assert
292 (equal '(1 (3 . 100))
293 (elmo-number-set-delete '((1 . 100)) 2))))
295 (luna-define-method test-elmo-number-set-delete-6 ((case test-elmo-util))
296 "Normal case."
297 (lunit-assert
298 (equal '((1 . 49) (51 . 100))
299 (elmo-number-set-delete '((1 . 100)) 50))))
301 (luna-define-method test-elmo-number-set-delete-7 ((case test-elmo-util))
302 "Check edge."
303 (lunit-assert
304 (equal '((1 . 98) 100)
305 (elmo-number-set-delete '((1 . 100)) 99))))
307 (luna-define-method test-elmo-number-set-delete-8 ((case test-elmo-util))
308 "Check edge."
309 (lunit-assert
310 (equal '((1 . 99))
311 (elmo-number-set-delete '((1 . 100)) 100))))
313 (luna-define-method test-elmo-number-set-delete-list-1 ((case test-elmo-util))
314 "Simple testcase."
315 (lunit-assert
316 (equal '((1 . 99))
317 (elmo-number-set-delete-list '((1 . 100)) '(100)))))
319 (luna-define-method test-elmo-number-set-to-number-list-1 ((case test-elmo-util))
320 "Simple testcase."
321 (lunit-assert
322 (equal '(1 2 3 4 5 6 7 8 9)
323 (elmo-number-set-to-number-list '((1 . 9)))))
324 (lunit-assert
325 (equal '(1)
326 (elmo-number-set-to-number-list '(1)))))