Fixed.
[riece] / lisp / test / test-riece-log.el
1 (require 'riece-log)
2
3 (luna-define-class test-riece-log (lunit-test-case))
4
5 (defun test-riece-log-delete-directory (directory)
6   (let ((files (directory-files directory t nil t)))
7     (while files
8       (if (file-directory-p (car files))
9           (unless (member (file-name-nondirectory (car files)) '("." ".."))
10             (test-riece-log-delete-directory (car files)))
11         (delete-file (car files)))
12       (setq files (cdr files)))
13     (delete-directory directory)))
14
15 (luna-define-method lunit-test-case-setup ((case test-riece-log))
16   (setq riece-log-directory
17         (expand-file-name (make-temp-name "test-riece-log")
18                            (if (featurep 'xemacs)
19                                (temp-directory)
20                              temporary-file-directory))
21         test-riece-log-directory
22         (expand-file-name "riece" riece-log-directory))
23   (make-directory riece-log-directory)
24   (make-directory test-riece-log-directory)
25   (write-region "03:14 <test> a b c\n03:15 <test> a b c\n" nil
26                 (expand-file-name "20380119.log" test-riece-log-directory)
27                 t 0)
28   (write-region "03:14 <test> 1 2 3\n" nil
29                 (expand-file-name "20380118.log" test-riece-log-directory)
30                 t 0))
31
32 (luna-define-method lunit-test-case-teardown ((case test-riece-log))
33   (test-riece-log-delete-directory riece-log-directory))
34
35 (luna-define-method test-riece-log-flashback-1 ((case test-riece-log))
36   (let ((riece-log-flashback 3)
37         riece-log-directory-map)
38     (lunit-assert-2
39      case
40      (equal
41       (concat "03:14 <test> 1 2 3 (2038/01/18)\n"
42               "03:14 <test> a b c (2038/01/19)\n"
43               "03:15 <test> a b c (2038/01/19)\n")
44       (with-temp-buffer
45         (riece-log-flashback (riece-make-identity "#riece" ""))
46         (buffer-string))))))
47
48 (luna-define-method test-riece-log-flashback-2 ((case test-riece-log))
49   (let ((riece-log-flashback t)
50         riece-log-directory-map)
51     (lunit-assert-2
52      case
53      (equal ""
54             (with-temp-buffer
55               (riece-log-flashback (riece-make-identity "#riece" ""))
56               (buffer-string))))))
57
58 (luna-define-method test-riece-log-encode-file-name ((case test-riece-log))
59   (let (riece-log-file-name-coding-system)
60     (lunit-assert-2
61      case
62      (equal "=23riece"
63             (riece-log-encode-file-name "#riece")))
64     (message "!!! %S" (riece-log-encode-file-name "#riece:*.jp"))
65     (lunit-assert-2
66      case
67      (equal "=23riece=3A=2A=2Ejp"
68             (riece-log-encode-file-name "#riece:*.jp")))
69     (message "%S" (riece-log-encode-file-name "#riece="))
70     (lunit-assert-2
71      case
72      (equal "=23riece=="
73             (riece-log-encode-file-name "#riece=")))))
74
75 (luna-define-method test-riece-log-encode-file-name-mule
76   ((case test-riece-log))
77   (let ((riece-log-file-name-coding-system 'iso-8859-1))
78     (lunit-assert-2
79      case
80      (equal "=23\xABriece\xBB"
81             (riece-log-encode-file-name
82              (format "#%criece%c"
83                      (make-char 'latin-iso8859-1 43)
84                      (make-char 'latin-iso8859-1 59))))))
85   (let ((riece-log-file-name-coding-system 'iso-2022-jp))
86     (lunit-assert-2
87      case
88      (equal "=23=1B=24B=24j=21=3C=249=1B=28B"
89             (riece-log-encode-file-name
90              (format "#%c%c%c"
91                     (make-char 'japanese-jisx0208 36 106)
92                     (make-char 'japanese-jisx0208 33 60)
93                     (make-char 'japanese-jisx0208 36 57)))))))
94
95 (luna-define-method test-riece-log-decode-file-name ((case test-riece-log))
96   (let (riece-log-file-name-coding-system)
97     (lunit-assert-2
98      case
99      (equal "#riece"
100             (riece-log-decode-file-name "=23riece")))
101     (lunit-assert-2
102      case
103      (equal "#riece:*.jp"
104             (riece-log-decode-file-name "=23riece=3A=2A=2Ejp")))
105     (lunit-assert-2
106      case
107      (equal "#riece="
108             (riece-log-decode-file-name "=23riece==")))))
109
110 (luna-define-method test-riece-log-decode-file-name-mule
111   ((case test-riece-log))
112   (let ((riece-log-file-name-coding-system 'iso-8859-1))
113     (lunit-assert-2
114      case
115      (equal (format "#%criece%c"
116                      (make-char 'latin-iso8859-1 43)
117                      (make-char 'latin-iso8859-1 59))
118             (riece-log-decode-file-name
119              "=23\xABriece\xBB"))))
120   (let ((riece-log-file-name-coding-system 'iso-2022-jp))
121     (lunit-assert-2
122      case
123      (equal (format "#%c%c%c"
124                     (make-char 'japanese-jisx0208 36 106)
125                     (make-char 'japanese-jisx0208 33 60)
126                     (make-char 'japanese-jisx0208 36 57))
127             (riece-log-decode-file-name
128              "=23=1B=24B=24j=21=3C=249=1B=28B")))))