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