base64.scm 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 Nikita Karetnikov <nikita@karetnikov.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-base64)
  19. #:use-module (guix base64)
  20. #:use-module (rnrs bytevectors)
  21. #:use-module (srfi srfi-64))
  22. (define (string->base64 str)
  23. (base64-encode (string->utf8 str)))
  24. ;;; Test vectors from <https://tools.ietf.org/rfc/rfc4648.txt>.
  25. (test-begin "base64")
  26. (test-equal "empty string"
  27. (string->base64 "")
  28. "")
  29. (test-equal "f"
  30. (string->base64 "f")
  31. "Zg==")
  32. (test-equal "fo"
  33. (string->base64 "fo")
  34. "Zm8=")
  35. (test-equal "foo"
  36. (string->base64 "foo")
  37. "Zm9v")
  38. (test-equal "foob"
  39. (string->base64 "foob")
  40. "Zm9vYg==")
  41. (test-equal "fooba"
  42. (string->base64 "fooba")
  43. "Zm9vYmE=")
  44. (test-equal "foobar"
  45. (string->base64 "foobar")
  46. "Zm9vYmFy")
  47. (test-end "base64")