New input method "probhat" for Bengali
[emacs.git] / test / automated / url-expand-tests.el
blob6d1d54d4ffc24c43da99adc5a69866cc2f0976ba
1 ;;; url-expand-tests.el --- Test suite for relative URI/URL resolution.
3 ;; Copyright (C) 2012-2016 Free Software Foundation, Inc.
5 ;; Author: Alain Schneble <a.s@realize.ch>
6 ;; Version: 1.0
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; Test cases covering URI reference resolution as described in RFC3986,
26 ;; section 5. Reference Resolution and especially the relative resolution
27 ;; rules specified in section 5.2. Relative Resolution.
29 ;; Each test calls `url-expand-file-name', typically with a relative
30 ;; reference URI and a base URI as string and compares the result (Actual)
31 ;; against a manually specified URI (Expected)
33 ;;; Code:
35 (require 'url-expand)
36 (require 'ert)
38 (ert-deftest url-expand-file-name/relative-resolution-normal-examples ()
39 "RFC 3986, Section 5.4 Reference Resolution Examples / Section 5.4.1. Normal Examples"
40 (should (equal (url-expand-file-name "g:h" "http://a/b/c/d;p?q") "g:h"))
41 (should (equal (url-expand-file-name "g" "http://a/b/c/d;p?q") "http://a/b/c/g"))
42 (should (equal (url-expand-file-name "./g" "http://a/b/c/d;p?q") "http://a/b/c/g"))
43 (should (equal (url-expand-file-name "g/" "http://a/b/c/d;p?q") "http://a/b/c/g/"))
44 (should (equal (url-expand-file-name "/g" "http://a/b/c/d;p?q") "http://a/g"))
45 (should (equal (url-expand-file-name "//g" "http://a/b/c/d;p?q") "http://g"))
46 (should (equal (url-expand-file-name "?y" "http://a/b/c/d;p?q") "http://a/b/c/d;p?y"))
47 (should (equal (url-expand-file-name "g?y" "http://a/b/c/d;p?q") "http://a/b/c/g?y"))
48 (should (equal (url-expand-file-name "#s" "http://a/b/c/d;p?q") "http://a/b/c/d;p?q#s"))
49 (should (equal (url-expand-file-name "g#s" "http://a/b/c/d;p?q") "http://a/b/c/g#s"))
50 (should (equal (url-expand-file-name "g?y#s" "http://a/b/c/d;p?q") "http://a/b/c/g?y#s"))
51 (should (equal (url-expand-file-name ";x" "http://a/b/c/d;p?q") "http://a/b/c/;x"))
52 (should (equal (url-expand-file-name "g;x" "http://a/b/c/d;p?q") "http://a/b/c/g;x"))
53 (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"))
54 (should (equal (url-expand-file-name "" "http://a/b/c/d;p?q") "http://a/b/c/d;p?q"))
55 (should (equal (url-expand-file-name "." "http://a/b/c/d;p?q") "http://a/b/c/"))
56 (should (equal (url-expand-file-name "./" "http://a/b/c/d;p?q") "http://a/b/c/"))
57 (should (equal (url-expand-file-name ".." "http://a/b/c/d;p?q") "http://a/b/"))
58 (should (equal (url-expand-file-name "../" "http://a/b/c/d;p?q") "http://a/b/"))
59 (should (equal (url-expand-file-name "../g" "http://a/b/c/d;p?q") "http://a/b/g"))
60 (should (equal (url-expand-file-name "../.." "http://a/b/c/d;p?q") "http://a/"))
61 (should (equal (url-expand-file-name "../../" "http://a/b/c/d;p?q") "http://a/"))
62 (should (equal (url-expand-file-name "../../g" "http://a/b/c/d;p?q") "http://a/g")))
64 (ert-deftest url-expand-file-name/relative-resolution-absolute-examples ()
65 "RFC 3986, Section 5.4 Reference Resolution Examples / Section 5.4.2. Abnormal Examples"
66 (should (equal (url-expand-file-name "../../../g" "http://a/b/c/d;p?q") "http://a/g"))
67 (should (equal (url-expand-file-name "../../../../g" "http://a/b/c/d;p?q") "http://a/g"))
69 (should (equal (url-expand-file-name "/./g" "http://a/b/c/d;p?q") "http://a/g"))
70 (should (equal (url-expand-file-name "/../g" "http://a/b/c/d;p?q") "http://a/g"))
71 (should (equal (url-expand-file-name "g." "http://a/b/c/d;p?q") "http://a/b/c/g."))
72 (should (equal (url-expand-file-name ".g" "http://a/b/c/d;p?q") "http://a/b/c/.g"))
73 (should (equal (url-expand-file-name "g.." "http://a/b/c/d;p?q") "http://a/b/c/g.."))
74 (should (equal (url-expand-file-name "..g" "http://a/b/c/d;p?q") "http://a/b/c/..g"))
76 (should (equal (url-expand-file-name "./../g" "http://a/b/c/d;p?q") "http://a/b/g"))
77 (should (equal (url-expand-file-name "./g/." "http://a/b/c/d;p?q") "http://a/b/c/g/"))
78 (should (equal (url-expand-file-name "g/./h" "http://a/b/c/d;p?q") "http://a/b/c/g/h"))
79 (should (equal (url-expand-file-name "g/../h" "http://a/b/c/d;p?q") "http://a/b/c/h"))
80 (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"))
81 (should (equal (url-expand-file-name "g;x=1/../y" "http://a/b/c/d;p?q") "http://a/b/c/y"))
83 (should (equal (url-expand-file-name "g?y/./x" "http://a/b/c/d;p?q") "http://a/b/c/g?y/./x"))
84 (should (equal (url-expand-file-name "g?y/../x" "http://a/b/c/d;p?q") "http://a/b/c/g?y/../x"))
85 (should (equal (url-expand-file-name "g#s/./x" "http://a/b/c/d;p?q") "http://a/b/c/g#s/./x"))
86 (should (equal (url-expand-file-name "g#s/../x" "http://a/b/c/d;p?q") "http://a/b/c/g#s/../x"))
88 (should (equal (url-expand-file-name "http:g" "http://a/b/c/d;p?q") "http:g")) ; for strict parsers
91 (ert-deftest url-expand-file-name/relative-resolution-additional-examples ()
92 "Reference Resolution Examples / Arbitrary Examples"
93 (should (equal (url-expand-file-name "" "http://host/foobar") "http://host/foobar"))
94 (should (equal (url-expand-file-name "?y" "http://a/b/c/d") "http://a/b/c/d?y"))
95 (should (equal (url-expand-file-name "?y" "http://a/b/c/d/") "http://a/b/c/d/?y"))
96 (should (equal (url-expand-file-name "?y#fragment" "http://a/b/c/d;p?q") "http://a/b/c/d;p?y#fragment"))
97 (should (equal (url-expand-file-name "#bar" "http://host") "http://host#bar"))
98 (should (equal (url-expand-file-name "#bar" "http://host/") "http://host/#bar"))
99 (should (equal (url-expand-file-name "#bar" "http://host/foo") "http://host/foo#bar"))
100 (should (equal (url-expand-file-name "foo#bar" "http://host/foobar") "http://host/foo#bar"))
101 (should (equal (url-expand-file-name "foo#bar" "http://host/foobar/") "http://host/foobar/foo#bar")))
103 (provide 'url-expand-tests)
105 ;;; url-expand-tests.el ends here