summaryrefslogtreecommitdiff
path: root/tests/quoted-printable.scm
diff options
context:
space:
mode:
Diffstat (limited to 'tests/quoted-printable.scm')
-rwxr-xr-xtests/quoted-printable.scm42
1 files changed, 37 insertions, 5 deletions
diff --git a/tests/quoted-printable.scm b/tests/quoted-printable.scm
index f3dd5eb..e41eced 100755
--- a/tests/quoted-printable.scm
+++ b/tests/quoted-printable.scm
@@ -19,9 +19,28 @@
(use-modules (email quoted-printable)
(ice-9 iconv)
+ (rnrs bytevectors)
(srfi srfi-1)
(srfi srfi-64))
+(set! *random-state* (random-state-from-platform))
+
+(define (random-bytevector len)
+ "Return a random bytevector of length LEN."
+ (u8-list->bytevector
+ (map (lambda _ (random 256)) (iota len))))
+
+(define (each-line-has-a-maximum-of-76-characters? str)
+ (every (lambda (line)
+ (<= (string-length line) 76))
+ (string-split str #\newline)))
+
+(define (string-has-only-quoted-printable-valid-characters? str)
+ (string-every (char-set-union
+ (char-set #\newline #\return #\space)
+ (ucs-range->char-set 33 127))
+ str))
+
(test-begin "quoted-printable")
(let ((decoded-text
@@ -43,11 +62,9 @@ abriquent pour te la vendre une =C3=A2me vulgaire.")
encoded-text)
(test-assert "quoted-printable wikipedia example: encoded output should not be more than 76 columns wide"
- (every (lambda (line)
- (<= (string-length line) 76))
- (string-split (quoted-printable-encode
- (string->bytevector decoded-text charset))
- #\newline))))
+ (each-line-has-a-maximum-of-76-characters?
+ (quoted-printable-encode
+ (string->bytevector decoded-text charset)))))
(test-equal "quoted-printable encoding of ="
(quoted-printable-encode
@@ -55,6 +72,21 @@ abriquent pour te la vendre une =C3=A2me vulgaire.")
(string-append "=" (string-upcase (number->string
(char->integer #\=) 16))))
+(let ((x (random-bytevector 1000)))
+ (test-equal "quoted-printable random bytevector: quoted-printable-encode and quoted-printable-decode are inverses of each other"
+ (quoted-printable-decode
+ (quoted-printable-encode x))
+ x))
+
+(test-assert "quoted-printable random bytevector: encoded output should not be more than 76 columns wide"
+ (each-line-has-a-maximum-of-76-characters?
+ (quoted-printable-encode
+ (random-bytevector 1000))))
+
+(test-assert "quoted-printable random bytevector: encoded output must only consist of printable ASCII characters"
+ (string-has-only-quoted-printable-valid-characters?
+ (quoted-printable-encode (random-bytevector 1000))))
+
(let ((encoded-text "=A1Hola,_se=F1or!")
(decoded-text "¡Hola, señor!")
(charset "ISO-8859-1"))