summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArun Isaac2018-09-15 11:18:42 +0530
committerArun Isaac2018-09-15 11:20:48 +0530
commitd3ebe5a4920bf28c2c579078bb69e349776d5840 (patch)
treeaa510484e4e97cc9376dede4ae4686677fd9acf3 /tests
parentae688fd185c90ceba7a5bc28c1704e42c69f5306 (diff)
downloadguile-email-d3ebe5a4920bf28c2c579078bb69e349776d5840.tar.gz
guile-email-d3ebe5a4920bf28c2c579078bb69e349776d5840.tar.lz
guile-email-d3ebe5a4920bf28c2c579078bb69e349776d5840.zip
tests: Add tests for quoted-printable.
* tests/quoted-printable.scm (random-bytevector, each-line-has-a-maximum-of-76-characters?, string-has-only-quoted-printable-valid-characters?): New functions. (quoted-printable random bytevector: quoted-printable-encode and quoted-printable-decode are inverses of each other, quoted-printable random bytevector: encoded output should not be more than 76 columns wide, quoted-printable random bytevector: encoded output must only consist of printable ASCII characters): New tests.
Diffstat (limited to 'tests')
-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"))