url-expand-tests.el 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ;;; url-expand-tests.el --- Test suite for relative URI/URL resolution.
  2. ;; Copyright (C) 2012-2017 Free Software Foundation, Inc.
  3. ;; Author: Alain Schneble <a.s@realize.ch>
  4. ;; Version: 1.0
  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. ;;; Commentary:
  17. ;; Test cases covering URI reference resolution as described in RFC3986,
  18. ;; section 5. Reference Resolution and especially the relative resolution
  19. ;; rules specified in section 5.2. Relative Resolution.
  20. ;; Each test calls `url-expand-file-name', typically with a relative
  21. ;; reference URI and a base URI as string and compares the result (Actual)
  22. ;; against a manually specified URI (Expected)
  23. ;;; Code:
  24. (require 'url-expand)
  25. (require 'ert)
  26. (ert-deftest url-expand-file-name/relative-resolution-normal-examples ()
  27. "RFC 3986, Section 5.4 Reference Resolution Examples / Section 5.4.1. Normal Examples"
  28. (should (equal (url-expand-file-name "g:h" "http://a/b/c/d;p?q") "g:h"))
  29. (should (equal (url-expand-file-name "g" "http://a/b/c/d;p?q") "http://a/b/c/g"))
  30. (should (equal (url-expand-file-name "./g" "http://a/b/c/d;p?q") "http://a/b/c/g"))
  31. (should (equal (url-expand-file-name "g/" "http://a/b/c/d;p?q") "http://a/b/c/g/"))
  32. (should (equal (url-expand-file-name "/g" "http://a/b/c/d;p?q") "http://a/g"))
  33. (should (equal (url-expand-file-name "//g" "http://a/b/c/d;p?q") "http://g"))
  34. (should (equal (url-expand-file-name "?y" "http://a/b/c/d;p?q") "http://a/b/c/d;p?y"))
  35. (should (equal (url-expand-file-name "g?y" "http://a/b/c/d;p?q") "http://a/b/c/g?y"))
  36. (should (equal (url-expand-file-name "#s" "http://a/b/c/d;p?q") "http://a/b/c/d;p?q#s"))
  37. (should (equal (url-expand-file-name "g#s" "http://a/b/c/d;p?q") "http://a/b/c/g#s"))
  38. (should (equal (url-expand-file-name "g?y#s" "http://a/b/c/d;p?q") "http://a/b/c/g?y#s"))
  39. (should (equal (url-expand-file-name ";x" "http://a/b/c/d;p?q") "http://a/b/c/;x"))
  40. (should (equal (url-expand-file-name "g;x" "http://a/b/c/d;p?q") "http://a/b/c/g;x"))
  41. (should (equal (url-expand-file-name "g;x?y#s" "http://a/b/c/d;p?q") "http://a/b/c/g;x?y#s"))
  42. (should (equal (url-expand-file-name "" "http://a/b/c/d;p?q") "http://a/b/c/d;p?q"))
  43. (should (equal (url-expand-file-name "." "http://a/b/c/d;p?q") "http://a/b/c/"))
  44. (should (equal (url-expand-file-name "./" "http://a/b/c/d;p?q") "http://a/b/c/"))
  45. (should (equal (url-expand-file-name ".." "http://a/b/c/d;p?q") "http://a/b/"))
  46. (should (equal (url-expand-file-name "../" "http://a/b/c/d;p?q") "http://a/b/"))
  47. (should (equal (url-expand-file-name "../g" "http://a/b/c/d;p?q") "http://a/b/g"))
  48. (should (equal (url-expand-file-name "../.." "http://a/b/c/d;p?q") "http://a/"))
  49. (should (equal (url-expand-file-name "../../" "http://a/b/c/d;p?q") "http://a/"))
  50. (should (equal (url-expand-file-name "../../g" "http://a/b/c/d;p?q") "http://a/g")))
  51. (ert-deftest url-expand-file-name/relative-resolution-absolute-examples ()
  52. "RFC 3986, Section 5.4 Reference Resolution Examples / Section 5.4.2. Abnormal Examples"
  53. (should (equal (url-expand-file-name "../../../g" "http://a/b/c/d;p?q") "http://a/g"))
  54. (should (equal (url-expand-file-name "../../../../g" "http://a/b/c/d;p?q") "http://a/g"))
  55. (should (equal (url-expand-file-name "/./g" "http://a/b/c/d;p?q") "http://a/g"))
  56. (should (equal (url-expand-file-name "/../g" "http://a/b/c/d;p?q") "http://a/g"))
  57. (should (equal (url-expand-file-name "g." "http://a/b/c/d;p?q") "http://a/b/c/g."))
  58. (should (equal (url-expand-file-name ".g" "http://a/b/c/d;p?q") "http://a/b/c/.g"))
  59. (should (equal (url-expand-file-name "g.." "http://a/b/c/d;p?q") "http://a/b/c/g.."))
  60. (should (equal (url-expand-file-name "..g" "http://a/b/c/d;p?q") "http://a/b/c/..g"))
  61. (should (equal (url-expand-file-name "./../g" "http://a/b/c/d;p?q") "http://a/b/g"))
  62. (should (equal (url-expand-file-name "./g/." "http://a/b/c/d;p?q") "http://a/b/c/g/"))
  63. (should (equal (url-expand-file-name "g/./h" "http://a/b/c/d;p?q") "http://a/b/c/g/h"))
  64. (should (equal (url-expand-file-name "g/../h" "http://a/b/c/d;p?q") "http://a/b/c/h"))
  65. (should (equal (url-expand-file-name "g;x=1/./y" "http://a/b/c/d;p?q") "http://a/b/c/g;x=1/y"))
  66. (should (equal (url-expand-file-name "g;x=1/../y" "http://a/b/c/d;p?q") "http://a/b/c/y"))
  67. (should (equal (url-expand-file-name "g?y/./x" "http://a/b/c/d;p?q") "http://a/b/c/g?y/./x"))
  68. (should (equal (url-expand-file-name "g?y/../x" "http://a/b/c/d;p?q") "http://a/b/c/g?y/../x"))
  69. (should (equal (url-expand-file-name "g#s/./x" "http://a/b/c/d;p?q") "http://a/b/c/g#s/./x"))
  70. (should (equal (url-expand-file-name "g#s/../x" "http://a/b/c/d;p?q") "http://a/b/c/g#s/../x"))
  71. (should (equal (url-expand-file-name "http:g" "http://a/b/c/d;p?q") "http:g")) ; for strict parsers
  72. )
  73. (ert-deftest url-expand-file-name/relative-resolution-additional-examples ()
  74. "Reference Resolution Examples / Arbitrary Examples"
  75. (should (equal (url-expand-file-name "" "http://host/foobar") "http://host/foobar"))
  76. (should (equal (url-expand-file-name "?y" "http://a/b/c/d") "http://a/b/c/d?y"))
  77. (should (equal (url-expand-file-name "?y" "http://a/b/c/d/") "http://a/b/c/d/?y"))
  78. (should (equal (url-expand-file-name "?y#fragment" "http://a/b/c/d;p?q") "http://a/b/c/d;p?y#fragment"))
  79. (should (equal (url-expand-file-name "#bar" "http://host") "http://host#bar"))
  80. (should (equal (url-expand-file-name "#bar" "http://host/") "http://host/#bar"))
  81. (should (equal (url-expand-file-name "#bar" "http://host/foo") "http://host/foo#bar"))
  82. (should (equal (url-expand-file-name "foo#bar" "http://host/foobar") "http://host/foo#bar"))
  83. (should (equal (url-expand-file-name "foo#bar" "http://host/foobar/") "http://host/foobar/foo#bar")))
  84. (provide 'url-expand-tests)
  85. ;;; url-expand-tests.el ends here