1 ;; test.el -*- coding: iso-2022-jp; lexical-binding: t; -*-
2 ;; run with `emacs --batch -q -l ert -l test.el --eval "(ert-run-tests-batch-and-exit)"
4 (require 'navi2ch-rfc3986
)
5 (require 'navi2ch-util
)
6 (require 'navi2ch-board-misc
)
7 (require 'navi2ch-http-date
)
9 (require 'navi2ch-thumbnail
)
10 (require 'navi2ch-multibbs
)
14 (ert-deftest replace-html-tag
()
16 (navi2ch-replace-html-tag
17 " <a href=\"../test/read.cgi/***/***/***\" target=\"_blank\">>>139</a> <br> foo")
20 (ert-deftest http-date-test-1
()
21 (let ((expected "Sun, 06 Nov 1994 08:49:37 GMT"))
22 (should (string= expected
(navi2ch-http-date-encode
23 (navi2ch-http-date-decode
24 "Sun, 06 Nov 1994 08:49:37 GMT"))))))
25 (ert-deftest http-date-test-2
()
26 (let ((expected "Sun, 06 Nov 1994 08:49:37 GMT"))
27 (should (string= expected
(navi2ch-http-date-encode
28 (navi2ch-http-date-decode
29 "Sunday, 06-Nov-94 08:49:37 GMT"))))))
30 (ert-deftest http-date-test-3
()
31 (let ((expected "Sun, 06 Nov 1994 08:49:37 GMT"))
32 (should (string= expected
(navi2ch-http-date-encode
33 (navi2ch-http-date-decode
34 "Sun Nov 6 08:49:37 1994"))))))
36 (ert-deftest tanpan-check-1
()
37 (should (navi2ch-net-is-tanpan-thread-p
38 "\e$BC;%Q%s%^%s\e(B \e$B!z\e(B<><>2010/09/15 01:09:42 ID:TanpanM<>\e$B$$$m$$$m$"$k$
5\e(B \e$B
!w
\e(Bbg r.so ver
2008/02/19<br
>ERROR
= 5656 <br
>(e_mes = []) <br
> <>\e$BL
>8E20$O%
(!A%
(!A$G
\e(B \e$B
"v\e(B
41 (ert-deftest thumbnail-save-good-work
()
42 (let* ((workdir (make-temp-file "workdir." t
))
43 (fileFoo (expand-file-name "foo" workdir
))
44 (fileBar (expand-file-name "bar" workdir
)))
47 (with-temp-file fileFoo
(insert "foo"))
49 (navi2ch-thumbnail-save-content fileFoo fileBar
)
51 (string= (with-temp-buffer (insert-file-contents fileBar
) (buffer-string))
53 (with-temp-file fileBar
(insert "bar"))
55 (navi2ch-thumbnail-save-content fileFoo fileBar t
)
57 (string= (with-temp-buffer (insert-file-contents fileBar
) (buffer-string))
59 (delete-directory workdir t
))))
61 (ert-deftest thumbnail-save-interactive-check
()
62 (cl-flet ((intform `(lambda () ,(cadr (interactive-form 'navi2ch-thumbnail-save-content
))))
63 (org:expand-file-name
(symbol-function 'expand-file-name
)))
64 (cl-letf (((symbol-function 'read-file-name
)
65 (lambda (prompt &optional dir default-filename
)
66 (org:expand-file-name default-filename dir
)))
67 ((symbol-function 'expand-file-name
)
68 (lambda (name &optional default-directory
)
69 (org:expand-file-name
(or name
"hoge") default-directory
))))
72 ;; prop `navi2ch-link' \e$B$+$iFI$_$@$9!#FI$_$@$;$J$$$H%(%i!<!#\e(B
73 (should-error (intform))
74 (save-excursion (insert (propertize "foo" 'navi2ch-link
"foobar")))
75 (let ((res (intform)))
76 (should (equal res
(list "foobar"
77 (expand-file-name "hoge"
78 navi2ch-thumbnail-save-content-dir
)
80 (put-text-property (point-min) (point-max) 'file-name
"barbaz")
81 (let ((res (intform)))
82 (should (equal res
(list "foobar"
83 (expand-file-name "barbaz"
84 navi2ch-thumbnail-save-content-dir
)
87 (ert-deftest thumbnail-save-file-invalid
()
88 (let* ((workdir (make-temp-file "workdir." t
))
89 (fileFoo (expand-file-name "foo" workdir
))
90 (fileBar (expand-file-name "bar" workdir
)))
93 ;; \e$B%U%!%$%k$,$J$$\e(B
95 (navi2ch-thumbnail-save-content fileFoo fileBar
))
96 ;; \e$B%U%!%$%k$,=q$-$3$_$G$-$J$$\e(B
97 (with-temp-file fileFoo
(insert "foo"))
98 (with-temp-file fileBar
(insert "bar"))
101 (navi2ch-thumbnail-save-content fileFoo fileBar
)))
102 (delete-directory workdir t
))))
104 (ert-deftest thumbnail-save-invalid-argument
()
105 ;; \e$BL58z$J0z?t\e(B
106 (let* ((workdir (make-temp-file "workdir." t
))
107 (fileFoo (expand-file-name "foo" workdir
)))
111 (navi2ch-thumbnail-save-content nil nil
))
113 (navi2ch-thumbnail-save-content nil fileFoo
))
115 (navi2ch-thumbnail-save-content fileFoo nil
)))
116 (delete-directory workdir t
))))
118 (ert-deftest thumbnail-save-same-file
()
119 ;; \e$BF1$8%U%!%$%k\e(B
120 (let* ((workdir (make-temp-file "workdir." t
))
121 (file (expand-file-name "foo" workdir
)))
124 (with-temp-file file
(insert "foo"))
126 (navi2ch-thumbnail-save-content file file t
))
128 (navi2ch-thumbnail-save-content file file nil
)))
129 (delete-directory workdir t
))))
131 (ert-deftest bm-sort-by-number
()
135 (insert "1\n1000\n2\n 12\n")
136 (navi2ch-bm-sort-by-number)
137 (buffer-substring-no-properties (point-min) (point-max))))))
139 (ert-deftest 2ch-url-to-board
()
140 (let ((datas '(("http://greta.5ch.net/poverty/oyster/1697/1697461053.dat" .
141 ((uri .
"http://greta.5ch.net/poverty/") (id .
"poverty")))
142 ("http://pc.2ch.net/unix/kako/999/999166513.html" .
143 ((uri .
"http://pc.2ch.net/unix/") (id .
"unix"))))))
145 (should (equal (cdr x
)
146 (navi2ch-2ch-url-to-board (car x
)))))))
148 (ert-deftest 2ch-url-to-article
()
149 (let ((datas '(("http://greta.5ch.net/poverty/oyster/1697/1697461053.dat" .
150 ((kako . t
) (artid .
"1697461053")))
151 ("http://pc.2ch.net/unix/kako/999/999166513.html" .
152 ((kako . t
) (artid .
"999166513"))))))
154 (should (equal (cdr x
)
155 (navi2ch-2ch-url-to-article (car x
)))))))
157 (ert-deftest util-replace-html-tag
()
159 (list (cons "<a href=\"//localhost/hoge.html\">abc</a>" "abc")
163 (cons "あ" (char-to-string 12354)) ; hiragana A
164 (cons "Α" (char-to-string 913))
165 (cons "α" (char-to-string 945))
166 ; \e$B%;%_%3%m%s$G=*N;$7$F$$$J$$$N$GJQ49$7$J$$\e(B
167 ; \e$B%P%C%U%!$N%F%9%H$GO"7k$9$k$N$G:G8e$K$*$/\e(B
168 (cons "&alpha" "&alpha"))))
171 (should (string= (navi2ch-replace-html-tag (car pair
)) (cdr pair
))))
174 (insert (mapconcat (lambda (pair) (car pair
)) datas
"; "))
175 (navi2ch-replace-html-tag-with-buffer)
177 (mapconcat (lambda (pair) (cdr pair
)) datas
"; ")))))
179 (ert-deftest thumbnail-image-escape-filename
()
181 (list (cons "/dir1/con/file" "/dir1/%63on/file")
182 (cons "/dir1/con.dir/file" "/dir1/%63on.dir/file")
183 (cons "/dir1/con/?file" "/dir1/%63on/%3ffile")
184 (cons "/dir1/con/:file" "/dir1/%63on/%3afile")
185 (cons "/dir1/con/*file" "/dir1/%63on/%2afile")
186 (cons "/dir1/con/|file" "/dir1/%63on/%7cfile")
187 (cons "/dir1/dir2/lPt1.txt" "/dir1/dir2/%6cPt1.txt")
188 (cons "cdn-9.motorsport.com" "cdn-9.motorsport.com"))))
191 (should (string= (navi2ch-thumbnail-image-escape-filename (car pair
)) (cdr pair
))))))