url-util-tests.el 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ;;; url-util-tests.el --- Test suite for url-util.
  2. ;; Copyright (C) 2012-2016 Free Software Foundation, Inc.
  3. ;; Author: Teodor Zlatanov <tzz@lifelogs.com>
  4. ;; Keywords: data
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Code:
  17. (require 'ert)
  18. (require 'url-util)
  19. (ert-deftest url-util-tests ()
  20. (let ((tests
  21. '(("key1=val1&key2=val2&key3=val1&key3=val2&key4&key5"
  22. ((key1 val1) (key2 "val2") (key3 val1 val2) (key4) (key5 "")))
  23. ("key1=val1;key2=val2;key3=val1;key3=val2;key4;key5"
  24. ((key1 "val1") (key2 val2) (key3 val1 val2) ("key4") (key5 "")) t)
  25. ("key1=val1;key2=val2;key3=val1;key3=val2;key4=;key5="
  26. ((key1 val1) (key2 val2) ("key3" val1 val2) (key4) (key5 "")) t t)))
  27. test)
  28. (while tests
  29. (setq test (car tests)
  30. tests (cdr tests))
  31. (should (equal (apply 'url-build-query-string (cdr test)) (car test)))))
  32. (should (equal (url-parse-query-string
  33. "key1=val1&key2=val2&key3=val1&key3=val2&key4=&key5")
  34. '(("key5" "")
  35. ("key4" "")
  36. ("key3" "val2" "val1")
  37. ("key2" "val2")
  38. ("key1" "val1")))))
  39. (provide 'url-util-tests)
  40. ;;; url-util-tests.el ends here