diff options
| author | Alain Schneble | 2015-12-26 14:52:43 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2015-12-26 14:53:08 +0100 |
| commit | 4b5b3985add83e093f3c46e9276cb0da010c05ea (patch) | |
| tree | 3c06a5656b40f21276a5b4cebeda3c3bd7268982 | |
| parent | 8dea6fe5b5bc2936b046e799ea61afc508e28752 (diff) | |
| download | emacs-4b5b3985add83e093f3c46e9276cb0da010c05ea.tar.gz emacs-4b5b3985add83e093f3c46e9276cb0da010c05ea.zip | |
Include the tests for the URL parsing fixes
| -rw-r--r-- | test/automated/url-expand-tests.el (renamed from test/lisp/url/url-expand-tests.el) | 0 | ||||
| -rw-r--r-- | test/automated/url-parse-tests.el | 167 |
2 files changed, 167 insertions, 0 deletions
diff --git a/test/lisp/url/url-expand-tests.el b/test/automated/url-expand-tests.el index 2bd28687f8d..2bd28687f8d 100644 --- a/test/lisp/url/url-expand-tests.el +++ b/test/automated/url-expand-tests.el | |||
diff --git a/test/automated/url-parse-tests.el b/test/automated/url-parse-tests.el new file mode 100644 index 00000000000..154e0917a43 --- /dev/null +++ b/test/automated/url-parse-tests.el | |||
| @@ -0,0 +1,167 @@ | |||
| 1 | ;;; url-parse-tests.el --- Test suite for URI/URL parsing. | ||
| 2 | |||
| 3 | ;; Copyright (C) 2012-2015 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Alain Schneble <a.s@realize.ch> | ||
| 6 | ;; Version: 1.0 | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 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. | ||
| 14 | |||
| 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. | ||
| 19 | |||
| 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/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; Test cases covering generic URI syntax as described in RFC3986, | ||
| 26 | ;; section 3. Syntax Components and 4. Usage. See also appendix | ||
| 27 | ;; A. Collected ABNF for URI, as the example given here are all | ||
| 28 | ;; productions of this grammar. | ||
| 29 | |||
| 30 | ;; Each tests parses a given URI string - whether relative or absolute - | ||
| 31 | ;; using `url-generic-parse-url' and compares the constructed | ||
| 32 | ;; URL-struct (Actual) against a manually `url-parse-make-urlobj'- | ||
| 33 | ;; constructed URL-struct (Expected). | ||
| 34 | |||
| 35 | ;;; Code: | ||
| 36 | |||
| 37 | (require 'url-parse) | ||
| 38 | (require 'ert) | ||
| 39 | |||
| 40 | (ert-deftest url-generic-parse-url/generic-uri-examples () | ||
| 41 | "RFC 3986, section 1.1.2. Examples / Example illustrating several URI schemes and variations in their common syntax components" | ||
| 42 | (should (equal (url-generic-parse-url "ftp://ftp.is.co.za/rfc/rfc1808.txt") (url-parse-make-urlobj "ftp" nil nil "ftp.is.co.za" nil "/rfc/rfc1808.txt" nil nil t))) | ||
| 43 | (should (equal (url-generic-parse-url "http://www.ietf.org/rfc/rfc2396.txt") (url-parse-make-urlobj "http" nil nil "www.ietf.org" nil "/rfc/rfc2396.txt" nil nil t))) | ||
| 44 | (should (equal (url-generic-parse-url "ldap://[2001:db8::7]/c=GB?objectClass?one") (url-parse-make-urlobj "ldap" nil nil "[2001:db8::7]" nil "/c=GB?objectClass?one" nil nil t))) | ||
| 45 | (should (equal (url-generic-parse-url "mailto:John.Doe@example.com") (url-parse-make-urlobj "mailto" nil nil nil nil "John.Doe@example.com" nil nil nil))) | ||
| 46 | (should (equal (url-generic-parse-url "news:comp.infosystems.www.servers.unix") (url-parse-make-urlobj "news" nil nil nil nil "comp.infosystems.www.servers.unix" nil nil nil))) | ||
| 47 | (should (equal (url-generic-parse-url "tel:+1-816-555-1212") (url-parse-make-urlobj "tel" nil nil nil nil "+1-816-555-1212" nil nil nil))) | ||
| 48 | (should (equal (url-generic-parse-url "telnet://192.0.2.16:80/") (url-parse-make-urlobj "telnet" nil nil "192.0.2.16" 80 "/" nil nil t))) | ||
| 49 | (should (equal (url-generic-parse-url "urn:oasis:names:specification:docbook:dtd:xml:4.1.2") (url-parse-make-urlobj "urn" nil nil nil nil "oasis:names:specification:docbook:dtd:xml:4.1.2" nil nil nil)))) | ||
| 50 | |||
| 51 | (ert-deftest url-generic-parse-url/generic-uri () | ||
| 52 | "RFC 3986, section 3. Syntax Components / generic URI syntax" | ||
| 53 | ;; empty path | ||
| 54 | (should (equal (url-generic-parse-url "http://host#") (url-parse-make-urlobj "http" nil nil "host" nil "" "" nil t))) | ||
| 55 | (should (equal (url-generic-parse-url "http://host#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "" "fragment" nil t))) | ||
| 56 | (should (equal (url-generic-parse-url "http://host?#") (url-parse-make-urlobj "http" nil nil "host" nil "?" "" nil t))) | ||
| 57 | (should (equal (url-generic-parse-url "http://host?query#") (url-parse-make-urlobj "http" nil nil "host" nil "?query" "" nil t))) | ||
| 58 | (should (equal (url-generic-parse-url "http://host?#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "?" "fragment" nil t))) | ||
| 59 | (should (equal (url-generic-parse-url "http://host?query#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "?query" "fragment" nil t))) | ||
| 60 | ;; absolute path / | ||
| 61 | (should (equal (url-generic-parse-url "http://host/#") (url-parse-make-urlobj "http" nil nil "host" nil "/" "" nil t))) | ||
| 62 | (should (equal (url-generic-parse-url "http://host/#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/" "fragment" nil t))) | ||
| 63 | (should (equal (url-generic-parse-url "http://host/?#") (url-parse-make-urlobj "http" nil nil "host" nil "/?" "" nil t))) | ||
| 64 | (should (equal (url-generic-parse-url "http://host/?query#") (url-parse-make-urlobj "http" nil nil "host" nil "/?query" "" nil t))) | ||
| 65 | (should (equal (url-generic-parse-url "http://host/?#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/?" "fragment" nil t))) | ||
| 66 | (should (equal (url-generic-parse-url "http://host/?query#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/?query" "fragment" nil t))) | ||
| 67 | ;; absolute path /foo | ||
| 68 | (should (equal (url-generic-parse-url "http://host/foo#") (url-parse-make-urlobj "http" nil nil "host" nil "/foo" "" nil t))) | ||
| 69 | (should (equal (url-generic-parse-url "http://host/foo#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/foo" "fragment" nil t))) | ||
| 70 | (should (equal (url-generic-parse-url "http://host/foo?#") (url-parse-make-urlobj "http" nil nil "host" nil "/foo?" "" nil t))) | ||
| 71 | (should (equal (url-generic-parse-url "http://host/foo?query#") (url-parse-make-urlobj "http" nil nil "host" nil "/foo?query" "" nil t))) | ||
| 72 | (should (equal (url-generic-parse-url "http://host/foo?#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/foo?" "fragment" nil t))) | ||
| 73 | (should (equal (url-generic-parse-url "http://host/foo?query#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/foo?query" "fragment" nil t))) | ||
| 74 | ;; absolute path /foo/ | ||
| 75 | (should (equal (url-generic-parse-url "http://host/foo/#") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/" "" nil t))) | ||
| 76 | (should (equal (url-generic-parse-url "http://host/foo/#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/" "fragment" nil t))) | ||
| 77 | (should (equal (url-generic-parse-url "http://host/foo/?#") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/?" "" nil t))) | ||
| 78 | (should (equal (url-generic-parse-url "http://host/foo/?query#") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/?query" "" nil t))) | ||
| 79 | (should (equal (url-generic-parse-url "http://host/foo/?#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/?" "fragment" nil t))) | ||
| 80 | (should (equal (url-generic-parse-url "http://host/foo/?query#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/?query" "fragment" nil t))) | ||
| 81 | ;; absolute path /foo/bar | ||
| 82 | (should (equal (url-generic-parse-url "http://host/foo/bar#") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar" "" nil t))) | ||
| 83 | (should (equal (url-generic-parse-url "http://host/foo/bar#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar" "fragment" nil t))) | ||
| 84 | (should (equal (url-generic-parse-url "http://host/foo/bar?#") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar?" "" nil t))) | ||
| 85 | (should (equal (url-generic-parse-url "http://host/foo/bar?query#") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar?query" "" nil t))) | ||
| 86 | (should (equal (url-generic-parse-url "http://host/foo/bar?#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar?" "fragment" nil t))) | ||
| 87 | (should (equal (url-generic-parse-url "http://host/foo/bar?query#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar?query" "fragment" nil t))) | ||
| 88 | ;; absolute path /foo/bar/ | ||
| 89 | (should (equal (url-generic-parse-url "http://host/foo/bar/#") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar/" "" nil t))) | ||
| 90 | (should (equal (url-generic-parse-url "http://host/foo/bar/#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar/" "fragment" nil t))) | ||
| 91 | (should (equal (url-generic-parse-url "http://host/foo/bar/?#") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar/?" "" nil t))) | ||
| 92 | (should (equal (url-generic-parse-url "http://host/foo/bar/?query#") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar/?query" "" nil t))) | ||
| 93 | (should (equal (url-generic-parse-url "http://host/foo/bar/?#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar/?" "fragment" nil t))) | ||
| 94 | (should (equal (url-generic-parse-url "http://host/foo/bar/?query#fragment") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar/?query" "fragment" nil t))) | ||
| 95 | ;; for more examples of URIs without fragments, see tests covering section 4.3. Absolute URI | ||
| 96 | ) | ||
| 97 | |||
| 98 | (ert-deftest url-generic-parse-url/network-path-reference () | ||
| 99 | "RFC 3986, section 4.2. Relative Reference / network-path reference: a relative reference that begins with two slash characters" | ||
| 100 | (should (equal (url-generic-parse-url "//host") (url-parse-make-urlobj nil nil nil "host" nil "" nil nil t))) | ||
| 101 | (should (equal (url-generic-parse-url "//host/") (url-parse-make-urlobj nil nil nil "host" nil "/" nil nil t))) | ||
| 102 | (should (equal (url-generic-parse-url "//host/foo") (url-parse-make-urlobj nil nil nil "host" nil "/foo" nil nil t))) | ||
| 103 | (should (equal (url-generic-parse-url "//host/foo/bar") (url-parse-make-urlobj nil nil nil "host" nil "/foo/bar" nil nil t))) | ||
| 104 | (should (equal (url-generic-parse-url "//host/foo/bar/") (url-parse-make-urlobj nil nil nil "host" nil "/foo/bar/" nil nil t)))) | ||
| 105 | |||
| 106 | (ert-deftest url-generic-parse-url/absolute-path-reference () | ||
| 107 | "RFC 3986, section 4.2. Relative Reference / absolute-path reference: a relative reference that begins with a single slash character" | ||
| 108 | (should (equal (url-generic-parse-url "/") (url-parse-make-urlobj nil nil nil nil nil "/" nil nil nil))) | ||
| 109 | (should (equal (url-generic-parse-url "/foo") (url-parse-make-urlobj nil nil nil nil nil "/foo" nil nil nil))) | ||
| 110 | (should (equal (url-generic-parse-url "/foo/bar") (url-parse-make-urlobj nil nil nil nil nil "/foo/bar" nil nil nil))) | ||
| 111 | (should (equal (url-generic-parse-url "/foo/bar/") (url-parse-make-urlobj nil nil nil nil nil "/foo/bar/" nil nil nil))) | ||
| 112 | (should (equal (url-generic-parse-url "/foo/bar#") (url-parse-make-urlobj nil nil nil nil nil "/foo/bar" "" nil nil))) | ||
| 113 | (should (equal (url-generic-parse-url "/foo/bar/#") (url-parse-make-urlobj nil nil nil nil nil "/foo/bar/" "" nil nil)))) | ||
| 114 | |||
| 115 | (ert-deftest url-generic-parse-url/relative-path-reference () | ||
| 116 | "RFC 3986, section 4.2. Relative Reference / relative-path reference: a relative reference that does not begin with a slash character" | ||
| 117 | (should (equal (url-generic-parse-url "foo") (url-parse-make-urlobj nil nil nil nil nil "foo" nil nil nil))) | ||
| 118 | (should (equal (url-generic-parse-url "foo/bar") (url-parse-make-urlobj nil nil nil nil nil "foo/bar" nil nil nil))) | ||
| 119 | (should (equal (url-generic-parse-url "foo/bar/") (url-parse-make-urlobj nil nil nil nil nil "foo/bar/" nil nil nil))) | ||
| 120 | (should (equal (url-generic-parse-url "./foo") (url-parse-make-urlobj nil nil nil nil nil "./foo" nil nil nil))) | ||
| 121 | (should (equal (url-generic-parse-url "./foo/bar") (url-parse-make-urlobj nil nil nil nil nil "./foo/bar" nil nil nil))) | ||
| 122 | (should (equal (url-generic-parse-url "./foo/bar/") (url-parse-make-urlobj nil nil nil nil nil "./foo/bar/" nil nil nil))) | ||
| 123 | (should (equal (url-generic-parse-url "../foo") (url-parse-make-urlobj nil nil nil nil nil "../foo" nil nil nil))) | ||
| 124 | (should (equal (url-generic-parse-url "../foo/bar") (url-parse-make-urlobj nil nil nil nil nil "../foo/bar" nil nil nil))) | ||
| 125 | (should (equal (url-generic-parse-url "../foo/bar/") (url-parse-make-urlobj nil nil nil nil nil "../foo/bar/" nil nil nil))) | ||
| 126 | (should (equal (url-generic-parse-url "./this:that") (url-parse-make-urlobj nil nil nil nil nil "./this:that" nil nil nil))) | ||
| 127 | ;; for more examples of relative-path references, see tests covering section 4.4. Same-Document Reference | ||
| 128 | ) | ||
| 129 | |||
| 130 | (ert-deftest url-generic-parse-url/absolute-uri () | ||
| 131 | "RFC 3986, section 4.3. Absolute URI / absolute URI: absolute form of a URI without a fragment identifier" | ||
| 132 | ;; empty path | ||
| 133 | (should (equal (url-generic-parse-url "http://host") (url-parse-make-urlobj "http" nil nil "host" nil "" nil nil t))) | ||
| 134 | (should (equal (url-generic-parse-url "http://host?") (url-parse-make-urlobj "http" nil nil "host" nil "?" nil nil t))) | ||
| 135 | (should (equal (url-generic-parse-url "http://host?query") (url-parse-make-urlobj "http" nil nil "host" nil "?query" nil nil t))) | ||
| 136 | ;; absolute path / | ||
| 137 | (should (equal (url-generic-parse-url "http://host/") (url-parse-make-urlobj "http" nil nil "host" nil "/" nil nil t))) | ||
| 138 | (should (equal (url-generic-parse-url "http://host/?") (url-parse-make-urlobj "http" nil nil "host" nil "/?" nil nil t))) | ||
| 139 | (should (equal (url-generic-parse-url "http://host/?query") (url-parse-make-urlobj "http" nil nil "host" nil "/?query" nil nil t))) | ||
| 140 | ;; absolute path /foo | ||
| 141 | (should (equal (url-generic-parse-url "http://host/foo") (url-parse-make-urlobj "http" nil nil "host" nil "/foo" nil nil t))) | ||
| 142 | (should (equal (url-generic-parse-url "http://host/foo?") (url-parse-make-urlobj "http" nil nil "host" nil "/foo?" nil nil t))) | ||
| 143 | (should (equal (url-generic-parse-url "http://host/foo?query") (url-parse-make-urlobj "http" nil nil "host" nil "/foo?query" nil nil t))) | ||
| 144 | ;; absolute path /foo/ | ||
| 145 | (should (equal (url-generic-parse-url "http://host/foo/") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/" nil nil t))) | ||
| 146 | (should (equal (url-generic-parse-url "http://host/foo/?") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/?" nil nil t))) | ||
| 147 | (should (equal (url-generic-parse-url "http://host/foo/?query") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/?query" nil nil t))) | ||
| 148 | ;; absolute path /foo/bar | ||
| 149 | (should (equal (url-generic-parse-url "http://host/foo/bar") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar" nil nil t))) | ||
| 150 | (should (equal (url-generic-parse-url "http://host/foo/bar?") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar?" nil nil t))) | ||
| 151 | (should (equal (url-generic-parse-url "http://host/foo/bar?query") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar?query" nil nil t))) | ||
| 152 | ;; absolute path /foo/bar/ | ||
| 153 | (should (equal (url-generic-parse-url "http://host/foo/bar/") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar/" nil nil t))) | ||
| 154 | (should (equal (url-generic-parse-url "http://host/foo/bar/?") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar/?" nil nil t))) | ||
| 155 | (should (equal (url-generic-parse-url "http://host/foo/bar/?query") (url-parse-make-urlobj "http" nil nil "host" nil "/foo/bar/?query" nil nil t))) | ||
| 156 | ;; example mentioned in RFC3986, section 5.4. Reference Resolution Examples | ||
| 157 | (should (equal (url-generic-parse-url "http://a/b/c/d;p?q") (url-parse-make-urlobj "http" nil nil "a" nil "/b/c/d;p?q" nil nil t)))) | ||
| 158 | |||
| 159 | (ert-deftest url-generic-parse-url/same-decument-reference () | ||
| 160 | "RFC 3986, section 4.4. Same-Document Reference / same-document reference: empty or number sign (\"#\") followed by a fragment identifier" | ||
| 161 | (should (equal (url-generic-parse-url "") (url-parse-make-urlobj nil nil nil nil nil "" nil nil nil))) | ||
| 162 | (should (equal (url-generic-parse-url "#") (url-parse-make-urlobj nil nil nil nil nil "" "" nil nil))) | ||
| 163 | (should (equal (url-generic-parse-url "#foo") (url-parse-make-urlobj nil nil nil nil nil "" "foo" nil nil)))) | ||
| 164 | |||
| 165 | (provide 'url-parse-tests) | ||
| 166 | |||
| 167 | ;;; url-parse-tests.el ends here | ||