cl-rfc2047-test.lisp 967 Bytes
Newer Older
ch's avatar
ch committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(in-package :cl-rfc2047-test)

(defparameter *ascii-phrases*
  '("one"
    "two three"
    "some what longer text that sould get broken up into multiple lines 123"))

(deftestsuite encode-tests () ())

(defun ensure-encoding (original encoded)
  (loop
     :for word :in (cl-ppcre:split cl-rfc2047::*crlfsp* encoded)
     :do (ensure (<= (length word) 75)
		 :report "length (~A) must not be larger than 75"
		 :arguments ((length word)))
  (ensure (string= original (decode encoded))
	  :report "~A must be equal to ~A"
	  :arguments (original (decode encoded)))))

(addtest encode-test
  (loop
     :for word :in *ascii-phrases*
     :do (ensure-encoding word (encode word))))

(addtest decode-known-encodings-test
  (loop
     :for (encoded decoded)
     :in '(("=?US-ASCII?Q?foo_bar=20baz?=" "foo bar baz")
	   ("=?ISO-8859-1?Q?n=e4n=F6n=fC?=" "nänönü")
	   ("=?uTf-8?b?Zm9vIGJhciBiYXo=?=" "foo bar baz"))
     :do (ensure (string= decoded (decode encoded)))))