1 ;; Copyright (C) 2001 Free Software Foundation, Inc.
3 ;; Author: Hrvoje Niksic <hniksic@xemacs.org>
4 ;; Maintainer: Hrvoje Niksic <hniksic@xemacs.org>
8 ;; This file is part of XEmacs.
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)
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.
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
25 ;;; Synched up with: Not in FSF.
29 ;; Test extents operations.
30 ;; See test-harness.el for instructions on how to run these tests.
34 (require 'test-harness)
37 (when (and (boundp 'load-file-name) (stringp load-file-name))
38 (push (file-name-directory load-file-name) load-path))
39 (require 'test-harness))))
42 ;;-----------------------------------------------------
43 ;; Creating and attaching.
44 ;;-----------------------------------------------------
47 (let ((extent (make-extent nil nil))
48 (string "somecoolstring"))
51 (Assert (extent-detached-p extent))
53 ;; Put it in a buffer.
54 (set-extent-endpoints extent 1 1 (current-buffer))
55 (Assert (eq (extent-object extent) (current-buffer)))
57 ;; And then into another buffer.
59 (set-extent-endpoints extent 1 1 (current-buffer))
60 (Assert (eq (extent-object extent) (current-buffer))))
62 ;; Now that the buffer doesn't exist, extent should be detached
64 (Assert (extent-detached-p extent))
66 ;; This line crashes XEmacs 21.2.46 and prior.
67 (set-extent-endpoints extent 1 (length string) string)
68 (Assert (eq (extent-object extent) string))
71 (let ((extent (make-extent 1 1)))
72 ;; By default, extent should be closed-open
73 (Assert (eq (get extent 'start-closed) t))
74 (Assert (eq (get extent 'start-open) nil))
75 (Assert (eq (get extent 'end-open) t))
76 (Assert (eq (get extent 'end-closed) nil))
78 ;; Make it closed-closed.
79 (set-extent-property extent 'end-closed t)
81 (Assert (eq (get extent 'start-closed) t))
82 (Assert (eq (get extent 'start-open) nil))
83 (Assert (eq (get extent 'end-open) nil))
84 (Assert (eq (get extent 'end-closed) t))
87 (set-extent-property extent 'start-open t)
89 (Assert (eq (get extent 'start-closed) nil))
90 (Assert (eq (get extent 'start-open) t))
91 (Assert (eq (get extent 'end-open) nil))
92 (Assert (eq (get extent 'end-closed) t))
95 (set-extent-property extent 'end-open t)
97 (Assert (eq (get extent 'start-closed) nil))
98 (Assert (eq (get extent 'start-open) t))
99 (Assert (eq (get extent 'end-open) t))
100 (Assert (eq (get extent 'end-closed) nil)))
104 ;;-----------------------------------------------------
105 ;; Insertion behavior.
106 ;;-----------------------------------------------------
108 (defun et-range (extent)
109 "List (START-POSITION END-POSITION) of EXTENT."
110 (list (extent-start-position extent)
111 (extent-end-position extent)))
113 (defun et-insert-at (string position)
114 "Insert STRING at POSITION in the current buffer."
119 ;; Test insertion at the beginning, middle, and end of the extent.
125 (let ((e (make-extent 4 7)))
126 ;; current state: "###[eee)###"
128 (Assert (equal (et-range e) '(4 7)))
130 (et-insert-at "xxx" 4)
132 ;; current state: "###[xxxeee)###"
134 (Assert (equal (et-range e) '(4 10)))
136 (et-insert-at "yyy" 7)
138 ;; current state: "###[xxxyyyeee)###"
140 (Assert (equal (et-range e) '(4 13)))
142 (et-insert-at "zzz" 13)
144 ;; current state: "###[xxxyyyeee)zzz###"
145 ;; 123 456789012 345678
146 (Assert (equal (et-range e) '(4 13)))
153 (let ((e (make-extent 4 7)))
154 (put e 'end-closed t)
156 ;; current state: "###[eee]###"
158 (Assert (equal (et-range e) '(4 7)))
160 (et-insert-at "xxx" 4)
162 ;; current state: "###[xxxeee]###"
164 (Assert (equal (et-range e) '(4 10)))
166 (et-insert-at "yyy" 7)
168 ;; current state: "###[xxxyyyeee]###"
170 (Assert (equal (et-range e) '(4 13)))
172 (et-insert-at "zzz" 13)
174 ;; current state: "###[xxxyyyeeezzz]###"
175 ;; 123 456789012345 678
176 (Assert (equal (et-range e) '(4 16)))
183 (let ((e (make-extent 4 7)))
184 (put e 'start-open t)
185 (put e 'end-closed t)
187 ;; current state: "###(eee]###"
189 (Assert (equal (et-range e) '(4 7)))
191 (et-insert-at "xxx" 4)
193 ;; current state: "###xxx(eee]###"
195 (Assert (equal (et-range e) '(7 10)))
197 (et-insert-at "yyy" 8)
199 ;; current state: "###xxx(eyyyee]###"
201 (Assert (equal (et-range e) '(7 13)))
203 (et-insert-at "zzz" 13)
205 ;; current state: "###xxx(eyyyeezzz]###"
206 ;; 123456 789012345 678
207 (Assert (equal (et-range e) '(7 16)))
214 (let ((e (make-extent 4 7)))
215 (put e 'start-open t)
217 ;; current state: "###(eee)###"
219 (Assert (equal (et-range e) '(4 7)))
221 (et-insert-at "xxx" 4)
223 ;; current state: "###xxx(eee)###"
225 (Assert (equal (et-range e) '(7 10)))
227 (et-insert-at "yyy" 8)
229 ;; current state: "###xxx(eyyyee)###"
231 (Assert (equal (et-range e) '(7 13)))
233 (et-insert-at "zzz" 13)
235 ;; current state: "###xxx(eyyyee)zzz###"
236 ;; 123456 789012 345678
237 (Assert (equal (et-range e) '(7 13)))
241 ;;-----------------------------------------------------
242 ;; Deletion behavior.
243 ;;-----------------------------------------------------
245 (dolist (props '((start-closed t end-open t)
246 (start-closed t end-open nil)
247 (start-closed nil end-open nil)
248 (start-closed nil end-open t)))
249 ;; Deletion needs to behave the same regardless of the open-ness of
253 (insert "xxxxxxxxxx")
254 (let ((e (make-extent 3 9)))
255 (set-extent-properties e props)
257 ;; current state: xx[xxxxxx]xx
259 (Assert (equal (et-range e) '(3 9)))
263 ;; current state: x[xxxxxx]xx
265 (Assert (equal (et-range e) '(2 8)))
269 ;; current state: x[xxxx]xx
271 (Assert (equal (et-range e) '(2 6)))
275 ;; current state: [xxx]xx
277 (Assert (equal (et-range e) '(1 4)))
281 ;; current state: [xx]x
283 (Assert (equal (et-range e) '(1 3)))
287 ;;; #### Should have a test for read-only-ness and insertion and
290 ;;-----------------------------------------------------
291 ;; `detachable' property
292 ;;-----------------------------------------------------
294 (dolist (props '((start-closed t end-open t)
295 (start-closed t end-open nil)
296 (start-closed nil end-open nil)
297 (start-closed nil end-open t)))
298 ;; `detachable' shouldn't relate to region properties, hence the
302 (let ((e (make-extent 4 7)))
303 (set-extent-properties e props)
304 (Assert (get e 'detachable))
306 (Assert (not (extent-detached-p e)))
309 ;; ###ee### (not detached yet)
310 (Assert (not (extent-detached-p e)))
313 ;; ###### (should be detached now)
314 (Assert (extent-detached-p e))))
318 (let ((e (make-extent 4 7)))
319 (set-extent-properties e props)
320 (put e 'detachable nil)
321 (Assert (not (get e 'detachable)))
323 (Assert (not (extent-detached-p e)))
327 (Assert (not (extent-detached-p e)))
331 (Assert (not (extent-detached-p e)))
332 (Assert (equal (et-range e) '(4 4)))
337 ;;-----------------------------------------------------
338 ;; Zero-length extents.
339 ;;-----------------------------------------------------
341 ;; closed-open (should stay put)
344 (let ((e (make-extent 4 4)))
345 (et-insert-at "foo" 4)
346 (Assert (equal (et-range e) '(4 4)))))
348 ;; open-closed (should move)
351 (let ((e (make-extent 4 4)))
352 (put e 'start-open t)
353 (put e 'end-closed t)
354 (et-insert-at "foo" 4)
355 (Assert (equal (et-range e) '(7 7)))))
357 ;; closed-closed (should extend)
360 (let ((e (make-extent 4 4)))
361 (put e 'end-closed t)
362 (et-insert-at "foo" 4)
363 (Assert (equal (et-range e) '(4 7)))))
365 ;; open-open (illegal; forced to behave like closed-open)
368 (let ((e (make-extent 4 4)))
369 (put e 'start-open t)
370 (et-insert-at "foo" 4)
371 (Assert (equal (et-range e) '(4 4)))))