aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorChong Yidong2013-02-04 20:02:25 +0800
committerChong Yidong2013-02-04 20:02:25 +0800
commit6e5c1569e941d385d28466a337ece0322bfa93e7 (patch)
tree4a2cef76a54c9ca882c33f797d9c91980a3554b1 /test
parent84a06b500fd1cb500e89b93d3f5746b60c6ffdd4 (diff)
downloademacs-6e5c1569e941d385d28466a337ece0322bfa93e7.tar.gz
emacs-6e5c1569e941d385d28466a337ece0322bfa93e7.zip
Merge FFAP's URI-detection code into thingatpt.el.
* lisp/ffap.el: Require thingatpt. (ffap-url-at-point): Delegate URI detection to thing-at-point. All URI-valid characters are now recognized. (ffap-string-at-point): Use use-region-p. (ffap-url-regexp): Extra character is handled by thing-at-point. (ffap-string-at-point-mode-alist): Allow parentheses. (ffap-newsgroup-regexp, ffap-newsgroup-heads, ffap-newsgroup-p): Convert to aliases; code moved to thingatpt.el. (ffap-gnus-hook): Use setq-local. * lisp/thingatpt.el: Rewrite the URL detection routines, absorbing some code from ffap.el. (thing-at-point-beginning-of-url-regexp): New var. (thing-at-point-uri-schemes): Update list of URI schemes. (thing-at-point-url-regexp): Variable deleted. (thing-at-point-markedup-url-regexp): Disallow newlines. (thing-at-point-newsgroup-regexp) (thing-at-point-newsgroup-heads) (thing-at-point-default-mail-uri-scheme): New variables. (thing-at-point-bounds-of-url-at-point): Rewrite. Use ffap's method to find the possible bounds of the URI at point. New optional argument to find ill-formed URIs. (thing-at-point-url-at-point): Rewrite. New arguments for finding ill-formed URIs. Use thing-at-point-bounds-of-url-at-point, and the scheme-adding heuristics from ffap-url-at-point. (thing-at-point--bounds-of-well-formed-url): New function. Do parens matching to decide whether to include parens in the URI * test/automated/thingatpt.el: New file. Fixes: debbugs:5673
Diffstat (limited to 'test')
-rw-r--r--test/ChangeLog4
-rw-r--r--test/automated/thingatpt.el88
2 files changed, 92 insertions, 0 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index 651453566f2..41bb1be190e 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
12013-02-04 Chong Yidong <cyd@gnu.org>
2
3 * automated/thingatpt.el: New file.
4
12013-02-03 Chong Yidong <cyd@gnu.org> 52013-02-03 Chong Yidong <cyd@gnu.org>
2 6
3 * automated/files.el (file-test--do-local-variables-test): Avoid 7 * automated/files.el (file-test--do-local-variables-test): Avoid
diff --git a/test/automated/thingatpt.el b/test/automated/thingatpt.el
new file mode 100644
index 00000000000..f33a8f4b0e6
--- /dev/null
+++ b/test/automated/thingatpt.el
@@ -0,0 +1,88 @@
1;;; thingatpt.el --- tests for thing-at-point.
2
3;; Copyright (C) 2013 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23
24(defvar thing-at-point-test-data
25 '(("http://1.gnu.org" 1 url "http://1.gnu.org")
26 ("http://2.gnu.org" 6 url "http://2.gnu.org")
27 ("http://3.gnu.org" 19 url "http://3.gnu.org")
28 ("https://4.gnu.org" 1 url "https://4.gnu.org")
29 ("bzr://savannah.gnu.org" 1 url "bzr://savannah.gnu.org")
30 ("A geo URI (geo:3.14159,-2.71828)." 12 url "geo:3.14159,-2.71828")
31 ("Visit http://5.gnu.org now." 5 url nil)
32 ("Visit http://6.gnu.org now." 7 url "http://6.gnu.org")
33 ("Visit http://7.gnu.org now." 22 url "http://7.gnu.org")
34 ("Visit http://8.gnu.org now." 22 url "http://8.gnu.org")
35 ("Visit http://9.gnu.org now." 24 url nil)
36 ;; Invalid URIs
37 ("<<<<" 2 url nil)
38 ("<>" 1 url nil)
39 ("<url:>" 1 url nil)
40 ("http://" 1 url nil)
41 ;; Invalid schema
42 ("foo://www.gnu.org" 1 url nil)
43 ("foohttp://www.gnu.org" 1 url nil)
44 ;; Non alphanumeric characters can be found in URIs
45 ("ftp://example.net/~foo!;#bar=baz&goo=bob" 3 url "ftp://example.net/~foo!;#bar=baz&goo=bob")
46 ("bzr+ssh://user@example.net:5/a%20d,5" 34 url "bzr+ssh://user@example.net:5/a%20d,5")
47 ;; <url:...> markup
48 ("Url: <url:foo://1.example.com>..." 8 url "foo://1.example.com")
49 ("Url: <url:foo://2.example.com>..." 30 url "foo://2.example.com")
50 ("Url: <url:foo://www.gnu.org/a bc>..." 20 url "foo://www.gnu.org/a bc")
51 ;; Hack used by thing-at-point: drop punctuation at end of URI.
52 ("Go to http://www.gnu.org, for details" 7 url "http://www.gnu.org")
53 ("Go to http://www.gnu.org." 24 url "http://www.gnu.org")
54 ;; Standard URI delimiters
55 ("Go to \"http://10.gnu.org\"." 8 url "http://10.gnu.org")
56 ("Go to \"http://11.gnu.org/\"." 26 url "http://11.gnu.org/")
57 ("Go to <http://12.gnu.org> now." 8 url "http://12.gnu.org")
58 ("Go to <http://13.gnu.org> now." 24 url "http://13.gnu.org")
59 ;; Parenthesis handling (non-standard)
60 ("http://example.com/a(b)c" 21 url "http://example.com/a(b)c")
61 ("http://example.com/a(b)" 21 url "http://example.com/a(b)")
62 ("(http://example.com/abc)" 2 url "http://example.com/abc")
63 ("This (http://example.com/a(b))" 7 url "http://example.com/a(b)")
64 ("This (http://example.com/a(b))" 30 url "http://example.com/a(b)")
65 ("This (http://example.com/a(b))" 5 url nil)
66 ("http://example.com/ab)c" 4 url "http://example.com/ab)c")
67 ;; URL markup, lacking schema
68 ("<url:foo@example.com>" 1 url "mailto:foo@example.com")
69 ("<url:ftp.example.net/abc/>" 1 url "ftp://ftp.example.net/abc/"))
70 "List of thing-at-point tests.
71Each list element should have the form
72
73 (STRING POS THING RESULT)
74
75where STRING is a string of buffer contents, POS is the value of
76point, THING is a symbol argument for `thing-at-point', and
77RESULT should be the result of calling `thing-at-point' from that
78position to retrieve THING.")
79
80(ert-deftest thing-at-point-tests ()
81 "Test the file-local variables implementation."
82 (dolist (test thing-at-point-test-data)
83 (with-temp-buffer
84 (insert (nth 0 test))
85 (goto-char (nth 1 test))
86 (should (equal (thing-at-point (nth 2 test)) (nth 3 test))))))
87
88;;; thingatpt.el ends here