Mercurial > hg > xemacs-beta
annotate tests/automated/syntax-tests.el @ 5328:dae3d95cf319
Merge.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 02 Jan 2011 02:32:59 +0000 |
parents | 0f66906b6e37 |
children | 308d34e9f07d |
rev | line source |
---|---|
398 | 1 ;; Copyright (C) 1999 Free Software Foundation, Inc. |
2 | |
3 ;; Author: Yoshiki Hayashi <t90553@mail.ecc.u-tokyo.ac.jp> | |
4 ;; Maintainer: Yoshiki Hayashi <t90553@mail.ecc.u-tokyo.ac.jp> | |
5 ;; Created: 1999 | |
6 ;; Keywords: tests | |
7 | |
8 ;; This file is part of XEmacs. | |
9 | |
10 ;; XEmacs is free software; you can redistribute it and/or modify it | |
11 ;; under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; XEmacs is distributed in the hope that it will be useful, but | |
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 ;; General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
23 ;; 02111-1307, USA. | |
24 | |
25 ;;; Synched up with: Not in FSF. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; Test syntax related functions. | |
30 ;; Right now it tests scan_words using forward-word and backward-word. | |
31 ;; See test-harness.el for instructions on how to run these tests. | |
32 | |
33 ;;; Notation | |
34 ;; W: word constituent character. | |
35 ;; NW: non word constituent character. | |
36 ;; -!-: current point. | |
37 ;; EOB: end of buffer | |
38 ;; BOB: beginning of buffer. | |
39 | |
40 ;; Algorithm of scan_words is simple. It just searches SW and then | |
41 ;; moves to NW. When with MULE, it also stops at word boundary. Word | |
42 ;; boundary is tricky and listing all possible cases will be huge. | |
43 ;; Those test are omitted here as it doesn't affect core | |
44 ;; functionality. | |
45 | |
46 (defun test-forward-word (string stop) | |
47 (goto-char (point-max)) | |
48 (let ((point (point))) | |
49 (insert string) | |
50 (goto-char point) | |
51 (forward-word 1) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5065
diff
changeset
|
52 (Assert (eq (point) (+ point stop))))) |
398 | 53 |
54 (with-temp-buffer | |
55 ;; -!- W NW | |
56 (test-forward-word "W " 1) | |
57 (test-forward-word "WO " 2) | |
58 ;; -!- W EOB | |
59 (test-forward-word "W" 1) | |
60 (test-forward-word "WO" 2) | |
61 ;; -!- NW EOB | |
62 (test-forward-word " " 1) | |
63 (test-forward-word " !" 2) | |
64 ;; -!- NW W NW | |
65 (test-forward-word " W " 2) | |
66 (test-forward-word " WO " 3) | |
67 (test-forward-word " !W " 3) | |
68 (test-forward-word " !WO " 4) | |
69 ;; -!- NW W EOB | |
70 (test-forward-word " W" 2) | |
71 (test-forward-word " WO" 3) | |
72 (test-forward-word " !W" 3) | |
73 (test-forward-word " !WO" 4)) | |
74 | |
75 (defun test-backward-word (string stop) | |
76 (goto-char (point-min)) | |
77 (insert string) | |
78 (let ((point (point))) | |
79 (backward-word 1) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5065
diff
changeset
|
80 (Assert (eq (point) (- point stop))))) |
398 | 81 |
82 (with-temp-buffer | |
83 ;; NW W -!- | |
84 (test-backward-word " W" 1) | |
85 (test-backward-word " WO" 2) | |
86 ;; BOB W -!- | |
87 (test-backward-word "W" 1) | |
88 (test-backward-word "WO" 2) | |
89 ;; BOB NW -!- | |
90 ;; -!-NW EOB | |
91 (test-backward-word " " 1) | |
92 (test-backward-word " !" 2) | |
93 ;; NW W NW -!- | |
94 (test-backward-word " W " 2) | |
95 (test-backward-word " WO " 3) | |
96 (test-backward-word " W !" 3) | |
97 (test-backward-word " WO !" 4) | |
98 ;; BOB W NW -!- | |
99 (test-backward-word "W " 2) | |
100 (test-backward-word "WO " 3) | |
101 (test-backward-word "W !" 3) | |
102 (test-backward-word "WO !" 4)) | |
460 | 103 |
104 ;; Works like test-forward-word, except for the following: | |
105 ;; after <string> is inserted, the syntax-table <apply-syntax> | |
106 ;; is applied to position <apply-pos>. | |
107 ;; <apply-pos> can be in the form (start . end), or can be a | |
108 ;; character position. | |
109 (defun test-syntax-table (string apply-pos apply-syntax stop) | |
1024 | 110 ;; We don't necessarily have syntax-table properties ... |
111 (when (fboundp 'lookup-syntax-properties) ; backwards compatible kludge | |
112 ;; ... and they may not be enabled by default if we do. | |
113 (setq lookup-syntax-properties t) | |
114 (goto-char (point-max)) | |
115 (unless (consp apply-pos) | |
116 (setq apply-pos `(,apply-pos . ,(+ 1 apply-pos)))) | |
117 (let ((point (point))) | |
118 (insert string) | |
119 (put-text-property (+ point (car apply-pos)) (+ point (cdr apply-pos)) | |
120 'syntax-table apply-syntax) | |
121 (goto-char point) | |
122 (forward-word 1) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5065
diff
changeset
|
123 (Assert (eq (point) (+ point stop)))))) |
460 | 124 |
125 ;; test syntax-table extents | |
126 (with-temp-buffer | |
127 ;; Apply punctuation to word | |
128 (test-syntax-table "WO" 1 `(,(syntax-string-to-code ".")) 1) | |
129 ;; Apply word to punctuation | |
130 (test-syntax-table "W." 1 `(,(syntax-string-to-code "w")) 2)) | |
131 | |
3880 | 132 ;; According to Ralf Angeli in |
133 ;; http://article.gmane.org/gmane.emacs.xemacs.beta/17353: | |
134 ;; Using a fresh CVS checkout of XEmacs trunk the following snippet | |
135 ;; returns "1" when evaluated whereas it returns "5" in GNU Emacs 21.3, | |
136 ;; CVS GNU Emacs and XEmacs 21.4.15. | |
137 ;; If `set-syntax-table' is used instead of `with-syntax-table', CVS | |
138 ;; XEmacs returns "5" as well, so I suppose that there is a problem in | |
139 ;; `with-syntax-table' or a function called by it. | |
140 | |
141 ;; Fixed 2007-03-25 Olivier Galibert <20070324221053.GA48218@dspnet.fr.eu.org> | |
142 (with-temp-buffer | |
143 (with-syntax-table (make-syntax-table) | |
144 (insert "foo bar") | |
145 (backward-sexp 1) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5065
diff
changeset
|
146 (Assert (eql (point) 5)))) |
3880 | 147 |
460 | 148 ;; Test forward-comment at buffer boundaries |
1024 | 149 ;; #### The second Assert fails (once interpreted, once compiled) on 21.4.9 |
150 ;; with sjt's version of Andy's syntax-text-property-killer patch. | |
460 | 151 (with-temp-buffer |
1095 | 152 (Skip-Test-Unless (fboundp 'c-mode) |
153 "c-mode unavailable" | |
154 "comment and parse-partial-sexp tests" | |
973 | 155 (c-mode) |
156 | |
157 (insert "// comment\n") | |
158 (forward-comment -2) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5065
diff
changeset
|
159 (Assert (eq (point) (point-min))) |
460 | 160 |
973 | 161 (let ((point (point))) |
162 (insert "/* comment */") | |
163 (goto-char point) | |
164 (forward-comment 2) | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5065
diff
changeset
|
165 (Assert (eq (point) (point-max))) |
460 | 166 |
973 | 167 ;; this last used to crash |
168 (parse-partial-sexp point (point-max))))) | |
3130 | 169 |
170 ;; Test backward-up-list | |
171 ;; Known-Bug: report = Evgeny Zacjev ca 2005-12-01, confirm = Aidan Kehoe | |
172 | |
173 (with-temp-buffer | |
174 ;; We are now using the standard syntax table. Thus there's no need to | |
175 ;; worry about a bogus syntax setting, eg, in a Gnus Article buffer the | |
176 ;; bug doesn't manifest. | |
177 | |
178 ;; value of point to the immediate left of this character | |
179 ;; 0 1 2 | |
180 ;; 1234 56789 012 34567 890 12 3456 7 | |
181 (insert "a ( \"b (c\" (\"defg\") \")\") h\n") | |
182 | |
183 ;; #### This test should check *every* position. | |
184 (flet ((backward-up-list-moves-point-from-to (start expected-end) | |
185 (goto-char start) | |
186 (backward-up-list 1) | |
187 (= (point) expected-end))) | |
188 (Known-Bug-Expect-Failure | |
189 ;; Evgeny's case | |
190 (Assert (backward-up-list-moves-point-from-to 16 12))) | |
191 (Assert (backward-up-list-moves-point-from-to 19 12)) | |
192 (Assert (backward-up-list-moves-point-from-to 20 3)) | |
193 (Known-Bug-Expect-Failure | |
194 (Assert (backward-up-list-moves-point-from-to 22 3))) | |
5065
133e816778ed
fix expected-buggy test to avoid abort in test file
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
195 (Known-Bug-Expect-Error scan-error |
133e816778ed
fix expected-buggy test to avoid abort in test file
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
196 (Assert (backward-up-list-moves-point-from-to 23 3)) |
133e816778ed
fix expected-buggy test to avoid abort in test file
Ben Wing <ben@xemacs.org>
parents:
4855
diff
changeset
|
197 ) |
3130 | 198 (Assert (backward-up-list-moves-point-from-to 24 3)) |
199 ;; This is maybe a little tricky, since we don't expect the position | |
200 ;; check to happen -- so use an illegal expected position | |
201 ;; I don't think there's any other way for this to fail that way, | |
202 ;; barring hardware error.... | |
203 (Check-Error-Message syntax-error | |
204 "Unbalanced parentheses" | |
205 (backward-up-list-moves-point-from-to 25 nil)) | |
206 ;; special-case check that point didn't move | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5065
diff
changeset
|
207 (Assert (= (point) 25)))) |
3130 | 208 |
4324
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
209 (loop |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
210 with envvar-not-existing = (symbol-name (gensym "whatever")) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
211 with envvar-existing = (symbol-name (gensym "whatever")) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
212 with envvar-existing-val = (make-string #x10000 ?\xe1) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
213 with examples = |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
214 (list (list (format "%chome%cwhatever%c%chi-there%c$%s" |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
215 directory-sep-char |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
216 directory-sep-char |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
217 directory-sep-char |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
218 directory-sep-char |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
219 directory-sep-char |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
220 envvar-existing) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
221 (format "%chi-there%c%s" |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
222 directory-sep-char |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
223 directory-sep-char |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
224 envvar-existing-val)) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
225 (if (memq system-type '(windows-nt cygwin32)) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
226 '("//network-path/c$" "//network-path/c$") |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
227 '("/network-path/c$" "/network-path/c$")) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
228 (list (format "/home/whoever/$%s" envvar-not-existing) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
229 (format "/home/whoever/$%s" envvar-not-existing)) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
230 (list (format "/home/whoever/$%s" envvar-existing) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
231 (format "/home/whoever/%s" envvar-existing-val)) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
232 (list (format "/home/whoever/${%s}" envvar-existing) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
233 (format "/home/whoever/%s" envvar-existing-val)) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
234 (list (format "/home/whoever/${%s}" envvar-not-existing) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
235 (format "/home/whoever/${%s}" envvar-not-existing))) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
236 initially (progn (setenv envvar-not-existing nil t) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
237 (setenv envvar-existing envvar-existing-val)) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
238 for (pre post) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
239 in examples |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
240 do |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
241 (Assert (string= post (substitute-in-file-name pre)))) |
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3880
diff
changeset
|
242 |