OSDN Git Service

Merge branch 'master' of git://github.com/monaka/binutils
[pf3gnuchains/pf3gnuchains3x.git] / tk / tests / textIndex.test
1 # This file is a Tcl script to test the code in the file tkTextIndex.c.
2 # This file is organized in the standard fashion for Tcl tests.
3 #
4 # Copyright (c) 1994 The Regents of the University of California.
5 # Copyright (c) 1994 Sun Microsystems, Inc.
6 # Copyright (c) 1998-1999 by Scriptics Corporation.
7 # All rights reserved.
8 #
9 # RCS: @(#) $Id$
10
11 package require tcltest 2.1
12 namespace import -force tcltest::configure
13 namespace import -force tcltest::testsDirectory
14 configure -testdir [file join [pwd] [file dirname [info script]]]
15 configure -loadfile [file join [testsDirectory] constraints.tcl]
16 tcltest::loadTestedCommands
17
18 # Some tests require the testtext command
19 testConstraint testtext [llength [info commands testtext]]
20
21 catch {destroy .t}
22 text .t -font {Courier -12} -width 20 -height 10
23 pack append . .t {top expand fill}
24 update
25 .t debug on
26 wm geometry . {}
27   
28 # The statements below reset the main window;  it's needed if the window
29 # manager is mwm to make mwm forget about a previous minimum size setting.
30
31 wm withdraw .
32 wm minsize . 1 1
33 wm positionfrom . user
34 wm deiconify .
35
36 .t insert 1.0 "Line 1
37 abcdefghijklm
38 12345
39 Line 4
40 b\u4e4fy GIrl .#@? x_yz
41 !@#$%
42 Line 7"
43
44 image create photo textimage -width 10 -height 10
45 textimage put red -to 0 0 9 9
46
47 test textIndex-1.1 {TkTextMakeByteIndex} {testtext} {
48     # (lineIndex < 0)
49     testtext .t byteindex -1 3
50 } {1.0 0}
51 test textIndex-1.2 {TkTextMakeByteIndex} {testtext} {
52     # (lineIndex < 0), because lineIndex == strtol(argv[2]) - 1
53     testtext .t byteindex 0 3
54 } {1.0 0}
55 test textIndex-1.3 {TkTextMakeByteIndex} {testtext} {
56     # not (lineIndex < 0)
57     testtext .t byteindex 1 3
58 } {1.3 3}
59 test textIndex-1.4 {TkTextMakeByteIndex} {testtext} {
60     # (byteIndex < 0)
61     testtext .t byteindex 3 -1
62 } {3.0 0}
63 test textIndex-1.5 {TkTextMakeByteIndex} {testtext} {
64     # not (byteIndex < 0)
65     testtext .t byteindex 3 3
66 } {3.3 3}
67 test textIndex-1.6 {TkTextMakeByteIndex} {testtext} {
68     # (indexPtr->linePtr == NULL)
69     testtext .t byteindex 9 2
70 } {8.0 0}
71 test textIndex-1.7 {TkTextMakeByteIndex} {testtext} {
72     # not (indexPtr->linePtr == NULL)
73     testtext .t byteindex 7 2
74 } {7.2 2}
75 test textIndex-1.8 {TkTextMakeByteIndex: shortcut for 0} {testtext} {
76     # (byteIndex == 0)
77     testtext .t byteindex 1 0
78 } {1.0 0}
79 test textIndex-1.9 {TkTextMakeByteIndex: shortcut for 0} {testtext} {
80     # not (byteIndex == 0)
81     testtext .t byteindex 3 80
82 } {3.5 5}
83 test textIndex-1.10 {TkTextMakeByteIndex: verify index is in range} {testtext} {
84     # for (segPtr = indexPtr->linePtr->segPtr; ; segPtr = segPtr->nextPtr) 
85     # one segment
86
87     testtext .t byteindex 3 5
88 } {3.5 5}
89 test textIndex-1.11 {TkTextMakeByteIndex: verify index is in range} {testtext} {
90     # for (segPtr = indexPtr->linePtr->segPtr; ; segPtr = segPtr->nextPtr)
91     #     index += segPtr->size
92     # Multiple segments, make sure add segment size to index.
93
94     .t mark set foo 3.2 
95     set x [testtext .t byteindex 3 7]
96     .t mark unset foo
97     set x
98 } {3.5 5}
99 test textIndex-1.12 {TkTextMakeByteIndex: verify index is in range} {testtext} {
100     # (segPtr == NULL)
101     testtext .t byteindex 3 7
102 } {3.5 5}
103 test textIndex-1.13 {TkTextMakeByteIndex: verify index is in range} {testtext} {
104     # not (segPtr == NULL)
105     testtext .t byteindex 3 4
106 } {3.4 4}
107 test textIndex-1.14 {TkTextMakeByteIndex: verify index is in range} {testtext} {
108     # (index + segPtr->size > byteIndex)
109     # in this segment.
110
111     testtext .t byteindex 3 4
112 } {3.4 4}
113 test textIndex-1.15 {TkTextMakeByteIndex: verify index is in range} {testtext} {
114     # (index + segPtr->size > byteIndex), index != 0
115     # in this segment.
116
117     .t mark set foo 3.2
118     set x [testtext .t byteindex 3 4]
119     .t mark unset foo
120     set x
121 } {3.4 4}
122 test textIndex-1.16 {TkTextMakeByteIndex: UTF-8 characters} {testtext} {
123     testtext .t byteindex 5 100
124 } {5.18 20}
125 test textIndex-1.17 {TkTextMakeByteIndex: prevent splitting UTF-8 character} \
126         {testtext} {
127     # ((byteIndex > index) && (segPtr->typePtr == &tkTextCharType)) 
128     # Wrong answer would be \xb9 (the 2nd byte of UTF rep of 0x4e4f).
129
130     set x [testtext .t byteindex 5 2]
131     list $x [.t get insert]
132 } {{5.2 4} y}
133 test textIndex-1.18 {TkTextMakeByteIndex: prevent splitting UTF-8 character} \
134         {testtext} {
135     # ((byteIndex > index) && (segPtr->typePtr == &tkTextCharType)) 
136     testtext .t byteindex 5 1
137     .t get insert
138 } "\u4e4f"
139
140 test textIndex-2.1 {TkTextMakeCharIndex} {
141     # (lineIndex < 0)
142     .t index -1.3
143 } 1.0
144 test textIndex-2.2 {TkTextMakeCharIndex} {
145     # (lineIndex < 0), because lineIndex == strtol(argv[2]) - 1
146     .t index 0.3
147 } 1.0
148 test textIndex-2.3 {TkTextMakeCharIndex} {
149     # not (lineIndex < 0)
150     .t index 1.3
151 } 1.3
152 test textIndex-2.4 {TkTextMakeCharIndex} {
153     # (charIndex < 0)
154     .t index 3.-1
155 } 3.0
156 test textIndex-2.5 {TkTextMakeCharIndex} {
157     # (charIndex < 0)
158     .t index 3.3
159 } 3.3
160 test textIndex-2.6 {TkTextMakeCharIndex} {
161     # (indexPtr->linePtr == NULL)
162     .t index 9.2
163 } 8.0
164 test textIndex-2.7 {TkTextMakeCharIndex} {
165     # not (indexPtr->linePtr == NULL)
166     .t index 7.2
167 } 7.2
168 test textIndex-2.8 {TkTextMakeCharIndex: verify index is in range} {
169     # for (segPtr = indexPtr->linePtr->segPtr; ; segPtr = segPtr->nextPtr)
170     # one segment
171
172     .t index 3.5
173 } 3.5
174 test textIndex-2.9 {TkTextMakeCharIndex: verify index is in range} {
175     # for (segPtr = indexPtr->linePtr->segPtr; ; segPtr = segPtr->nextPtr)
176     # Multiple segments, make sure add segment size to index.
177
178     .t mark set foo 3.2 
179     set x [.t index 3.7]
180     .t mark unset foo
181     set x
182 } 3.5
183 test textIndex-2.10 {TkTextMakeCharIndex: verify index is in range} {
184     # (segPtr == NULL)
185     .t index 3.7
186 } 3.5
187 test textIndex-2.11 {TkTextMakeCharIndex: verify index is in range} {
188     # not (segPtr == NULL)
189     .t index 3.4
190 } 3.4
191 test textIndex-2.12 {TkTextMakeCharIndex: verify index is in range} {
192     # (segPtr->typePtr == &tkTextCharType)
193     # Wrong answer would be \xb9 (the 2nd byte of UTF rep of 0x4e4f).
194
195     .t mark set insert 5.2
196     .t get insert
197 } y
198 test textIndex-2.13 {TkTextMakeCharIndex: verify index is in range} {
199     # not (segPtr->typePtr == &tkTextCharType)
200
201     .t image create 5.2 -image textimage
202     .t mark set insert 5.5
203     set x [.t get insert]
204     .t delete 5.2
205     set x
206 } "G"
207 test textIndex-2.14 {TkTextMakeCharIndex: verify index is in range} {
208     # (charIndex < segPtr->size)
209
210     .t image create 5.0 -image textimage
211     set x [.t index 5.0]
212     .t delete 5.0
213     set x
214 } 5.0
215
216 .t mark set foo 3.2
217 .t tag add x 2.8 2.11
218 .t tag add x 6.0 6.2
219 set weirdTag "funny . +- 22.1\n\t{"
220 .t tag add $weirdTag 2.1  2.6
221 set weirdMark "asdf \n{-+ 66.2\t"
222 .t mark set $weirdMark 4.0
223 .t tag config y -relief raised
224 test textIndex-3.1 {TkTextGetIndex, weird mark names} {
225     list [catch {.t index $weirdMark} msg] $msg
226 } {0 4.0}
227
228 test textIndex-4.1 {TkTextGetIndex, tags} {
229     list [catch {.t index x.first} msg] $msg
230 } {0 2.8}
231 test textIndex-4.2 {TkTextGetIndex, tags} {
232     list [catch {.t index x.last} msg] $msg
233 } {0 6.2}
234 test textIndex-4.3 {TkTextGetIndex, weird tags} {
235     list [.t index $weirdTag.first+1c] [.t index $weirdTag.last+2c]
236 } {2.2 2.8}
237 test textIndex-4.4 {TkTextGetIndex, tags} {
238     list [catch {.t index x.gorp} msg] $msg
239 } {1 {bad text index "x.gorp"}}
240 test textIndex-4.5 {TkTextGetIndex, tags} {
241     list [catch {.t index foo.last} msg] $msg
242 } {1 {bad text index "foo.last"}}
243 test textIndex-4.6 {TkTextGetIndex, tags} {
244     list [catch {.t index y.first} msg] $msg
245 } {1 {text doesn't contain any characters tagged with "y"}}
246 test textIndex-4.7 {TkTextGetIndex, tags} {
247     list [catch {.t index x.last,} msg] $msg
248 } {1 {bad text index "x.last,"}}
249 test textIndex-4.8 {TkTextGetIndex, tags} {
250     .t tag add z 1.0
251     set result [list [.t index z.first] [.t index z.last]]
252     .t tag delete z
253     set result
254 } {1.0 1.1}
255
256 test textIndex-5.1 {TkTextGetIndex, "@"} {nonPortable fonts} {
257     .t index @12,9
258 } 1.1
259 test textIndex-5.2 {TkTextGetIndex, "@"} {fonts} {
260     .t index @-2,7
261 } 1.0
262 test textIndex-5.3 {TkTextGetIndex, "@"} {fonts} {
263     .t index @10,-7
264 } 1.0
265 test textIndex-5.4 {TkTextGetIndex, "@"} {fonts} {
266     list [catch {.t index @x} msg] $msg
267 } {1 {bad text index "@x"}}
268 test textIndex-5.5 {TkTextGetIndex, "@"} {fonts} {
269     list [catch {.t index @10q} msg] $msg
270 } {1 {bad text index "@10q"}}
271 test textIndex-5.6 {TkTextGetIndex, "@"} {fonts} {
272     list [catch {.t index @10,} msg] $msg
273 } {1 {bad text index "@10,"}}
274 test textIndex-5.7 {TkTextGetIndex, "@"} {fonts} {
275     list [catch {.t index @10,a} msg] $msg
276 } {1 {bad text index "@10,a"}}
277 test textIndex-5.8 {TkTextGetIndex, "@"} {fonts} {
278     list [catch {.t index @10,9,} msg] $msg
279 } {1 {bad text index "@10,9,"}}
280
281 test textIndex-6.1 {TkTextGetIndex, numeric} {
282     list [catch {.t index 2.3} msg] $msg
283 } {0 2.3}
284 test textIndex-6.2 {TkTextGetIndex, numeric} {
285     list [catch {.t index -} msg] $msg
286 } {1 {bad text index "-"}}
287 test textIndex-6.3 {TkTextGetIndex, numeric} {
288     list [catch {.t index 2.end} msg] $msg
289 } {0 2.13}
290 test textIndex-6.4 {TkTextGetIndex, numeric} {
291     list [catch {.t index 2.x} msg] $msg
292 } {1 {bad text index "2.x"}}
293 test textIndex-6.5 {TkTextGetIndex, numeric} {
294     list [catch {.t index 2.3x} msg] $msg
295 } {1 {bad text index "2.3x"}}
296
297 test textIndex-7.1 {TkTextGetIndex, miscellaneous other bases} {
298     list [catch {.t index end} msg] $msg
299 } {0 8.0}
300 test textIndex-7.2 {TkTextGetIndex, miscellaneous other bases} {
301     list [catch {.t index foo} msg] $msg
302 } {0 3.2}
303 test textIndex-7.3 {TkTextGetIndex, miscellaneous other bases} {
304     list [catch {.t index foo+1c} msg] $msg
305 } {0 3.3}
306
307 test textIndex-8.1 {TkTextGetIndex, modifiers} {
308     list [catch {.t index 2.1+1char} msg] $msg
309 } {0 2.2}
310 test textIndex-8.2 {TkTextGetIndex, modifiers} {
311     list [catch {.t index "2.1          +1char"} msg] $msg
312 } {0 2.2}
313 test textIndex-8.3 {TkTextGetIndex, modifiers} {
314     list [catch {.t index 2.1-1char} msg] $msg
315 } {0 2.0}
316 test textIndex-8.4 {TkTextGetIndex, modifiers} {
317     list [catch {.t index {2.1  }} msg] $msg
318 } {0 2.1}
319 test textIndex-8.5 {TkTextGetIndex, modifiers} {
320     list [catch {.t index {2.1+foo bar}} msg] $msg
321 } {1 {bad text index "2.1+foo bar"}}
322 test textIndex-8.6 {TkTextGetIndex, modifiers} {
323     list [catch {.t index {2.1 foo bar}} msg] $msg
324 } {1 {bad text index "2.1 foo bar"}}
325
326 test textIndex-9.1 {TkTextIndexCmp} {
327     list [.t compare 3.1 < 3.2] [.t compare 3.1 == 3.2]
328 } {1 0}
329 test textIndex-9.2 {TkTextIndexCmp} {
330     list [.t compare 3.2 < 3.2] [.t compare 3.2 == 3.2]
331 } {0 1}
332 test textIndex-9.3 {TkTextIndexCmp} {
333     list [.t compare 3.3 < 3.2] [.t compare 3.3 == 3.2]
334 } {0 0}
335 test textIndex-9.4 {TkTextIndexCmp} {
336     list [.t compare 2.1 < 3.2] [.t compare 2.1 == 3.2]
337 } {1 0}
338 test textIndex-9.5 {TkTextIndexCmp} {
339     list [.t compare 4.1 < 3.2] [.t compare 4.1 == 3.2]
340 } {0 0}
341
342 test textIndex-10.1 {ForwBack} {
343     list [catch {.t index {2.3 + x}} msg] $msg
344 } {1 {bad text index "2.3 + x"}}
345 test textIndex-10.2 {ForwBack} {
346     list [catch {.t index {2.3 + 2 chars}} msg] $msg
347 } {0 2.5}
348 test textIndex-10.3 {ForwBack} {
349     list [catch {.t index {2.3 + 2c}} msg] $msg
350 } {0 2.5}
351 test textIndex-10.4 {ForwBack} {
352     list [catch {.t index {2.3 - 3ch}} msg] $msg
353 } {0 2.0}
354 test textIndex-10.5 {ForwBack} {
355     list [catch {.t index {1.3 + 3 lines}} msg] $msg
356 } {0 4.3}
357 test textIndex-10.6 {ForwBack} {
358     list [catch {.t index {2.3 -1l}} msg] $msg
359 } {0 1.3}
360 test textIndex-10.7 {ForwBack} {
361     list [catch {.t index {2.3 -1 gorp}} msg] $msg
362 } {1 {bad text index "2.3 -1 gorp"}}
363 test textIndex-10.8 {ForwBack} {
364     list [catch {.t index {2.3 - 4 lines}} msg] $msg
365 } {0 1.3}
366 test textIndex-10.9 {ForwBack} {
367     .t mark set insert 2.0
368     list [catch {.t index {insert -0 chars}} msg] $msg
369 } {0 2.0}
370 test textIndex-10.10 {ForwBack} {
371     .t mark set insert 2.end
372     list [catch {.t index {insert +0 chars}} msg] $msg
373 } {0 2.13}
374
375 test textIndex-11.1 {TkTextIndexForwBytes} {testtext} {
376     testtext .t forwbytes 2.3 -7
377 } {1.3 3}
378 test textIndex-11.2 {TkTextIndexForwBytes} {testtext} {
379     testtext .t forwbytes 2.3 5
380 } {2.8 8}
381 test textIndex-11.3 {TkTextIndexForwBytes} {testtext} {
382     testtext .t forwbytes 2.3 10
383 } {2.13 13}
384 test textIndex-11.4 {TkTextIndexForwBytes} {testtext} {
385     testtext .t forwbytes 2.3 11
386 } {3.0 0}
387 test textIndex-11.5 {TkTextIndexForwBytes} {testtext} {
388     testtext .t forwbytes 2.3 57
389 } {7.6 6}
390 test textIndex-11.6 {TkTextIndexForwBytes} {testtext} {
391     testtext .t forwbytes 2.3 58
392 } {8.0 0}
393 test textIndex-11.7 {TkTextIndexForwBytes} {testtext} {
394     testtext .t forwbytes 2.3 59
395 } {8.0 0}
396
397 test textIndex-12.1 {TkTextIndexForwChars} {
398     # (charCount < 0)
399     .t index {2.3 + -7 chars}
400 } 1.3
401 test textIndex-12.2 {TkTextIndexForwChars} {
402     # not (charCount < 0)
403     .t index {2.3 + 5 chars}
404 } 2.8
405 test textIndex-12.3 {TkTextIndexForwChars: find index} {
406     # for ( ; segPtr != NULL; segPtr = segPtr->nextPtr)
407     # one loop
408     .t index {2.3 + 9 chars}
409 } 2.12
410 test textIndex-12.4 {TkTextIndexForwChars: find index} {
411     # for ( ; segPtr != NULL; segPtr = segPtr->nextPtr)
412     # multiple loops
413     .t mark set foo 2.5
414     set x [.t index {2.3 + 9 chars}]
415     .t mark unset foo
416     set x
417 } 2.12
418 test textIndex-12.5 {TkTextIndexForwChars: find index} {
419     # for ( ; segPtr != NULL; segPtr = segPtr->nextPtr)
420     # border condition: last char
421
422     .t index {2.3 + 10 chars}
423 } 2.13
424 test textIndex-12.6 {TkTextIndexForwChars: find index} {
425     # for ( ; segPtr != NULL; segPtr = segPtr->nextPtr)
426     # border condition: segPtr == NULL -> beginning of next line
427     
428     .t index {2.3 + 11 chars}
429 } 3.0
430 test textIndex-12.7 {TkTextIndexForwChars: find index} {
431     # (segPtr->typePtr == &tkTextCharType)
432     .t index {2.3 + 2 chars}
433 } 2.5
434 test textIndex-12.8 {TkTextIndexForwChars: find index} {
435     # (charCount == 0)
436     # No more chars, so we found byte offset.
437
438     .t index {2.3 + 2 chars}
439 } 2.5
440 test textIndex-12.9 {TkTextIndexForwChars: find index} {
441     # not (segPtr->typePtr == &tkTextCharType)
442
443     .t image create 2.4 -image textimage
444     set x [.t get {2.3 + 3 chars}]
445     .t delete 2.4
446     set x    
447 } "f"
448 test textIndex-12.10 {TkTextIndexForwChars: find index} {
449     # dstPtr->byteIndex += segPtr->size - byteOffset
450     # When moving to next segment, account for bytes in last segment.
451     # Wrong answer would be 2.4
452
453     .t mark set foo 2.4
454     set x [.t index {2.3 + 5 chars}]
455     .t mark unset foo
456     set x
457 } 2.8
458 test textIndex-12.11 {TkTextIndexForwChars: go to next line} {
459     # (linePtr == NULL)
460     .t index {7.6 + 3 chars}
461 } 8.0
462 test textIndex-12.12 {TkTextIndexForwChars: go to next line} {
463     # Reset byteIndex to 0 now that we are on a new line.
464     # Wrong answer would be 2.9
465     .t index {1.3 + 6 chars}
466 } 2.2
467 test textIndex-12.13 {TkTextIndexForwChars} {
468     # right to end
469     .t index {2.3 + 56 chars}
470 } 8.0
471 test textIndex-12.14 {TkTextIndexForwChars} {
472     # try to go past end
473     .t index {2.3 + 57 chars}
474 } 8.0
475
476 test textIndex-13.1 {TkTextIndexBackBytes} {testtext} {
477     testtext .t backbytes 3.2 -10
478 } {4.6 6}
479 test textIndex-13.2 {TkTextIndexBackBytes} {testtext} {
480     testtext .t backbytes 3.2 2
481 } {3.0 0}
482 test textIndex-13.3 {TkTextIndexBackBytes} {testtext} {
483     testtext .t backbytes 3.2 3
484 } {2.13 13}
485 test textIndex-13.4 {TkTextIndexBackBytes} {testtext} {
486     testtext .t backbytes 3.2 22
487 } {1.1 1}
488 test textIndex-13.5 {TkTextIndexBackBytes} {testtext} {
489     testtext .t backbytes 3.2 23
490 } {1.0 0}
491 test textIndex-13.6 {TkTextIndexBackBytes} {testtext} {
492     testtext .t backbytes 3.2 24
493 } {1.0 0}
494
495 test textIndex-14.1 {TkTextIndexBackChars} {
496     # (charCount < 0)
497     .t index {3.2 - -10 chars}
498 } 4.6
499 test textIndex-14.2 {TkTextIndexBackChars} {
500     # not (charCount < 0)
501     .t index {3.2 - 2 chars}
502 } 3.0
503 test textIndex-14.3 {TkTextIndexBackChars: find starting segment} {
504     # for (segPtr = dstPtr->linePtr->segPtr; ; segPtr = segPtr->nextPtr)
505     # single loop
506
507     .t index {3.2 - 3 chars}
508 } 2.13
509 test textIndex-14.4 {TkTextIndexBackChars: find starting segment} {
510     # for (segPtr = dstPtr->linePtr->segPtr; ; segPtr = segPtr->nextPtr)
511     # multiple loop
512
513     .t mark set foo1 2.5
514     .t mark set foo2 2.7
515     .t mark set foo3 2.10
516     set x [.t index {2.9 - 1 chars}]
517     .t mark unset foo1 foo2 foo3
518     set x
519 } 2.8
520 test textIndex-14.5 {TkTextIndexBackChars: find starting seg and offset} {
521     # for (segPtr = dstPtr->linePtr->segPtr; ; segPtr = segPtr->nextPtr)
522     # Make sure segSize was decremented.  Wrong answer would be 2.10
523
524     .t mark set foo 2.2
525     set x [.t index {2.9 - 1 char}]
526     .t mark unset foo
527     set x
528 } 2.8
529 test textIndex-14.6 {TkTextIndexBackChars: back over characters} {
530     # (segPtr->typePtr == &tkTextCharType)
531
532     .t index {3.2 - 22 chars}
533 } 1.1
534 test textIndex-14.7 {TkTextIndexBackChars: loop backwards over chars} {
535     # (charCount == 0)
536     # No more chars, so we found byte offset.
537
538     .t index {3.4 - 2 chars}
539 } 3.2
540 test textIndex-14.8 {TkTextIndexBackChars: loop backwards over chars} {
541     # (p == start)
542     # Still more chars, but we reached beginning of segment
543
544     .t image create 5.6 -image textimage
545     set x [.t index {5.8 - 3 chars}]
546     .t delete 5.6
547     set x
548 } 5.5
549 test textIndex-14.9 {TkTextIndexBackChars: back over image} {
550     # not (segPtr->typePtr == &tkTextCharType)
551
552     .t image create 5.6 -image textimage
553     set x [.t get {5.8 - 4 chars}]
554     .t delete 5.6
555     set x
556 } "G"
557 test textIndex-14.10 {TkTextIndexBackChars: move to previous segment} {
558     # (segPtr != oldPtr)
559     # More segments to go
560
561     .t mark set foo 3.4
562     set x [.t index {3.5 - 2 chars}]
563     .t mark unset foo
564     set x
565 } 3.3
566 test textIndex-14.11 {TkTextIndexBackChars: move to previous segment} {
567     # not (segPtr != oldPtr)
568     # At beginning of line.
569
570     .t mark set foo 3.4
571     set x [.t index {3.5 - 10 chars}]
572     .t mark unset foo
573     set x
574 } 2.9
575 test textIndex-14.12 {TkTextIndexBackChars: move to previous line} {
576     # (lineIndex == 0) 
577     .t index {1.5 - 10 chars}
578 } 1.0
579 test textIndex-14.13 {TkTextIndexBackChars: move to previous line} {
580     # not (lineIndex == 0) 
581     .t index {2.5 - 10 chars}
582 } 1.2
583 test textIndex-14.14 {TkTextIndexBackChars: move to previous line} {
584     # for (segPtr = oldPtr; segPtr != NULL; segPtr = segPtr->nextPtr)
585     # Set byteIndex to end of previous line so we can subtract more
586     # bytes from it.  Otherwise we get an TkTextIndex with a negative
587     # byteIndex.
588
589     .t index {2.5 - 6 chars}
590 } 1.6
591 test textIndex-14.15 {TkTextIndexBackChars: UTF} {
592     .t get {5.3 - 1 chars}
593 } y
594 test textIndex-14.16 {TkTextIndexBackChars: UTF} {
595     .t get {5.3 - 2 chars}
596 } \u4e4f
597 test textIndex-14.17 {TkTextIndexBackChars: UTF} {
598     .t get {5.3 - 3 chars}
599 } b
600
601 proc getword index {
602     .t get [.t index "$index wordstart"] [.t index "$index wordend"]
603 }
604 test textIndex-15.1 {StartEnd} {
605     list [catch {.t index {2.3 lineend}} msg] $msg
606 } {0 2.13}
607 test textIndex-15.2 {StartEnd} {
608     list [catch {.t index {2.3 linee}} msg] $msg
609 } {0 2.13}
610 test textIndex-15.3 {StartEnd} {
611     list [catch {.t index {2.3 line}} msg] $msg
612 } {1 {bad text index "2.3 line"}}
613 test textIndex-15.4 {StartEnd} {
614     list [catch {.t index {2.3 linestart}} msg] $msg
615 } {0 2.0}
616 test textIndex-15.5 {StartEnd} {
617     list [catch {.t index {2.3 lines}} msg] $msg
618 } {0 2.0}
619 test textIndex-15.6 {StartEnd} {
620     getword 5.3
621 } { }
622 test textIndex-15.7 {StartEnd} {
623     getword 5.4
624 } GIrl
625 test textIndex-15.8 {StartEnd} {
626     getword 5.7
627 } GIrl
628 test textIndex-15.9 {StartEnd} {
629     getword 5.8
630 } { }
631 test textIndex-15.10 {StartEnd} {
632     getword 5.14
633 } x_yz
634 test textIndex-15.11 {StartEnd} {
635     getword 6.2
636 } #
637 test textIndex-15.12 {StartEnd} {
638     getword 3.4
639 } 12345
640 .t tag add x 2.8 2.11
641 test textIndex-15.13 {StartEnd} {
642     list [catch {.t index {2.2 worde}} msg] $msg
643 } {0 2.13}
644 test textIndex-15.14 {StartEnd} {
645     list [catch {.t index {2.12 words}} msg] $msg
646 } {0 2.0}
647 test textIndex-15.15 {StartEnd} {
648     list [catch {.t index {2.12 word}} msg] $msg
649 } {1 {bad text index "2.12 word"}}
650
651 test testIndex-16.1 {TkTextPrintIndex} {
652     set t [text .t2]
653     $t insert end \n
654     $t window create end -window [button $t.b]
655     set result [$t index end-2c]
656     pack $t
657     catch {destroy $t}
658 } 0
659
660
661 test testIndex-16.2 {TkTextPrintIndex} {
662     set t [text .t2]
663     $t insert end \n
664     $t window create end -window [button $t.b]
665     set result [$t tag add {} end-2c]
666     pack $t
667     catch {destroy $t}
668 } 0
669
670 # cleanup
671 rename textimage {}
672 catch {destroy .t}
673 ::tcltest::cleanupTests
674 return
675
676
677
678
679
680
681
682
683
684
685
686
687