| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | (define-module (test-base32)
|
| 20 | #:use-module (gcrypt hash)
|
| 21 | #:use-module (guix base32)
|
| 22 | #:use-module (guix utils)
|
| 23 | #:use-module (srfi srfi-1)
|
| 24 | #:use-module (srfi srfi-34)
|
| 25 | #:use-module (srfi srfi-64)
|
| 26 | #:use-module (ice-9 match)
|
| 27 | #:use-module (rnrs bytevectors)
|
| 28 | #:use-module (rnrs io ports))
|
| 29 |
|
| 30 | |
| 31 |
|
| 32 | (test-begin "base32")
|
| 33 |
|
| 34 | (test-assert "bytevector->base32-string"
|
| 35 | (fold (lambda (bv expected result)
|
| 36 | (and result
|
| 37 | (string=? (bytevector->base32-string bv)
|
| 38 | expected)))
|
| 39 | #t
|
| 40 |
|
| 41 | |
| 42 | (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar"))
|
| 43 | '(""
|
| 44 | "my"
|
| 45 | "mzxq"
|
| 46 | "mzxw6"
|
| 47 | "mzxw6yq"
|
| 48 | "mzxw6ytb"
|
| 49 | "mzxw6ytboi")))
|
| 50 |
|
| 51 | (test-assert "base32-string->bytevector"
|
| 52 | (every (lambda (bv)
|
| 53 | (equal? (base32-string->bytevector
|
| 54 | (bytevector->base32-string bv))
|
| 55 | bv))
|
| 56 | |
| 57 | (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar"))))
|
| 58 |
|
| 59 | (test-assert "nix-base32-string->bytevector"
|
| 60 | (every (lambda (bv)
|
| 61 | (equal? (nix-base32-string->bytevector
|
| 62 | (bytevector->nix-base32-string bv))
|
| 63 | bv))
|
| 64 | |
| 65 | (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar"))))
|
| 66 |
|
| 67 | (test-equal "&invalid-base32-character"
|
| 68 | #\e
|
| 69 | (guard (c ((invalid-base32-character? c)
|
| 70 | (invalid-base32-character-value c)))
|
| 71 | (nix-base32-string->bytevector
|
| 72 | (string-append (make-string 51 #\a) "e"))))
|
| 73 |
|
| 74 | (test-end)
|