4 (luna-define-class test-elmo-util
(lunit-test-case))
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."
21 (let ((str "/foo//./../bar/"))
23 (elmo-recover-string-from-filename
24 (elmo-replace-string-as-filename str
))))))
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))
32 (elmo-object-save test-elmo-temoporary-file 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
))))
41 (elmo-object-save test-elmo-temoporary-file list
)
44 (elmo-object-load test-elmo-temoporary-file
)))))
46 (luna-define-method test-elmo-save-string-1
((case test-elmo-util
))
50 (luna-define-method test-elmo-uniq-list-1
((case test-elmo-util
))
52 (eq nil
(elmo-uniq-list nil
)))
54 (equal '(1) (elmo-uniq-list '(1))))
56 (equal '(1) (elmo-uniq-list '(1 1))))
58 (equal '(1) (elmo-uniq-list '(1 1 1)))))
60 (luna-define-method test-elmo-uniq-list-2
((case test-elmo-util
))
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))))
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"
70 (equal '("foo" "foo") (elmo-uniq-list '("foo" "foo") #'delq
)))
72 (equal '(:foo
) (elmo-uniq-list '(:foo
:foo
) #'delq
))))
74 (luna-define-method test-elmo-list-insert-1
((case test-elmo-util
))
77 (elmo-list-insert '(1 2 3 5) 4 3)))
80 (elmo-list-insert '(1 2 3 5) 9 :notfound
)))
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
))
88 (let* ((list1 '(1 2 3 4 5))
90 (elmo-list-insert list1
4 3)
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
)))
101 (setq clist1
(delq (car list2
) clist1
))
102 (setq list2
(cdr list2
)))
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
)
111 (test-elmo-same-list-p (nth 1 diff1
)
114 (luna-define-method test-elmo-list-diff
((case test-elmo-util
))
115 (let ((list1 '(1 2 3))
121 (test-elmo-same-diff-p '(nil nil
)
122 (elmo-list-diff nil nil
)))
124 (test-elmo-same-diff-p '(nil (1 2 3))
125 (elmo-list-diff nil list1
)))
127 (test-elmo-same-diff-p '((1 2 3) nil
)
128 (elmo-list-diff list1 nil
)))
130 (test-elmo-same-diff-p '(nil nil
)
131 (elmo-list-diff list1 list1
)))
133 (test-elmo-same-diff-p '(nil (4))
134 (elmo-list-diff list1 list2
)))
136 (test-elmo-same-diff-p '((3) (4))
137 (elmo-list-diff list1 list3
)))
139 (test-elmo-same-diff-p '((1 2 3) (4 5 6))
140 (elmo-list-diff list1 list4
)))
142 (test-elmo-same-diff-p '((1 2) (5 6))
143 (elmo-list-diff list3 list4
)))
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
))
150 (string= "f" (elmo-delete-char ?o
"foo")))
152 (string= "f\nf" (elmo-delete-char ?o
"foo\nfoo")))
154 (string= "" (elmo-delete-char ?o
"oo")))
156 (string= "" (elmo-delete-char ?o
""))))
158 (luna-define-method test-elmo-concat-path-1
((case test-elmo-util
))
162 (elmo-concat-path "/home" "foo")))
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")
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")
183 (elmo-remove-passwd "key")
185 (equal '(("foo" .
"key")
187 elmo-passwd-alist
))))
189 (luna-define-method test-elmo-remove-passwd-3
((case test-elmo-util
))
191 (let ((password "cGFzc3dk")
192 (elmo-passwd-alist '(("foo" .
"key")
196 (elmo-remove-passwd "key")
198 (equal '(("foo" .
"key")
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)
210 (string= "\0\0\0\0\0\0\0\0" password1
))
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
))
217 (string= "\"dot.atom.text\""
218 (elmo-address-quote-specials "dot.atom.text")))
221 (elmo-address-quote-specials "..."))))
223 (luna-define-method test-elmo-address-quote-specials-2
((case test-elmo-util
))
227 "atext!#$%&'*+-/=?^_`{|}~"
228 (elmo-address-quote-specials "atext!#$%&'*+-/=?^_`{|}~"))))
230 (luna-define-method test-elmo-elmo-flatten-1
((case test-elmo-util
))
235 (elmo-flatten '(1 2 (3 4 5))))))
237 (luna-define-method test-elmo-number-set-member-1
((case test-elmo-util
))
241 (elmo-number-set-member 1 '((1 .
99)))))
244 (elmo-number-set-member 99 '((1 .
99))))))
246 (luna-define-method test-elmo-number-set-member-2
((case test-elmo-util
))
249 (null (elmo-number-set-member 0 '((1 .
99)))))
251 (null (elmo-number-set-member 100 '((1 .
99))))))
253 (luna-define-method test-elmo-number-set-append-list-1
((case test-elmo-util
))
257 (elmo-number-set-append-list '((1 .
99)) '(100)))))
259 (luna-define-method test-elmo-number-set-append-1
((case test-elmo-util
))
263 (elmo-number-set-append '((1 .
99)) 100))))
265 (luna-define-method test-elmo-number-set-delete-1
((case test-elmo-util
))
269 (elmo-number-set-delete '(1 2 3) 1))))
271 (luna-define-method test-elmo-number-set-delete-2
((case test-elmo-util
))
275 (elmo-number-set-delete '(1 2 3) 2))))
277 (luna-define-method test-elmo-number-set-delete-3
((case test-elmo-util
))
281 (elmo-number-set-delete '(1 2 3) 3))))
283 (luna-define-method test-elmo-number-set-delete-4
((case test-elmo-util
))
287 (elmo-number-set-delete '((1 .
100)) 1))))
289 (luna-define-method test-elmo-number-set-delete-5
((case test-elmo-util
))
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
))
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
))
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
))
311 (elmo-number-set-delete '((1 .
100)) 100))))
313 (luna-define-method test-elmo-number-set-delete-list-1
((case test-elmo-util
))
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
))
322 (equal '(1 2 3 4 5 6 7 8 9)
323 (elmo-number-set-to-number-list '((1 .
9)))))
326 (elmo-number-set-to-number-list '(1)))))