1 ;; run with `emacs --batch --script test.el'
5 (add-to-list 'load-path
6 (expand-file-name "ert"
7 (file-name-directory load-file-name
))))
13 (cons (expand-file-name ".."
14 (file-name-directory load-file-name
))
16 (require 'navi2ch-util
)
17 (require 'navi2ch-http-date
)
18 (require 'navi2ch-net
)
19 (require 'navi2ch-thumbnail
)
23 (ert-deftest replace-html-tag
()
25 (navi2ch-replace-html-tag
26 " <a href=\"../test/read.cgi/***/***/***\" target=\"_blank\">>>139</a> <br> foo")
29 (ert-deftest http-date-test-1
()
30 (let ((expected "Sun, 06 Nov 1994 08:49:37 GMT"))
31 (should (string= expected
(navi2ch-http-date-encode
32 (navi2ch-http-date-decode
33 "Sun, 06 Nov 1994 08:49:37 GMT"))))))
34 (ert-deftest http-date-test-2
()
35 (let ((expected "Sun, 06 Nov 1994 08:49:37 GMT"))
36 (should (string= expected
(navi2ch-http-date-encode
37 (navi2ch-http-date-decode
38 "Sunday, 06-Nov-94 08:49:37 GMT"))))))
39 (ert-deftest http-date-test-3
()
40 (let ((expected "Sun, 06 Nov 1994 08:49:37 GMT"))
41 (should (string= expected
(navi2ch-http-date-encode
42 (navi2ch-http-date-decode
43 "Sun Nov 6 08:49:37 1994"))))))
45 (ert-deftest tanpan-check-1
()
46 (should (navi2ch-net-is-tanpan-thread-p
47 "短パンマン ★<><>2010/09/15 01:09:42 ID:TanpanM<>いろいろあるさ @bg r.so ver 2008/02/19<br>ERROR = 5656 <br>(e_mes = []) <br> <>名古屋はエ〜エ〜で ♪
50 (ert-deftest thumbnail-save-good-work
()
51 (let* ((workdir (make-temp-file "workdir." t
))
52 (fileFoo (expand-file-name "foo" workdir
))
53 (fileBar (expand-file-name "bar" workdir
)))
56 (with-temp-file fileFoo
(insert "foo"))
58 (navi2ch-thumbnail-save-content fileFoo fileBar
)
60 (string= (with-temp-buffer (insert-file-contents fileBar
) (buffer-string))
62 (with-temp-file fileBar
(insert "bar"))
64 (navi2ch-thumbnail-save-content fileFoo fileBar t
)
66 (string= (with-temp-buffer (insert-file-contents fileBar
) (buffer-string))
68 (delete-directory workdir t
))))
70 (ert-deftest thumbnail-save-interactive-check
()
71 (let ((si:read-file-name
(symbol-function 'read-file-name
))
75 (fset 'read-file-name
(lambda (a b c
)
76 (expand-file-name (or c
"hoge") b
)))
77 (lexical-let ((evalform (cadr (interactive-form 'navi2ch-thumbnail-save-content
))))
78 (fset 'intform
(lambda () (eval evalform
))))
80 ;; prop `navi2ch-link' から読みだす。読みだせないとエラー。
81 (should-error (intform))
82 (save-excursion (insert (propertize "foo" 'navi2ch-link
"foobar")))
83 (let ((res (intform)))
84 (should (equal res
(list "foobar"
85 (expand-file-name "hoge"
86 navi2ch-thumbnail-save-content-dir
)
88 (put-text-property (point-min) (point-max) 'file-name
"barbaz")
89 (let ((res (intform)))
90 (should (equal res
(list "foobar"
91 (expand-file-name "barbaz"
92 navi2ch-thumbnail-save-content-dir
)
94 (fset 'read-file-name si
:read-file-name
))))
96 (ert-deftest thumbnail-save-file-invalid
()
97 (let* ((workdir (make-temp-file "workdir." t
))
98 (fileFoo (expand-file-name "foo" workdir
))
99 (fileBar (expand-file-name "bar" workdir
)))
104 (navi2ch-thumbnail-save-content fileFoo fileBar
))
106 (with-temp-file fileFoo
(insert "foo"))
107 (with-temp-file fileBar
(insert "bar"))
110 (navi2ch-thumbnail-save-content fileFoo fileBar
)))
111 (delete-directory workdir t
))))
113 (ert-deftest thumbnail-save-invalid-argument
()
115 (let* ((workdir (make-temp-file "workdir." t
))
116 (fileFoo (expand-file-name "foo" workdir
)))
120 (navi2ch-thumbnail-save-content nil nil
))
122 (navi2ch-thumbnail-save-content nil fileFoo
))
124 (navi2ch-thumbnail-save-content fileFoo nil
)))
125 (delete-directory workdir t
))))
127 (ert-deftest thumbnail-save-same-file
()
129 (let* ((workdir (make-temp-file "workdir." t
))
130 (file (expand-file-name "foo" workdir
)))
133 (with-temp-file file
(insert "foo"))
135 (navi2ch-thumbnail-save-content file file t
))
137 (navi2ch-thumbnail-save-content file file nil
)))
138 (delete-directory workdir t
))))
140 (ert-deftest bm-sort-by-number
()
144 (insert "1\n1000\n2\n 12\n")
145 (navi2ch-bm-sort-by-number)
146 (buffer-substring-no-properties (point-min) (point-max))))))
150 (ert-run-tests-batch)