b432b09577da910c392f08b5d2aca4b8b9132e2b
[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 "=23riece" 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.txt" test-riece-log-directory)
27                 t 0)
28   (write-region "03:14 <test> 1 2 3\n" nil
29                 (expand-file-name "20380118.txt" 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     (lunit-assert-2
65      case
66      (equal "=23riece=3A=2A=2Ejp"
67             (riece-log-encode-file-name "#riece:*.jp")))
68     (lunit-assert-2
69      case
70      (equal "=23riece=="
71             (riece-log-encode-file-name "#riece=")))))
72
73 (luna-define-method test-riece-log-encode-file-name-mule
74   ((case test-riece-log))
75   (let ((riece-log-file-name-coding-system 'iso-8859-1))
76     (lunit-assert-2
77      case
78      (equal "=23\xABriece\xBB"
79             (riece-log-encode-file-name
80              (format "#%criece%c"
81                      (make-char 'latin-iso8859-1 43)
82                      (make-char 'latin-iso8859-1 59))))))
83   (let ((riece-log-file-name-coding-system 'iso-2022-jp))
84     (lunit-assert-2
85      case
86      (equal "=23=1B=24B=24j=21=3C=249=1B=28B"
87             (riece-log-encode-file-name
88              (format "#%c%c%c"
89                     (make-char 'japanese-jisx0208 36 106)
90                     (make-char 'japanese-jisx0208 33 60)
91                     (make-char 'japanese-jisx0208 36 57)))))))
92
93 (luna-define-method test-riece-log-decode-file-name ((case test-riece-log))
94   (let (riece-log-file-name-coding-system)
95     (lunit-assert-2
96      case
97      (equal "#riece"
98             (riece-log-decode-file-name "=23riece")))
99     (lunit-assert-2
100      case
101      (equal "#riece:*.jp"
102             (riece-log-decode-file-name "=23riece=3A=2A=2Ejp")))
103     (lunit-assert-2
104      case
105      (equal "#riece="
106             (riece-log-decode-file-name "=23riece==")))))
107
108 (luna-define-method test-riece-log-decode-file-name-mule
109   ((case test-riece-log))
110   (let ((riece-log-file-name-coding-system 'iso-8859-1))
111     (lunit-assert-2
112      case
113      (equal (format "#%criece%c"
114                      (make-char 'latin-iso8859-1 43)
115                      (make-char 'latin-iso8859-1 59))
116             (riece-log-decode-file-name
117              "=23\xABriece\xBB"))))
118   (let ((riece-log-file-name-coding-system 'iso-2022-jp))
119     (lunit-assert-2
120      case
121      (equal (format "#%c%c%c"
122                     (make-char 'japanese-jisx0208 36 106)
123                     (make-char 'japanese-jisx0208 33 60)
124                     (make-char 'japanese-jisx0208 36 57))
125             (riece-log-decode-file-name
126              "=23=1B=24B=24j=21=3C=249=1B=28B")))))