1# This file is a Tcl script to test the code in the file tkText.c.
2# This file is organized in the standard fashion for Tcl tests.
3#
4# Copyright (c) 1992-1994 The Regents of the University of California.
5# Copyright (c) 1994-1996 Sun Microsystems, Inc.
6# Copyright (c) 1998-1999 by Scriptics Corporation.
7# All rights reserved.
8#
9# RCS: @(#) $Id$
10
11package require tcltest 2.1
12eval tcltest::configure $argv
13tcltest::loadTestedCommands
14namespace import -force tcltest::test
15
16# Create entries in the option database to be sure that geometry options
17# like border width have predictable values.
18
19option add *Text.borderWidth 2
20option add *Text.highlightThickness 2
21option add *Text.font {Courier -12}
22
23text .t -width 20 -height 10
24pack append . .t {top expand fill}
25update
26.t debug on
27wm geometry . {}
28
29# The statements below reset the main window;  it's needed if the window
30# manager is mwm to make mwm forget about a previous minimum size setting.
31
32wm withdraw .
33wm minsize . 1 1
34wm positionfrom . user
35wm deiconify .
36
37entry .t.e
38.t.e insert end abcdefg
39.t.e select from 0
40
41.t insert 1.0 "Line 1
42abcdefghijklm
4312345
44Line 4
45bOy GIrl .#@? x_yz
46!@#$%
47Line 7"
48
49catch {destroy .t2}
50text .t2
51set i 0
52foreach test {
53    {-autoseparators yes 1 nah}
54    {-background #ff00ff #ff00ff <gorp>}
55    {-bd 4 4 foo}
56    {-bg blue blue #xx}
57    {-blockcursor 0 0 xx}
58    {-borderwidth 7 7 ++}
59    {-cursor watch watch lousy}
60    {-exportselection no 0 maybe}
61    {-fg red red stupid}
62    {-font fixed fixed {}}
63    {-foreground #012 #012 bogus}
64    {-height 5 5 bad}
65    {-highlightbackground #123 #123 bogus}
66    {-highlightcolor #234 #234 bogus}
67    {-highlightthickness -2 0 bad}
68    {-inactiveselectbackground #ffff01234567 #ffff01234567 bogus}
69    {-insertbackground green green <bogus>}
70    {-insertborderwidth 45 45 bogus}
71    {-insertofftime 100 100 2.4}
72    {-insertontime 47 47 e1}
73    {-insertwidth 2.3 2 47d}
74    {-maxundo 5 5 noway}
75    {-padx 3.4 3 2.4.}
76    {-pady 82 82 bogus}
77    {-relief raised raised bumpy}
78    {-selectbackground #ffff01234567 #ffff01234567 bogus}
79    {-selectborderwidth 21 21 3x}
80    {-selectforeground yellow yellow #12345}
81    {-spacing1 20 20 1.3x}
82    {-spacing1 -5 0 bogus}
83    {-spacing2 5 5 bogus}
84    {-spacing2 -1 0 bogus}
85    {-spacing3 20 20 bogus}
86    {-spacing3 -10 0 bogus}
87    {-state d disabled foo}
88    {-tabs {1i 2i 3i 4i} {1i 2i 3i 4i} bad_tabs}
89    {-tabstyle wordprocessor wordprocessor garbage}
90    {-undo 1 1 eh}
91    {-width 73 73 2.4}
92    {-wrap w word bad_wrap}
93} {
94    test text-1.[incr i] {text options} {
95	set result {}
96	lappend result [catch {.t2 configure [lindex $test 0] [lindex $test 3]}]
97	.t2 configure [lindex $test 0] [lindex $test 1]
98	lappend result [.t2 cget [lindex $test 0]]
99    } [list 1 [lindex $test 2]]
100}
101test text-1.[incr i] {text options} {
102    .t2 configure -takefocus "any old thing"
103    .t2 cget -takefocus
104} {any old thing}
105test text-1.[incr i] {text options} {
106    .t2 configure -xscrollcommand "x scroll command"
107    .t2 configure -xscrollcommand
108} {-xscrollcommand xScrollCommand ScrollCommand {} {x scroll command}}
109test text-1.[incr i] {text options} {
110    .t2 configure -yscrollcommand "test command"
111    .t2 configure -yscrollcommand
112} {-yscrollcommand yScrollCommand ScrollCommand {} {test command}}
113test text-1.[incr i] {text options} {
114    set result {}
115    foreach i [.t2 configure] {
116	lappend result [lindex $i 4]
117    }
118    set result
119} {1 blue {} {} 0 7 watch {} 0 {} fixed #012 5 #123 #234 0 #ffff01234567 green 45 100 47 2 5 3 82 raised #ffff01234567 21 yellow 0 0 0 0 {} disabled {1i 2i 3i 4i} wordprocessor {any old thing} 1 73 word {x scroll command} {test command}}
120
121test text-2.1 {Tk_TextCmd procedure} {
122    list [catch {text} msg] $msg
123} {1 {wrong # args: should be "text pathName ?options?"}}
124test text-2.2 {Tk_TextCmd procedure} {
125    list [catch {text foobar} msg] $msg
126} {1 {bad window path name "foobar"}}
127test text-2.3 {Tk_TextCmd procedure} {
128    catch {destroy .t2}
129    list [catch {text .t2 -gorp nofun} msg] $msg [winfo exists .t2]
130} {1 {unknown option "-gorp"} 0}
131test text-2.4 {Tk_TextCmd procedure} {
132    catch {destroy .t2}
133    list [catch {text .t2 -bd 2 -fg red} msg] $msg \
134	[lindex [.t2 config -bd] 4] [lindex [.t2 config -fg] 4]
135} {0 .t2 2 red}
136if {$tcl_platform(platform) == "windows"} {
137    set relief flat
138} elseif {[tk windowingsystem] eq "aqua"} {
139    set relief solid
140} else {
141    set relief raised
142}
143test text-2.5 {Tk_TextCmd procedure} {
144    catch {destroy .t2}
145    text .t2
146    .t2 tag cget sel -relief 
147} $relief
148test text-2.6 {Tk_TextCmd procedure} {
149    catch {destroy .t2}
150    list [text .t2] [winfo class .t2]
151} {.t2 Text}
152
153test text-3.1 {TextWidgetCmd procedure, basics} {
154    list [catch {.t} msg] $msg
155} {1 {wrong # args: should be ".t option ?arg arg ...?"}}
156test text-3.2 {TextWidgetCmd procedure} {
157    list [catch {.t gorp 1.0 z 1.2} msg] $msg
158} {1 {bad option "gorp": must be bbox, cget, compare, configure, count, debug, delete, dlineinfo, dump, edit, get, image, index, insert, mark, peer, replace, scan, search, see, tag, window, xview, or yview}}
159
160test text-4.1 {TextWidgetCmd procedure, "bbox" option} {
161    list [catch {.t bbox} msg] $msg
162} {1 {wrong # args: should be ".t bbox index"}}
163test text-4.2 {TextWidgetCmd procedure, "bbox" option} {
164    list [catch {.t bbox a b} msg] $msg
165} {1 {wrong # args: should be ".t bbox index"}}
166test text-4.3 {TextWidgetCmd procedure, "bbox" option} {
167    list [catch {.t bbox bad_mark} msg] $msg
168} {1 {bad text index "bad_mark"}}
169
170test text-5.1 {TextWidgetCmd procedure, "cget" option} {
171    list [catch {.t cget} msg] $msg
172} {1 {wrong # args: should be ".t cget option"}}
173test text-5.2 {TextWidgetCmd procedure, "cget" option} {
174    list [catch {.t cget a b} msg] $msg
175} {1 {wrong # args: should be ".t cget option"}}
176test text-5.3 {TextWidgetCmd procedure, "cget" option} {
177    list [catch {.t cget -gorp} msg] $msg
178} {1 {unknown option "-gorp"}}
179test text-5.4 {TextWidgetCmd procedure, "cget" option} {
180    .t configure -bd 17
181    .t cget -bd
182} {17}
183.t configure -bd [lindex [.t configure -bd] 3]
184
185test text-6.1 {TextWidgetCmd procedure, "compare" option} {
186    list [catch {.t compare a b} msg] $msg
187} {1 {wrong # args: should be ".t compare index1 op index2"}}
188test text-6.2 {TextWidgetCmd procedure, "compare" option} {
189    list [catch {.t compare a b c d} msg] $msg
190} {1 {wrong # args: should be ".t compare index1 op index2"}}
191test text-6.3 {TextWidgetCmd procedure, "compare" option} {
192    list [catch {.t compare @x == 1.0} msg] $msg
193} {1 {bad text index "@x"}}
194test text-6.4 {TextWidgetCmd procedure, "compare" option} {
195    list [catch {.t compare 1.0 < @y} msg] $msg
196} {1 {bad text index "@y"}}
197test text-6.5 {TextWidgetCmd procedure, "compare" option} {
198    list [.t compare 1.1 < 1.0] [.t compare 1.1 < 1.1] [.t compare 1.1 < 1.2]
199} {0 0 1}
200test text-6.6 {TextWidgetCmd procedure, "compare" option} {
201    list [.t compare 1.1 <= 1.0] [.t compare 1.1 <= 1.1] [.t compare 1.1 <= 1.2]
202} {0 1 1}
203test text-6.7 {TextWidgetCmd procedure, "compare" option} {
204    list [.t compare 1.1 == 1.0] [.t compare 1.1 == 1.1] [.t compare 1.1 == 1.2]
205} {0 1 0}
206test text-6.8 {TextWidgetCmd procedure, "compare" option} {
207    list [.t compare 1.1 >= 1.0] [.t compare 1.1 >= 1.1] [.t compare 1.1 >= 1.2]
208} {1 1 0}
209test text-6.9 {TextWidgetCmd procedure, "compare" option} {
210    list [.t compare 1.1 > 1.0] [.t compare 1.1 > 1.1] [.t compare 1.1 > 1.2]
211} {1 0 0}
212test text-6.10 {TextWidgetCmd procedure, "compare" option} {
213    list [.t com 1.1 != 1.0] [.t compare 1.1 != 1.1] [.t compare 1.1 != 1.2]
214} {1 0 1}
215test text-6.11 {TextWidgetCmd procedure, "compare" option} {
216    list [catch {.t compare 1.0 <x 1.2} msg] $msg
217} {1 {bad comparison operator "<x": must be <, <=, ==, >=, >, or !=}}
218test text-6.12 {TextWidgetCmd procedure, "compare" option} {
219    list [catch {.t compare 1.0 >> 1.2} msg] $msg
220} {1 {bad comparison operator ">>": must be <, <=, ==, >=, >, or !=}}
221test text-6.13 {TextWidgetCmd procedure, "compare" option} {
222    list [catch {.t compare 1.0 z 1.2} msg] $msg
223} {1 {bad comparison operator "z": must be <, <=, ==, >=, >, or !=}}
224test text-6.14 {TextWidgetCmd procedure, "compare" option} {
225    list [catch {.t co 1.0 z 1.2} msg] $msg
226} {1 {ambiguous option "co": must be bbox, cget, compare, configure, count, debug, delete, dlineinfo, dump, edit, get, image, index, insert, mark, peer, replace, scan, search, see, tag, window, xview, or yview}}
227
228# "configure" option is already covered above
229
230test text-7.1 {TextWidgetCmd procedure, "debug" option} {
231    list [catch {.t debug 0 1} msg] $msg
232} {1 {wrong # args: should be ".t debug boolean"}}
233test text-7.2 {TextWidgetCmd procedure, "debug" option} {
234    list [catch {.t de 0 1} msg] $msg
235} {1 {ambiguous option "de": must be bbox, cget, compare, configure, count, debug, delete, dlineinfo, dump, edit, get, image, index, insert, mark, peer, replace, scan, search, see, tag, window, xview, or yview}}
236test text-7.3 {TextWidgetCmd procedure, "debug" option} {
237    .t debug true
238    .t deb
239} 1
240test text-7.4 {TextWidgetCmd procedure, "debug" option} {
241    .t debug false
242    .t debug
243} 0
244.t debug
245
246test text-8.1 {TextWidgetCmd procedure, "delete" option} {
247    list [catch {.t delete} msg] $msg
248} {1 {wrong # args: should be ".t delete index1 ?index2 ...?"}}
249test text-8.2 {TextWidgetCmd procedure, "delete" option} {
250    list [catch {.t delete a b c} msg] $msg
251} {1 {bad text index "a"}}
252test text-8.3 {TextWidgetCmd procedure, "delete" option} {
253    list [catch {.t delete @x 2.2} msg] $msg
254} {1 {bad text index "@x"}}
255test text-8.4 {TextWidgetCmd procedure, "delete" option} {
256    list [catch {.t delete 2.3 @y} msg] $msg
257} {1 {bad text index "@y"}}
258test text-8.5 {TextWidgetCmd procedure, "delete" option} {
259    .t configure -state disabled
260    .t delete 2.3
261    .t g 2.0 2.end
262} abcdefghijklm
263.t configure -state normal
264test text-8.6 {TextWidgetCmd procedure, "delete" option} {
265    .t delete 2.3
266    .t get 2.0 2.end
267} abcefghijklm
268test text-8.7 {TextWidgetCmd procedure, "delete" option} {
269    .t delete 2.1 2.3
270    .t get 2.0 2.end
271} aefghijklm
272test text-8.8 {TextWidgetCmd procedure, "delete" option} {
273    # All indices are checked before we actually delete anything
274    list [catch {.t delete 2.1 2.3 foo} msg] $msg \
275	    [.t get 2.0 2.end]
276} {1 {bad text index "foo"} aefghijklm}
277set prevtext [.t get 1.0 end-1c]
278test text-8.9 {TextWidgetCmd procedure, "delete" option} {
279    # auto-forward one byte if the last "pair" is just one
280    .t delete 1.0 end; .t insert 1.0 "foo\nabcdefghijklm"
281    .t delete 2.1 2.3 2.3
282    .t get 1.0 end-1c
283} foo\naefghijklm
284test text-8.10 {TextWidgetCmd procedure, "delete" option} {
285    # all indices will be ordered before deletion
286    .t delete 1.0 end; .t insert 1.0 "foo\nabcdefghijklm"
287    .t delete 2.0 2.3 2.7 2.9 2.4
288    .t get 1.0 end-1c
289} foo\ndfgjklm
290test text-8.11 {TextWidgetCmd procedure, "delete" option} {
291    # and check again with even pairs
292    .t delete 1.0 end; .t insert 1.0 "foo\nabcdefghijklm"
293    .t delete 2.0 2.2 2.7 2.9 2.4 2.5
294    .t get 1.0 end-1c
295} foo\ncdfgjklm
296test text-8.12 {TextWidgetCmd procedure, "delete" option} {
297    # we should get the longest range on equal start indices
298    .t delete 1.0 end; .t insert 1.0 "foo\nabcdefghijklm"
299    .t delete 2.0 2.2 2.0 2.5 2.0 2.3 2.8 2.7
300    .t get 1.0 end-1c
301} foo\nfghijklm
302test text-8.13 {TextWidgetCmd procedure, "delete" option} {
303    # we should get the longest range on equal start indices
304    .t delete 1.0 end; .t insert 1.0 "foo\nabcdefghijklm"
305    .t delete 2.0 2.2 1.2 2.6 2.0 2.5
306    .t get 1.0 end-1c
307} foghijklm
308test text-8.14 {TextWidgetCmd procedure, "delete" option} {
309    # we should get the longest range on equal start indices
310    .t delete 1.0 end; .t insert 1.0 "foo\nabcdefghijklm"
311    .t delete 2.0 2.2 2.0 2.5 1.1 2.3 2.8 2.7
312    .t get 1.0 end-1c
313} ffghijklm
314test text-8.15 {TextWidgetCmd procedure, "delete" option} {
315    # we should get the watch for overlapping ranges - they should
316    # essentially be merged into one span.
317    .t delete 1.0 end; .t insert 1.0 "foo\nabcdefghijklm"
318    .t delete 2.0 2.6 2.2 2.8
319    .t get 1.0 end-1c
320} foo\nijklm
321test text-8.16 {TextWidgetCmd procedure, "delete" option} {
322    # we should get the watch for overlapping ranges - they should
323    # essentially be merged into one span.
324    .t delete 1.0 end; .t insert 1.0 "foo\nabcdefghijklm"
325    .t delete 2.0 2.6 2.2 2.4
326    .t get 1.0 end-1c
327} foo\nghijklm
328.t delete 1.0 end; .t insert 1.0 $prevtext
329test text-8.17 {TextWidgetCmd procedure, "replace" option} {
330    list [catch {.t replace 1.3 2.3} err] $err
331} {1 {wrong # args: should be ".t replace index1 index2 chars ?tagList chars tagList ...?"}}
332test text-8.18 {TextWidgetCmd procedure, "replace" option} {
333    list [catch {.t replace 3.1 2.3 foo} err] $err
334} {1 {Index "2.3" before "3.1" in the text}}
335test text-8.19 {TextWidgetCmd procedure, "replace" option} {
336    list [catch {.t replace 2.1 2.3 foo} err] $err
337} {0 {}}
338.t delete 1.0 end; .t insert 1.0 $prevtext
339test text-8.20 {TextWidgetCmd procedure, "replace" option with undo} {
340    .t configure -undo 0
341    .t configure -undo 1
342    # Ensure it is treated as a single undo action
343    .t replace 2.1 2.3 foo
344    .t edit undo
345    .t configure -undo 0
346    string equal [.t get 1.0 end-1c] $prevtext
347} {1}
348test text-8.21 {TextWidgetCmd procedure, "replace" option with undo} {
349    .t configure -undo 0
350    .t configure -undo 1
351    .t replace 2.1 2.3 foo
352    # Ensure we can override a text widget and intercept undo
353    # actions.  If in the future a different mechanism is available
354    # to do this, then we should be able to change this test.  The
355    # behaviour tested for here is not, strictly speaking, documented.
356    rename .t test.t
357    set res {}
358    proc .t {args} { lappend ::res $args ; uplevel 1 test.t $args }
359    .t edit undo
360    rename .t {}
361    rename test.t .t
362    .t configure -undo 0
363    set res
364} {{edit undo} {delete 2.1 2.4} {mark set insert 2.1} {see insert} {insert 2.1 ef} {mark set insert 2.3} {see insert}}
365test text-8.22 {TextWidgetCmd procedure, "replace" option with undo} {
366    .t configure -undo 0
367    .t configure -undo 1
368    # Ensure that undo (even composite undo like 'replace')
369    # works when the widget shows nothing useful.
370    .t replace 2.1 2.3 foo
371    .t configure -start 1 -end 1
372    .t edit undo
373    .t configure -start {} -end {}
374    .t configure -undo 0
375    if {![string equal [.t get 1.0 end-1c] $prevtext]} {
376	set res [list [.t get 1.0 end-1c] ne $prevtext]
377    } else {
378	set res 1
379    }
380} {1}
381.t delete 1.0 end; .t insert 1.0 $prevtext
382test text-8.23 {TextWidgetCmd procedure, "replace" option with peers, undo} {
383    .t configure -undo 0
384    .t configure -undo 1
385    .t peer create .tt -undo 1
386    # Ensure that undo (even composite undo like 'replace')
387    # works when the the event took place in one peer, which
388    # is then deleted, before the undo takes place in another peer.
389    .tt replace 2.1 2.3 foo
390    .tt configure -start 1 -end 1
391    destroy .tt
392    .t edit undo
393    .t configure -start {} -end {}
394    .t configure -undo 0
395    if {![string equal [.t get 1.0 end-1c] $prevtext]} {
396	set res [list [.t get 1.0 end-1c] ne $prevtext]
397    } else {
398        set res 1
399    }
400} {1}
401.t delete 1.0 end; .t insert 1.0 $prevtext
402test text-8.24 {TextWidgetCmd procedure, "replace" option with peers, undo} {
403    .t configure -undo 0
404    .t configure -undo 1
405    .t peer create .tt -undo 1
406    # Ensure that undo (even composite undo like 'replace')
407    # works when the the event took place in one peer, which
408    # is then deleted, before the undo takes place in another peer
409    # which isn't showing everything.
410    .tt replace 2.1 2.3 foo
411    set res [.tt get 2.1 2.4]
412    .tt configure -start 1 -end 1
413    destroy .tt
414    .t configure -start 3 -end 4
415    # msg will actually be set to a silently ignored error message here,
416    # (that the .tt command doesn't exist), but that is not important.
417    lappend res [catch {.t edit undo} msg]
418    .t configure -undo 0
419    .t configure -start {} -end {}
420    if {![string equal [.t get 1.0 end-1c] $prevtext]} {
421	lappend res [list [.t get 1.0 end-1c] ne $prevtext]
422    } else {
423	lappend res 1
424    }
425} {foo 0 1}
426test text-8.25 {TextWidgetCmd procedure, "replace" option crash} -setup {
427    destroy .tt
428} -body {
429    text .tt
430    .tt insert 0.0 foo\n
431    .tt replace end-1l end bar
432} -cleanup {
433    destroy .tt
434} -result {}
435
436.t delete 1.0 end; .t insert 1.0 $prevtext
437
438test text-9.1 {TextWidgetCmd procedure, "get" option} {
439    list [catch {.t get} msg] $msg
440} {1 {wrong # args: should be ".t get ?-displaychars? ?--? index1 ?index2 ...?"}}
441test text-9.2 {TextWidgetCmd procedure, "get" option} {
442    list [catch {.t get a b c} msg] $msg
443} {1 {bad text index "a"}}
444test text-9.3 {TextWidgetCmd procedure, "get" option} {
445    list [catch {.t get @q 3.1} msg] $msg
446} {1 {bad text index "@q"}}
447test text-9.4 {TextWidgetCmd procedure, "get" option} {
448    list [catch {.t get 3.1 @r} msg] $msg
449} {1 {bad text index "@r"}}
450test text-9.5 {TextWidgetCmd procedure, "get" option} {
451    .t get 5.7 5.3
452} {}
453test text-9.6 {TextWidgetCmd procedure, "get" option} {
454    .t get 5.3 5.5
455} { G}
456test text-9.7 {TextWidgetCmd procedure, "get" option} {
457    .t get 5.3 end
458} { GIrl .#@? x_yz
459!@#$%
460Line 7
461}
462.t mark set a 5.3
463.t mark set b 5.3
464.t mark set c 5.5
465test text-9.8 {TextWidgetCmd procedure, "get" option} {
466    .t get 5.2 5.7
467} {y GIr}
468test text-9.9 {TextWidgetCmd procedure, "get" option} {
469    .t get 5.2
470} {y}
471test text-9.10 {TextWidgetCmd procedure, "get" option} {
472    .t get 5.2 5.4
473} {y }
474test text-9.11 {TextWidgetCmd procedure, "get" option} {
475    .t get 5.2 5.4 5.4
476} {{y } G}
477test text-9.12 {TextWidgetCmd procedure, "get" option} {
478    .t get 5.2 5.4 5.4 5.5
479} {{y } G}
480test text-9.13 {TextWidgetCmd procedure, "get" option} {
481    .t get 5.2 5.4 5.5 "5.5+5c"
482} {{y } {Irl .}}
483test text-9.14 {TextWidgetCmd procedure, "get" option} {
484    .t get 5.2 5.4 5.4 5.5 end-3c
485} {{y } G { }}
486test text-9.15 {TextWidgetCmd procedure, "get" option} {
487    .t get 5.2 5.4 5.4 5.5 end-3c end
488} {{y } G { 7
489}}
490test text-9.16 {TextWidgetCmd procedure, "get" option} {
491    .t get 5.2 5.3 5.4 5.3
492} {y}
493test text-9.17 {TextWidgetCmd procedure, "get" option} {
494    .t index "5.2 +3 indices"
495} {5.5}
496test text-9.17a {TextWidgetCmd procedure, "get" option} {
497    .t index "5.2 +3chars"
498} {5.5}
499test text-9.17b {TextWidgetCmd procedure, "get" option} {
500    .t index "5.2 +3displayindices"
501} {5.5}
502.t tag configure elide -elide 1
503.t tag add elide 5.2 5.4
504test text-9.18 {TextWidgetCmd procedure, "get" option} {
505    list [catch {.t get 5.2 5.4 5.5 foo} msg] $msg
506} {1 {bad text index "foo"}}
507test text-9.19 {TextWidgetCmd procedure, "get" option} {
508    .t get 5.2 5.4 5.4 5.5 end-3c end
509} {{y } G { 7
510}}
511test text-9.20 {TextWidgetCmd procedure, "get" option} {
512    .t get -displaychars 5.2 5.4 5.4 5.5 end-3c end
513} {{} G { 7
514}}
515test text-9.21 {TextWidgetCmd procedure, "get" option} {
516    list [.t index "5.1 +4indices"] [.t index "5.1+4d indices"]
517} {5.5 5.7}
518test text-9.22 {TextWidgetCmd procedure, "get" option} {
519    list [.t index "5.1 +4a chars"] [.t index "5.1+4d chars"]
520} {5.5 5.7}
521test text-9.23 {TextWidgetCmd procedure, "get" option} {
522    list [.t index "5.5 -4indices"] [.t index "5.7-4d indices"]
523} {5.1 5.1}
524test text-9.24 {TextWidgetCmd procedure, "get" option} {
525    list [.t index "5.5 -4a chars"] [.t index "5.7-4d chars"]
526} {5.1 5.1}
527.t window create 5.4
528test text-9.25 {TextWidgetCmd procedure, "get" option} {
529    list [.t index "5.1 +4indices"] [.t index "5.1+4d indices"]
530} {5.5 5.7}
531test text-9.25a {TextWidgetCmd procedure, "get" option} {
532    list [.t index "5.1 +4a chars"] [.t index "5.1+4d chars"]
533} {5.6 5.8}
534test text-9.26 {TextWidgetCmd procedure, "get" option} {
535    list [.t index "5.5 -4indices"] [.t index "5.7-4d indices"]
536} {5.1 5.1}
537test text-9.26a {TextWidgetCmd procedure, "get" option} {
538    list [.t index "5.6 -4a chars"] [.t index "5.8-4d chars"]
539} {5.1 5.1}
540.t delete 5.4 
541.t tag add elide 5.5 5.6
542test text-9.27 {TextWidgetCmd procedure, "get" option} {
543    .t get -displaychars 5.2 5.8
544} {Grl}
545.t tag delete elide
546.t mark unset a
547.t mark unset b
548.t mark unset c
549test text-9.2.1 {TextWidgetCmd procedure, "count" option} {
550    list [catch {.t count} msg] $msg
551} {1 {wrong # args: should be ".t count ?options? index1 index2"}}
552test text-9.2.2.1 {TextWidgetCmd procedure, "count" option} {
553    list [catch {.t count blah 1.0 2.0} msg] $msg
554} {1 {bad option "blah" must be -chars, -displaychars, -displayindices, -displaylines, -indices, -lines, -update, -xpixels, or -ypixels}}
555test text-9.2.2 {TextWidgetCmd procedure, "count" option} {
556    list [catch {.t count a b} msg] $msg
557} {1 {bad text index "a"}}
558test text-9.2.3 {TextWidgetCmd procedure, "count" option} {
559    list [catch {.t count @q 3.1} msg] $msg
560} {1 {bad text index "@q"}}
561test text-9.2.4 {TextWidgetCmd procedure, "count" option} {
562    list [catch {.t count 3.1 @r} msg] $msg
563} {1 {bad text index "@r"}}
564test text-9.2.5 {TextWidgetCmd procedure, "count" option} {
565    .t count 5.7 5.3
566} {-4}
567test text-9.2.6 {TextWidgetCmd procedure, "count" option} {
568    .t count 5.3 5.5
569} {2}
570test text-9.2.7 {TextWidgetCmd procedure, "count" option} {
571    .t count 5.3 end
572} {29}
573.t mark set a 5.3
574.t mark set b 5.3
575.t mark set c 5.5
576test text-9.2.8 {TextWidgetCmd procedure, "count" option} {
577    .t count 5.2 5.7
578} {5}
579test text-9.2.9 {TextWidgetCmd procedure, "count" option} {
580    .t count 5.2 5.3
581} {1}
582test text-9.2.10 {TextWidgetCmd procedure, "count" option} {
583    .t count 5.2 5.4
584} {2}
585test text-9.2.17 {TextWidgetCmd procedure, "count" option} {
586    list [catch {.t count 5.2 foo} msg] $msg
587} {1 {bad text index "foo"}}
588.t tag configure elide -elide 1
589.t tag add elide 2.2 3.4
590.t tag add elide 4.0 4.1
591test text-9.2.18 {TextWidgetCmd procedure, "count" option} {
592    .t count -displayindices 2.0 3.0
593} {2}
594test text-9.2.19 {TextWidgetCmd procedure, "count" option} {
595    .t count -displayindices 2.2 3.0
596} {0}
597test text-9.2.20 {TextWidgetCmd procedure, "count" option} {
598    .t count -displayindices 2.0 4.2
599} {5}
600# Create one visible and one invisible window
601frame .t.w1
602frame .t.w2
603.t mark set a 2.2
604# Creating this window here means that the elidden text
605# now starts at 2.3, but 'a' is automatically moved to 2.3
606.t window create 2.1 -window .t.w1
607.t window create 3.1 -window .t.w2
608test text-9.2.21 {TextWidgetCmd procedure, "count" option} {
609    .t count -displayindices 2.0 3.0
610} {3}
611test text-9.2.22 {TextWidgetCmd procedure, "count" option} {
612    .t count -displayindices 2.2 3.0
613} {1}
614test text-9.2.23 {TextWidgetCmd procedure, "count" option} {
615    .t count -displayindices a 3.0
616} {0}
617test text-9.2.24 {TextWidgetCmd procedure, "count" option} {
618    .t count -displayindices 2.0 4.2
619} {6}
620test text-9.2.25 {TextWidgetCmd procedure, "count" option} {
621    .t count -displaychars 2.0 3.0
622} {2}
623test text-9.2.26 {TextWidgetCmd procedure, "count" option} {
624    .t count -displaychars 2.2 3.0
625} {1}
626test text-9.2.27 {TextWidgetCmd procedure, "count" option} {
627    .t count -displaychars a 3.0
628} {0}
629test text-9.2.28 {TextWidgetCmd procedure, "count" option} {
630    .t count -displaychars 2.0 4.2
631} {5}
632test text-9.2.29 {TextWidgetCmd procedure, "count" option} {
633    list [.t count -indices 2.2 3.0] [.t count 2.2 3.0]
634} {10 10}
635test text-9.2.30 {TextWidgetCmd procedure, "count" option} {
636    list [.t count -indices a 3.0] [.t count a 3.0]
637} {9 9}
638test text-9.2.31 {TextWidgetCmd procedure, "count" option} {
639    .t count -indices 2.0 4.2
640} {21}
641test text-9.2.32 {TextWidgetCmd procedure, "count" option} {
642    .t count -chars 2.2 3.0
643} {10}
644test text-9.2.33 {TextWidgetCmd procedure, "count" option} {
645    .t count -chars a 3.0
646} {9}
647test text-9.2.34 {TextWidgetCmd procedure, "count" option} {
648    .t count -chars 2.0 4.2
649} {19}
650destroy .t.w1
651destroy .t.w2
652set current [.t get 1.0 end-1c]
653.t delete 1.0 end
654.t insert end [string repeat "abcde " 50]\n
655.t insert end [string repeat "fghij " 50]\n
656.t insert end [string repeat "klmno " 50]
657test text-9.2.35 {TextWidgetCmd procedure, "count" option} {
658    .t count -lines 1.0 end
659} {3}
660test text-9.2.36 {TextWidgetCmd procedure, "count" option} {
661    .t count -lines end 1.0
662} {-3}
663test text-9.2.37 {TextWidgetCmd procedure, "count" option} {
664    list [catch {.t count -lines 1.0 2.0 3.0} res] $res
665} {1 {bad option "1.0" must be -chars, -displaychars, -displayindices, -displaylines, -indices, -lines, -update, -xpixels, or -ypixels}}
666test text-9.2.38 {TextWidgetCmd procedure, "count" option} {
667    .t count -lines end end
668} {0}
669test text-9.2.39 {TextWidgetCmd procedure, "count" option} {
670    .t count -lines 1.5 2.5
671} {1}
672test text-9.2.40 {TextWidgetCmd procedure, "count" option} {
673    .t count -lines 2.5 "2.5 lineend"
674} {0}
675test text-9.2.41 {TextWidgetCmd procedure, "count" option} {
676    .t count -lines 2.7 "1.0 lineend"
677} {-1}
678test text-9.2.42 {TextWidgetCmd procedure, "count" option} {
679    set old_wrap [.t cget -wrap]
680    .t configure -wrap none
681    set res [.t count -displaylines 1.0 end]
682    .t configure -wrap $old_wrap
683    set res
684} {3}
685test text-9.2.43 {TextWidgetCmd procedure, "count" option} {
686    .t count -lines -chars -indices -displaylines 1.0 end
687} {3 903 903 45}
688.t configure -wrap none
689
690# Newer tags are higher priority
691.t tag configure elide1 -elide 0
692.t tag configure elide2 -elide 1
693.t tag configure elide3 -elide 0
694.t tag configure elide4 -elide 1
695
696test text-0.2.44.0 {counting with tag priority eliding} {
697    .t delete 1.0 end
698    .t insert end "hello"
699    list [.t count -displaychars 1.0 1.0] \
700      [.t count -displaychars 1.0 1.1] \
701      [.t count -displaychars 1.0 1.2] \
702      [.t count -displaychars 1.0 1.3] \
703      [.t count -displaychars 1.0 1.4] \
704      [.t count -displaychars 1.0 1.5] \
705      [.t count -displaychars 1.0 1.6] \
706      [.t count -displaychars 1.0 2.6] \
707} {0 1 2 3 4 5 5 6}
708test text-0.2.44 {counting with tag priority eliding} {
709    .t delete 1.0 end
710    .t insert end "hello"
711    .t tag add elide1 1.2 1.4
712    .t count -displaychars 1.0 1.5
713} {5}
714test text-0.2.45 {counting with tag priority eliding} {
715    .t delete 1.0 end
716    .t insert end "hello"
717    .t tag add elide2 1.2 1.4
718    .t count -displaychars 1.0 1.5
719} {3}
720test text-0.2.46 {counting with tag priority eliding} {
721    set res {}
722    .t delete 1.0 end
723    .t insert end "hello"
724    .t tag add elide2 1.2 1.4
725    .t tag add elide1 1.2 1.4
726    lappend res [.t count -displaychars 1.0 1.5]
727    .t delete 1.0 end
728    .t insert end "hello"
729    .t tag add elide1 1.2 1.4
730    .t tag add elide2 1.2 1.4
731    lappend res [.t count -displaychars 1.0 1.5]
732} {3 3}
733test text-0.2.47 {counting with tag priority eliding} {
734    set res {}
735    .t delete 1.0 end
736    .t insert end "hello"
737    .t tag add elide2 1.2 1.4
738    .t tag add elide3 1.2 1.4
739    lappend res [.t count -displaychars 1.0 1.5]
740    .t delete 1.0 end
741    .t insert end "hello"
742    .t tag add elide3 1.2 1.4
743    .t tag add elide3 1.2 1.4
744    lappend res [.t count -displaychars 1.0 1.5]
745} {5 5}
746test text-0.2.48 {counting with tag priority eliding} {
747    set res {}
748    .t delete 1.0 end
749    .t insert end "hello"
750    .t tag add elide2 1.2 1.4
751    .t tag add elide3 1.2 1.4
752    .t tag add elide4 1.2 1.4
753    .t tag add elide1 1.2 1.4
754    lappend res [.t count -displaychars 1.0 1.5]
755    .t delete 1.0 end
756    .t insert end "hello"
757    .t tag add elide1 1.2 1.4
758    .t tag add elide4 1.2 1.4
759    .t tag add elide2 1.2 1.4
760    .t tag add elide3 1.2 1.4
761    lappend res [.t count -displaychars 1.0 1.5]
762} {3 3}
763test text-0.2.49 {counting with tag priority eliding} {
764    set res {}
765    .t delete 1.0 end
766    .t insert end "hello"
767    .t tag add elide2 1.2 1.4
768    .t tag add elide3 1.2 1.4
769    .t tag add elide1 1.2 1.4
770    lappend res [.t count -displaychars 1.0 1.5]
771    .t delete 1.0 end
772    .t insert end "hello"
773    .t tag add elide1 1.2 1.4
774    .t tag add elide2 1.2 1.4
775    .t tag add elide3 1.2 1.4
776    lappend res [.t count -displaychars 1.0 1.5]
777} {5 5}
778test text-0.2.50 {counting with tag priority eliding} {
779    set res {}
780    .t delete 1.0 end
781    .t insert end "hello"
782    .t tag add elide2 1.0 1.5
783    .t tag add elide1 1.2 1.4
784    lappend res [.t count -displaychars 1.0 1.5]
785    lappend res [.t count -displaychars 1.1 1.5]
786    lappend res [.t count -displaychars 1.2 1.5]
787    lappend res [.t count -displaychars 1.3 1.5]
788    .t delete 1.0 end
789    .t insert end "hello"
790    .t tag add elide1 1.0 1.5
791    .t tag add elide2 1.2 1.4
792    lappend res [.t count -displaychars 1.0 1.5]
793    lappend res [.t count -displaychars 1.1 1.5]
794    lappend res [.t count -displaychars 1.2 1.5]
795    lappend res [.t count -displaychars 1.3 1.5]
796} {0 0 0 0 3 2 1 1}
797test text-0.2.51 {counting with tag priority eliding} {
798    set res {}
799    .t delete 1.0 end
800    .t tag configure WELCOME -elide 1
801    .t tag configure SYSTEM -elide 0
802    .t tag configure TRAFFIC -elide 1
803    .t insert end "\n" {SYSTEM TRAFFIC}
804    .t insert end "\n" WELCOME
805    lappend res [.t count -displaychars 1.0 end]
806    lappend res [.t count -displaychars 1.0 end-1c]
807    lappend res [.t count -displaychars 1.0 1.2]
808    lappend res [.t count -displaychars 2.0 end]
809    lappend res [.t count -displaychars 2.0 end-1c]
810    lappend res [.t index "1.0 +1 indices"]
811    lappend res [.t index "1.0 +1 display indices"]
812    lappend res [.t index "1.0 +1 display chars"]
813    lappend res [.t index end] 
814    lappend res [.t index "end -1 indices"]
815    lappend res [.t index "end -1 display indices"]
816    lappend res [.t index "end -1 display chars"]
817    lappend res [.t index "end -2 indices"]
818    lappend res [.t index "end -2 display indices"]
819    lappend res [.t index "end -2 display chars"]
820} {1 0 0 1 0 2.0 4.0 4.0 4.0 3.0 3.0 3.0 2.0 1.0 1.0}
821
822.t delete 1.0 end
823.t insert end $current
824unset current
825
826test text-10.1 {TextWidgetCmd procedure, "index" option} {
827    list [catch {.t index} msg] $msg
828} {1 {wrong # args: should be ".t index index"}}
829test text-10.2 {TextWidgetCmd procedure, "index" option} {
830    list [catch {.t ind a b} msg] $msg
831} {1 {wrong # args: should be ".t index index"}}
832test text-10.3 {TextWidgetCmd procedure, "index" option} {
833    list [catch {.t in a b} msg] $msg
834} {1 {ambiguous option "in": must be bbox, cget, compare, configure, count, debug, delete, dlineinfo, dump, edit, get, image, index, insert, mark, peer, replace, scan, search, see, tag, window, xview, or yview}}
835test text-10.4 {TextWidgetCmd procedure, "index" option} {
836    list [catch {.t index @xyz} msg] $msg
837} {1 {bad text index "@xyz"}}
838test text-10.5 {TextWidgetCmd procedure, "index" option} {
839    .t index 1.2
840} 1.2
841
842test text-11.1 {TextWidgetCmd procedure, "insert" option} {
843    list [catch {.t insert 1.2} msg] $msg
844} {1 {wrong # args: should be ".t insert index chars ?tagList chars tagList ...?"}}
845test text-11.2 {TextWidgetCmd procedure, "insert" option} {
846    .t config -state disabled
847    .t insert 1.2 xyzzy
848    .t get 1.0 1.end
849} {Line 1}
850.t config -state normal
851test text-11.3 {TextWidgetCmd procedure, "insert" option} {
852    .t insert 1.2 xyzzy
853    .t get 1.0 1.end
854} {Lixyzzyne 1}
855test text-11.4 {TextWidgetCmd procedure, "insert" option} {
856    .t delete 1.0 end
857    .t insert 1.0 "Sample text" x
858    .t tag ranges x
859} {1.0 1.11}
860test text-11.5 {TextWidgetCmd procedure, "insert" option} {
861    .t delete 1.0 end
862    .t insert 1.0 "Sample text" x
863    .t insert 1.2 "XYZ" y
864    list [.t tag ranges x] [.t tag ranges y]
865} {{1.0 1.2 1.5 1.14} {1.2 1.5}}
866test text-11.6 {TextWidgetCmd procedure, "insert" option} {
867    .t delete 1.0 end
868    .t insert 1.0 "Sample text" {x y z}
869    list [.t tag ranges x] [.t tag ranges y] [.t tag ranges z]
870} {{1.0 1.11} {1.0 1.11} {1.0 1.11}}
871test text-11.7 {TextWidgetCmd procedure, "insert" option} {
872    .t delete 1.0 end
873    .t insert 1.0 "Sample text" {x y z}
874    .t insert 1.3 "A" {a b z}
875    list [.t tag ranges a] [.t tag ranges b] [.t tag ranges x] [.t tag ranges y] [.t tag ranges z]
876} {{1.3 1.4} {1.3 1.4} {1.0 1.3 1.4 1.12} {1.0 1.3 1.4 1.12} {1.0 1.12}}
877test text-11.8 {TextWidgetCmd procedure, "insert" option} {
878    .t delete 1.0 end
879    list [catch {.t insert 1.0 "Sample text" "a \{b"} msg] $msg
880} {1 {unmatched open brace in list}}
881test text-11.9 {TextWidgetCmd procedure, "insert" option} {
882    .t delete 1.0 end
883    .t insert 1.0 "First" bold " " {} second "x y z" " third"
884    list [.t get 1.0 1.end] [.t tag ranges bold] [.t tag ranges x] \
885	    [.t tag ranges y] [.t tag ranges z]
886} {{First second third} {1.0 1.5} {1.6 1.12} {1.6 1.12} {1.6 1.12}}
887test text-11.10 {TextWidgetCmd procedure, "insert" option} {
888    .t delete 1.0 end
889    .t insert 1.0 "First" bold " second" silly
890    list [.t get 1.0 1.end] [.t tag ranges bold] [.t tag ranges silly]
891} {{First second} {1.0 1.5} {1.5 1.12}}
892
893# Edit, mark, scan, search, see, tag, window, xview, and yview actions are tested elsewhere.
894
895test text-12.1 {ConfigureText procedure} {
896    list [catch {.t2 configure -state foobar} msg] $msg
897} {1 {bad state "foobar": must be disabled or normal}}
898test text-12.2 {ConfigureText procedure} {
899    .t2 configure -spacing1 -2 -spacing2 1 -spacing3 1
900    list [.t2 cget -spacing1] [.t2 cget -spacing2] [.t2 cget -spacing3]
901} {0 1 1}
902test text-12.3 {ConfigureText procedure} {
903    .t2 configure -spacing1 1 -spacing2 -1 -spacing3 1
904    list [.t2 cget -spacing1] [.t2 cget -spacing2] [.t2 cget -spacing3]
905} {1 0 1}
906test text-12.4 {ConfigureText procedure} {
907    .t2 configure -spacing1 1 -spacing2 1 -spacing3 -3
908    list [.t2 cget -spacing1] [.t2 cget -spacing2] [.t2 cget -spacing3]
909} {1 1 0}
910test text-12.5 {ConfigureText procedure} {
911    set x [list [catch {.t2 configure -tabs {30 foo}} msg] $msg $errorInfo]
912    .t2 configure -tabs {10 20 30}
913    set x
914} {1 {bad tab alignment "foo": must be left, right, center, or numeric} {bad tab alignment "foo": must be left, right, center, or numeric
915    (while processing -tabs option)
916    invoked from within
917".t2 configure -tabs {30 foo}"}}
918test text-12.6 {ConfigureText procedure} {
919    .t2 configure -tabs {10 20 30}
920    .t2 configure -tabs {}
921    .t2 cget -tabs
922} {}
923test text-12.7 {ConfigureText procedure} {
924    list [catch {.t2 configure -wrap bogus} msg] $msg
925} {1 {bad wrap "bogus": must be char, none, or word}}
926test text-12.8 {ConfigureText procedure} {
927    .t2 configure -selectborderwidth 17 -selectforeground #332211 \
928	    -selectbackground #abc
929    list [lindex [.t2 tag config sel -borderwidth] 4] \
930	[lindex [.t2 tag config sel -foreground] 4] \
931	[lindex [.t2 tag config sel -background] 4]
932} {17 #332211 #abc}
933test text-12.9 {ConfigureText procedure} {
934    .t2 configure -selectborderwidth {}
935    .t2 tag cget sel -borderwidth
936} {}
937test text-12.10 {ConfigureText procedure} {
938    list [catch {.t2 configure -selectborderwidth foo} msg] $msg
939} {1 {bad screen distance "foo"}}
940test text-12.11 {ConfigureText procedure} {
941    catch {destroy .t2}
942    .t.e select to 2
943    text .t2 -exportselection 1
944    selection get
945} {ab}
946test text-12.12 {ConfigureText procedure} {
947    catch {destroy .t2}
948    .t.e select to 2
949    text .t2 -exportselection 0
950    .t2 insert insert 1234657890
951    .t2 tag add sel 1.0 1.4
952    selection get
953} {ab}
954test text-12.13 {ConfigureText procedure} {
955    catch {destroy .t2}
956    .t.e select to 1
957    text .t2 -exportselection 1
958    .t2 insert insert 1234657890
959    .t2 tag add sel 1.0 1.4
960    selection get
961} {1234}
962test text-12.14 {ConfigureText procedure} {
963    catch {destroy .t2}
964    .t.e select to 1
965    text .t2 -exportselection 0
966    .t2 insert insert 1234657890
967    .t2 tag add sel 1.0 1.4
968    .t2 configure -exportselection 1
969    selection get
970} {1234}
971test text-12.15 {ConfigureText procedure} {
972    catch {destroy .t2}
973    text .t2 -exportselection 1
974    .t2 insert insert 1234657890
975    .t2 tag add sel 1.0 1.4
976    set result [selection get]
977    .t2 configure -exportselection 0
978    lappend result [catch {selection get} msg] $msg
979} {1234 1 {PRIMARY selection doesn't exist or form "STRING" not defined}}
980test text-12.16 {ConfigureText procedure} {fonts} {
981    # This test is non-portable because the window size will vary depending
982    # on the font size, which can vary.
983    catch {destroy .t2}
984    toplevel .t2
985    text .t2.t -width 20 -height 10
986    pack append .t2 .t2.t top
987    wm geometry .t2 +0+0
988    update
989    wm geometry .t2
990} {150x140+0+0}
991test text-12.17 {ConfigureText procedure} {
992    # This test was failing Windows because the title bar on .t2
993    # was a certain minimum size and it was interfering with the size
994    # requested by the -setgrid.  The "overrideredirect" gets rid of the
995    # titlebar so the toplevel can shrink to the appropriate size.
996    catch {destroy .t2}
997    toplevel .t2
998    wm overrideredirect .t2 1
999    text .t2.t -width 20 -height 10 -setgrid 1
1000    pack append .t2 .t2.t top
1001    wm geometry .t2 +0+0
1002    update
1003    wm geometry .t2
1004} {20x10+0+0}
1005test text-12.18 {ConfigureText procedure} {
1006    # This test was failing on Windows because the title bar on .t2
1007    # was a certain minimum size and it was interfering with the size
1008    # requested by the -setgrid.  The "overrideredirect" gets rid of the
1009    # titlebar so the toplevel can shrink to the appropriate size.
1010    catch {destroy .t2}
1011    toplevel .t2
1012    wm overrideredirect .t2 1
1013    text .t2.t -width 20 -height 10 -setgrid 1
1014    pack append .t2 .t2.t top
1015    wm geometry .t2 +0+0
1016    update
1017    set result [wm geometry .t2]
1018    wm geometry .t2 15x8
1019    update
1020    lappend result [wm geometry .t2]
1021    .t2.t configure -wrap word
1022    update
1023    lappend result [wm geometry .t2]
1024} {20x10+0+0 15x8+0+0 15x8+0+0}
1025
1026test text-13.1 {TextWorldChanged procedure, spacing options} fonts {
1027    catch {destroy .t2}
1028    text .t2 -width 20 -height 10
1029    set result [winfo reqheight .t2]
1030    .t2 configure -spacing1 2
1031    lappend result [winfo reqheight .t2]
1032    .t2  configure -spacing3 1
1033    lappend result [winfo reqheight .t2]
1034    .t2 configure -spacing1 0
1035    lappend result [winfo reqheight .t2]
1036} {140 160 170 150}
1037
1038test text-14.1 {TextEventProc procedure} {
1039    text .tx1 -bg #543210
1040    rename .tx1 .tx2
1041    set x {}
1042    lappend x [winfo exists .tx1]
1043    lappend x [.tx2 cget -bg]
1044    destroy .tx1
1045    lappend x [info command .tx*] [winfo exists .tx1] [winfo exists .tx2]
1046} {1 #543210 {} 0 0}
1047
1048test text-15.1 {TextCmdDeletedProc procedure} {
1049    text .tx1
1050    rename .tx1 {}
1051    list [info command .tx*] [winfo exists .tx1]
1052} {{} 0}
1053test text-15.2 {TextCmdDeletedProc procedure, disabling -setgrid} fonts {
1054    catch {destroy .top}
1055    toplevel .top
1056    wm geom .top +0+0
1057    text .top.t -setgrid 1 -width 20 -height 10
1058    pack .top.t
1059    update
1060    set x [wm geometry .top]
1061    rename .top.t {}
1062    update
1063    lappend x [wm geometry .top]
1064    destroy .top
1065    set x
1066} {20x10+0+0 150x140+0+0}
1067
1068test text-16.1 {InsertChars procedure} {
1069    catch {destroy .t2}
1070    text .t2
1071    .t2 insert 2.0 abcd\n
1072    .t2 get 1.0 end
1073} {abcd
1074
1075}
1076test text-16.2 {InsertChars procedure} {
1077    catch {destroy .t2}
1078    text .t2
1079    .t2 insert 1.0 abcd\n
1080    .t2 insert end 123\n
1081    .t2 get 1.0 end
1082} {abcd
1083123
1084
1085}
1086test text-16.3 {InsertChars procedure} {
1087    catch {destroy .t2}
1088    text .t2
1089    .t2 insert 1.0 abcd\n
1090    .t2 insert 10.0 123
1091    .t2 get 1.0 end
1092} {abcd
1093123
1094}
1095test text-16.4 {InsertChars procedure, inserting on top visible line} {
1096    catch {destroy .t2}
1097    text .t2 -width 20 -height 4 -wrap word
1098    pack .t2
1099    .t2 insert insert "Now is the time for all great men to come to the "
1100    .t2 insert insert "aid of their party.\n"
1101    .t2 insert insert "Now is the time for all great men.\n"
1102    .t2 see end
1103    update
1104    .t2 insert 1.0 "Short\n"
1105    .t2 index @0,0
1106} {2.56}
1107test text-16.5 {InsertChars procedure, inserting on top visible line} {
1108    catch {destroy .t2}
1109    text .t2 -width 20 -height 4 -wrap word
1110    pack .t2
1111    .t2 insert insert "Now is the time for all great men to come to the "
1112    .t2 insert insert "aid of their party.\n"
1113    .t2 insert insert "Now is the time for all great men.\n"
1114    .t2 see end
1115    update
1116    .t2 insert 1.55 "Short\n"
1117    .t2 index @0,0
1118} {2.0}
1119test text-16.6 {InsertChars procedure, inserting on top visible line} {
1120    catch {destroy .t2}
1121    text .t2 -width 20 -height 4 -wrap word
1122    pack .t2
1123    .t2 insert insert "Now is the time for all great men to come to the "
1124    .t2 insert insert "aid of their party.\n"
1125    .t2 insert insert "Now is the time for all great men.\n"
1126    .t2 see end
1127    update
1128    .t2 insert 1.56 "Short\n"
1129    .t2 index @0,0
1130} {1.56}
1131test text-16.7 {InsertChars procedure, inserting on top visible line} {
1132    catch {destroy .t2}
1133    text .t2 -width 20 -height 4 -wrap word
1134    pack .t2
1135    .t2 insert insert "Now is the time for all great men to come to the "
1136    .t2 insert insert "aid of their party.\n"
1137    .t2 insert insert "Now is the time for all great men.\n"
1138    .t2 see end
1139    update
1140    .t2 insert 1.57 "Short\n"
1141    .t2 index @0,0
1142} {1.56}
1143catch {destroy .t2}
1144
1145proc setup {} {
1146    .t delete 1.0 end
1147    .t insert 1.0 "Line 1
1148abcde
114912345
1150Line 4"
1151}
1152
1153.t delete 1.0 end
1154test text-17.1 {DeleteChars procedure} {
1155    .t get 1.0 end
1156} {
1157}
1158test text-17.2 {DeleteChars procedure} {
1159    list [catch {.t delete foobar} msg] $msg
1160} {1 {bad text index "foobar"}}
1161test text-17.3 {DeleteChars procedure} {
1162    list [catch {.t delete 1.0 lousy} msg] $msg
1163} {1 {bad text index "lousy"}}
1164test text-17.4 {DeleteChars procedure} {
1165    setup
1166    .t delete 2.1
1167    .t get 1.0 end
1168} {Line 1
1169acde
117012345
1171Line 4
1172}
1173test text-17.5 {DeleteChars procedure} {
1174    setup
1175    .t delete 2.3
1176    .t get 1.0 end
1177} {Line 1
1178abce
117912345
1180Line 4
1181}
1182test text-17.6 {DeleteChars procedure} {
1183    setup
1184    .t delete 2.end
1185    .t get 1.0 end
1186} {Line 1
1187abcde12345
1188Line 4
1189}
1190test text-17.7 {DeleteChars procedure} {
1191    setup
1192    .t tag add sel 4.2 end
1193    .t delete 4.2 end
1194    list [.t tag ranges sel] [.t get 1.0 end]
1195} {{} {Line 1
1196abcde
119712345
1198Li
1199}}
1200test text-17.8 {DeleteChars procedure} {
1201    setup
1202    .t tag add sel 1.0 end
1203    .t delete 4.0 end
1204    list [.t tag ranges sel] [.t get 1.0 end]
1205} {{1.0 3.5} {Line 1
1206abcde
120712345
1208}}
1209test text-17.9 {DeleteChars procedure} {
1210    setup
1211    .t delete 2.2 2.2
1212    .t get 1.0 end
1213} {Line 1
1214abcde
121512345
1216Line 4
1217}
1218test text-17.10 {DeleteChars procedure} {
1219    setup
1220    .t delete 2.3 2.1
1221    .t get 1.0 end
1222} {Line 1
1223abcde
122412345
1225Line 4
1226}
1227test text-17.11 {DeleteChars procedure} {
1228    catch {destroy .t2}
1229    toplevel .t2
1230    text .t2.t -width 20 -height 5
1231    pack append .t2 .t2.t top
1232    wm geometry .t2 +0+0
1233    .t2.t insert 1.0 "abc\n123\nx\ny\nz\nq\nr\ns"
1234    update
1235    .t2.t delete 1.0 3.0
1236    list [.t2.t index @0,0] [.t2.t get @0,0]
1237} {1.0 x}
1238test text-17.12 {DeleteChars procedure} {
1239    catch {destroy .t2}
1240    toplevel .t2
1241    text .t2.t -width 20 -height 5
1242    pack append .t2 .t2.t top
1243    wm geometry .t2 +0+0
1244    .t2.t insert 1.0 "abc\n123\nx\ny\nz\nq\nr\ns"
1245    .t2.t yview 3.0
1246    update
1247    .t2.t delete 2.0 4.0
1248    list [.t2.t index @0,0] [.t2.t get @0,0]
1249} {2.0 y}
1250catch {destroy .t2}
1251toplevel .t2
1252text .t2.t -width 1 -height 10 -wrap char
1253frame .t2.f -width 200 -height 20 -relief raised -bd 2
1254pack .t2.f .t2.t -side left
1255wm geometry .t2 +0+0
1256update
1257test text-17.13 {DeleteChars procedure, updates affecting topIndex} {
1258    .t2.t delete 1.0 end
1259    .t2.t insert end "abcde\n12345\nqrstuv"
1260    .t2.t yview 2.1
1261    .t2.t delete 1.4 2.3
1262    .t2.t index @0,0
1263} {1.2}
1264test text-17.14 {DeleteChars procedure, updates affecting topIndex} {
1265    .t2.t delete 1.0 end
1266    .t2.t insert end "abcde\n12345\nqrstuv"
1267    .t2.t yview 2.1
1268    .t2.t delete 2.3 2.4
1269    .t2.t index @0,0
1270} {2.0}
1271test text-17.15 {DeleteChars procedure, updates affecting topIndex} {
1272    .t2.t delete 1.0 end
1273    .t2.t insert end "abcde\n12345\nqrstuv"
1274    .t2.t yview 1.3
1275    .t2.t delete 1.0 1.2
1276    .t2.t index @0,0
1277} {1.1}
1278test text-17.16 {DeleteChars procedure, updates affecting topIndex} {
1279    catch {destroy .t2}
1280    toplevel .t2
1281    text .t2.t -width 6 -height 10 -wrap word
1282    frame .t2.f -width 200 -height 20 -relief raised -bd 2
1283    pack .t2.f .t2.t -side left
1284    wm geometry .t2 +0+0
1285    update
1286    .t2.t insert end "abc def\n01 2345 678 9101112\nLine 3\nLine 4\nLine 5\n6\n7\n8\n"
1287    .t2.t yview 2.4
1288    .t2.t delete 2.5
1289    set x [.t2.t index @0,0]
1290    .t2.t delete 2.5
1291    list $x [.t2.t index @0,0]
1292} {2.3 2.0}
1293
1294.t delete 1.0 end
1295foreach i {a b c d e f g h i j k l m n o p q r s t u v w x y z} {
1296    .t insert end $i.0$i.1$i.2$i.3$i.4\n
1297}
1298test text-18.1 {TextFetchSelection procedure} {
1299    .t tag add sel 1.3 3.4
1300    selection get
1301} {a.1a.2a.3a.4
1302b.0b.1b.2b.3b.4
1303c.0c}
1304test text-18.2 {TextFetchSelection procedure} {
1305    .t tag add x 1.2
1306    .t tag add x 1.4
1307    .t tag add x 2.0
1308    .t tag add x 2.3
1309    .t tag remove sel 1.0 end
1310    .t tag add sel 1.0 3.4
1311    selection get
1312} {a.0a.1a.2a.3a.4
1313b.0b.1b.2b.3b.4
1314c.0c}
1315test text-18.3 {TextFetchSelection procedure} {
1316    .t tag remove sel 1.0 end
1317    .t tag add sel 13.3
1318    selection get
1319} {m}
1320test text-18.4 {TextFetchSelection procedure} {
1321    .t tag remove x 1.0 end
1322    .t tag add sel 1.0 3.4
1323    .t tag remove sel 1.0 end
1324    .t tag add sel 1.2 1.5
1325    .t tag add sel 2.4 3.1
1326    .t tag add sel 10.0 10.end
1327    .t tag add sel 13.3
1328    selection get
1329} {0a..1b.2b.3b.4
1330cj.0j.1j.2j.3j.4m}
1331set x ""
1332for {set i 1} {$i < 200} {incr i} {
1333    append x "This is line $i, padded to just about 53 characters.\n"
1334}
1335test text-18.5 {TextFetchSelection procedure, long selections} {
1336    .t delete 1.0 end
1337    .t insert end $x
1338    .t tag add sel 1.0 end
1339    selection get
1340} $x\n
1341
1342test text-19.1 {TkTextLostSelection procedure} unix {
1343    catch {destroy .t2}
1344    text .t2
1345    .t2 insert 1.0 "abc\ndef\nghijk\n1234"
1346    .t2 tag add sel 1.2 3.3
1347    .t.e select to 1
1348    .t2 tag ranges sel
1349} {}
1350test text-19.2 {TkTextLostSelection procedure} win {
1351    catch {destroy .t2}
1352    text .t2
1353    .t2 insert 1.0 "abc\ndef\nghijk\n1234"
1354    .t2 tag add sel 1.2 3.3
1355    .t.e select to 1
1356    .t2 tag ranges sel
1357} {1.2 3.3}
1358catch {destroy .t2}
1359test text-19.3 {TkTextLostSelection procedure} {
1360    catch {destroy .t2}
1361    text .t2
1362    .t2 insert 1.0 "abcdef\nghijk\n1234"
1363    .t2 tag add sel 1.0 1.3
1364    set x [selection get]
1365    selection clear
1366    lappend x [catch {selection get} msg] $msg
1367    .t2 tag add sel 1.0 1.3
1368    lappend x [selection get]
1369} {abc 1 {PRIMARY selection doesn't exist or form "STRING" not defined} abc}
1370
1371.t delete 1.0 end
1372.t insert end "xxyz xyz x. the\nfoo -forward bar xxxxx BaR foo\nxyz xxyzx"
1373test text-20.1 {TextSearchCmd procedure, argument parsing} {
1374    list [catch {.t search -} msg] $msg
1375} {1 {bad switch "-": must be --, -all, -backward, -count, -elide, -exact, -forward, -nocase, -nolinestop, -overlap, -regexp, or -strictlimits}}
1376test text-20.2 {TextSearchCmd procedure, -backwards option} {
1377    .t search -backwards xyz 1.4
1378} {1.1}
1379test text-20.2.1 {TextSearchCmd procedure, -all option} {
1380    .t search -all xyz 1.4
1381} {1.5 3.0 3.5 1.1}
1382test text-20.3 {TextSearchCmd procedure, -forwards option} {
1383    .t search -forwards xyz 1.4
1384} {1.5}
1385test text-20.4 {TextSearchCmd procedure, -exact option} {
1386    .t search -f -exact x. 1.0
1387} {1.9}
1388test text-20.5 {TextSearchCmd procedure, -regexp option} {
1389    .t search -b -regexp x.z 1.4
1390} {1.1}
1391test text-20.6 {TextSearchCmd procedure, -count option} {
1392    set length unmodified
1393    list [.t search -count length x. 1.4] $length
1394} {1.9 2}
1395test text-20.7 {TextSearchCmd procedure, -count option} {
1396    list [catch {.t search -count} msg] $msg
1397} {1 {no value given for "-count" option}}
1398test text-20.8 {TextSearchCmd procedure, -nocase option} {
1399    list [.t search -nocase BaR 1.1] [.t search BaR 1.1]
1400} {2.13 2.23}
1401test text-20.9 {TextSearchCmd procedure, -n ambiguous option} {
1402    list [catch {.t search -n BaR 1.1} msg] $msg
1403} {1 {bad switch "-n": must be --, -all, -backward, -count, -elide, -exact, -forward, -nocase, -nolinestop, -overlap, -regexp, or -strictlimits}}
1404test text-20.9.1 {TextSearchCmd procedure, -nocase option} {
1405    .t search -noc BaR 1.1
1406} {2.13}
1407test text-20.9.2 {TextSearchCmd procedure, -nolinestop option} {
1408    list [catch {.t search -nolinestop BaR 1.1} msg] $msg
1409} {1 {the "-nolinestop" option requires the "-regexp" option to be present}}
1410test text-20.9.3 {TextSearchCmd procedure, -nolinestop option} {
1411    set msg ""
1412    list [.t search -nolinestop -regexp -count msg e.*o 1.1] $msg
1413} {1.14 32}
1414test text-20.10 {TextSearchCmd procedure, -- option} {
1415    .t search -- -forward 1.0
1416} {2.4}
1417test text-20.11 {TextSearchCmd procedure, argument parsing} {
1418    list [catch {.t search abc} msg] $msg
1419} {1 {wrong # args: should be ".t search ?switches? pattern index ?stopIndex?"}}
1420test text-20.12 {TextSearchCmd procedure, argument parsing} {
1421    list [catch {.t search abc d e f} msg] $msg
1422} {1 {wrong # args: should be ".t search ?switches? pattern index ?stopIndex?"}}
1423test text-20.13 {TextSearchCmd procedure, check index} {
1424    list [catch {.t search abc gorp} msg] $msg
1425} {1 {bad text index "gorp"}}
1426test text-20.14 {TextSearchCmd procedure, startIndex == "end"} {
1427    .t search non-existent end
1428} {}
1429test text-20.15 {TextSearchCmd procedure, startIndex == "end"} {
1430    .t search non-existent end
1431} {}
1432test text-20.16 {TextSearchCmd procedure, bad stopIndex} {
1433    list [catch {.t search abc 1.0 lousy} msg] $msg
1434} {1 {bad text index "lousy"}}
1435test text-20.17 {TextSearchCmd procedure, pattern case conversion} {
1436    list [.t search -nocase BAR 1.1] [.t search BAR 1.1]
1437} {2.13 {}}
1438test text-20.18 {TextSearchCmd procedure, bad regular expression pattern} {
1439    list [catch {.t search -regexp a( 1.0} msg] $msg
1440} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
1441test text-20.19 {TextSearchCmd procedure, skip dummy last line} {
1442    .t search -backwards BaR end 1.0
1443} {2.23}
1444test text-20.20 {TextSearchCmd procedure, skip dummy last line} {
1445    .t search -backwards \n end 1.0
1446} {3.9}
1447test text-20.21 {TextSearchCmd procedure, skip dummy last line} {
1448    .t search \n end
1449} {1.15}
1450test text-20.22 {TextSearchCmd procedure, skip dummy last line} {
1451    .t search -back \n 1.0
1452} {3.9}
1453test text-20.23 {TextSearchCmd procedure, extract line contents} {
1454    .t tag add foo 1.2
1455    .t tag add x 1.3
1456    .t mark set silly 1.2
1457    .t search xyz 3.6
1458} {1.1}
1459test text-20.24 {TextSearchCmd procedure, stripping newlines} {
1460    .t search the\n 1.0
1461} {1.12}
1462test text-20.25 {TextSearchCmd procedure, handling newlines} {
1463    .t search -regexp the\n 1.0
1464} {1.12}
1465test text-20.26 {TextSearchCmd procedure, stripping newlines} {
1466    .t search -regexp {the$} 1.0
1467} {1.12}
1468test text-20.27 {TextSearchCmd procedure, handling newlines} {
1469    .t search -regexp \n 1.0
1470} {1.15}
1471test text-20.28 {TextSearchCmd procedure, line case conversion} {
1472    list [.t search -nocase bar 2.18] [.t search bar 2.18]
1473} {2.23 2.13}
1474test text-20.29 {TextSearchCmd procedure, firstChar and lastChar} {
1475    .t search -backwards xyz 1.6
1476} {1.5}
1477test text-20.30 {TextSearchCmd procedure, firstChar and lastChar} {
1478    .t search -backwards xyz 1.5
1479} {1.1}
1480test text-20.31 {TextSearchCmd procedure, firstChar and lastChar} {
1481    .t search xyz 1.5
1482} {1.5}
1483test text-20.32 {TextSearchCmd procedure, firstChar and lastChar} {
1484    .t search xyz 1.6
1485} {3.0}
1486test text-20.33 {TextSearchCmd procedure, firstChar and lastChar} {
1487    .t search {} 1.end
1488} {1.15}
1489test text-20.34 {TextSearchCmd procedure, firstChar and lastChar} {
1490    .t search f 1.end
1491} {2.0}
1492test text-20.35 {TextSearchCmd procedure, firstChar and lastChar} {
1493    .t search {} end
1494} {1.0}
1495test text-20.35a {TextSearchCmd procedure, regexp finds empty lines} {
1496    # Test for fix of bug #1643
1497    .t insert end "\n"
1498    tk::TextSetCursor .t 4.0
1499    .t search -forward -regexp {^$} insert end
1500} {4.0}
1501    
1502catch {destroy .t2}
1503toplevel .t2
1504wm geometry .t2 +0+0
1505text .t2.t -width 30 -height 10
1506pack .t2.t
1507.t2.t insert 1.0 "This is a line\nand this is another"
1508.t2.t insert end "\nand this is yet another"
1509frame .t2.f -width 20 -height 20 -bd 2 -relief raised
1510.t2.t window create 2.5 -window .t2.f
1511test text-20.36 {TextSearchCmd procedure, firstChar and lastChar} {
1512    .t2.t search his 2.6
1513} {2.6}
1514test text-20.37 {TextSearchCmd procedure, firstChar and lastChar} {
1515    .t2.t search this 2.6
1516} {3.4}
1517test text-20.38 {TextSearchCmd procedure, firstChar and lastChar} {
1518    .t2.t search is 2.6
1519} {2.7}
1520test text-20.39 {TextSearchCmd procedure, firstChar and lastChar} {
1521    .t2.t search his 2.7
1522} {3.5}
1523test text-20.40 {TextSearchCmd procedure, firstChar and lastChar} {
1524    .t2.t search -backwards "his is another" 2.6
1525} {2.6}
1526test text-20.41 {TextSearchCmd procedure, firstChar and lastChar} {
1527    .t2.t search -backwards "his is" 2.6
1528} {1.1}
1529destroy .t2
1530test text-20.42 {TextSearchCmd procedure, firstChar and lastChar} {
1531    .t search -backwards forw 2.5
1532} {2.5}
1533test text-20.43 {TextSearchCmd procedure, firstChar and lastChar} {
1534    .t search forw 2.5
1535} {2.5}
1536test text-20.44 {TextSearchCmd procedure, firstChar and lastChar} {
1537    catch {destroy .t2}
1538    text .t2
1539    list [.t2 search a 1.0] [.t2 search -backward a 1.0]
1540} {{} {}}
1541test text-20.45 {TextSearchCmd procedure, regexp match length} {
1542    set length unchanged
1543    list [.t search -regexp -count length x(.)(.*)z 1.1] $length
1544} {1.1 7}
1545test text-20.46 {TextSearchCmd procedure, regexp match length} {
1546    set length unchanged
1547    list [.t search -regexp -backward -count length fo* 2.5] $length
1548} {2.0 3}
1549test text-20.47 {TextSearchCmd procedure, checking stopIndex} {
1550    list [.t search bar 2.1 2.13] [.t search bar 2.1 2.14] \
1551	    [.t search bar 2.12 2.14] [.t search bar 2.14 2.14]
1552} {{} 2.13 2.13 {}}
1553test text-20.48 {TextSearchCmd procedure, checking stopIndex} {
1554    list [.t search -backwards bar 2.20 2.13] \
1555      [.t search -backwards bar 2.20 2.14] \
1556      [.t search -backwards bar 2.14 2.13] \
1557      [.t search -backwards bar 2.13 2.13]
1558} {2.13 {} 2.13 {}}
1559test text-20.48.1 {TextSearchCmd procedure, checking stopIndex} {
1560    list [.t search -backwards -strict bar 2.20 2.13] \
1561      [.t search -backwards -strict bar 2.20 2.14] \
1562      [.t search -backwards -strict bar 2.14 2.13] \
1563      [.t search -backwards -strict bar 2.13 2.13]
1564} {2.13 {} {} {}}
1565test text-20.49 {TextSearchCmd procedure, embedded windows and index/count} {
1566    frame .t.f1 -width 20 -height 20 -relief raised -bd 2
1567    frame .t.f2 -width 20 -height 20 -relief raised -bd 2
1568    frame .t.f3 -width 20 -height 20 -relief raised -bd 2
1569    frame .t.f4 -width 20 -height 20 -relief raised -bd 2
1570    .t window create 2.10 -window .t.f3
1571    .t window create 2.8 -window .t.f2
1572    .t window create 2.8 -window .t.f1
1573    .t window create 2.1 -window .t.f4
1574    set result ""
1575    lappend result [.t search -count x forward 1.0] $x
1576    lappend result [.t search -count x wa 1.0] $x
1577    .t delete 2.1
1578    .t delete 2.8 2.10
1579    .t delete 2.10
1580    set result
1581} {2.6 10 2.11 2}
1582test text-20.50 {TextSearchCmd procedure, error setting variable} {
1583    catch {unset a}
1584    set a 44
1585    list [catch {.t search -count a(2) xyz 1.0} msg] $msg
1586} {1 {can't set "a(2)": variable isn't array}}
1587test text-20.51 {TextSearchCmd procedure, wrap-around} {
1588    .t search -backwards xyz 1.1
1589} {3.5}
1590test text-20.52 {TextSearchCmd procedure, wrap-around} {
1591    .t search -backwards xyz 1.1 1.0
1592} {}
1593test text-20.53 {TextSearchCmd procedure, wrap-around} {
1594    .t search xyz 3.6
1595} {1.1}
1596test text-20.54 {TextSearchCmd procedure, wrap-around} {
1597    .t search xyz 3.6 end
1598} {}
1599test text-20.55 {TextSearchCmd procedure, no match} {
1600    .t search non_existent 3.5
1601} {}
1602test text-20.56 {TextSearchCmd procedure, no match} {
1603    .t search -regexp non_existent 3.5
1604} {}
1605test text-20.57 {TextSearchCmd procedure, special cases} {
1606    .t search -back x 1.1
1607} {1.0}
1608test text-20.58 {TextSearchCmd procedure, special cases} {
1609    .t search -back x 1.0
1610} {3.8}
1611test text-20.59 {TextSearchCmd procedure, special cases} {
1612    .t search \n {end-2c}
1613} {3.9}
1614test text-20.60 {TextSearchCmd procedure, special cases} {
1615    .t search \n end
1616} {1.15}
1617test text-20.61 {TextSearchCmd procedure, special cases} {
1618    .t search x 1.0
1619} {1.0}
1620test text-20.62 {TextSearchCmd, freeing copy of pattern} {
1621    # This test doesn't return a result, but it will generate
1622    # a core leak if the pattern copy isn't properly freed.
1623    # (actually in Tk 8.5 objectification means there is no
1624    # longer a copy of the pattern, but we leave this test in
1625    # anyway).
1626    set p abcdefg1234567890
1627    set p $p$p$p$p$p$p$p$p
1628    set p $p$p$p$p$p
1629    .t search -nocase $p 1.0
1630} {}
1631test text-20.63 {TextSearchCmd, unicode} {
1632    .t delete 1.0 end
1633    .t insert end "foo\u30c9\u30cabar"
1634    .t search \u30c9\u30ca 1.0
1635} 1.3
1636test text-20.64 {TextSearchCmd, unicode} {
1637    .t delete 1.0 end
1638    .t insert end "foo\u30c9\u30cabar"
1639    list [.t search -count n \u30c9\u30ca 1.0] $n
1640} {1.3 2}
1641test text-20.65 {TextSearchCmd, unicode with non-text segments} {
1642    .t delete 1.0 end
1643    button .b1 -text baz
1644    .t insert end "foo\u30c9"
1645    .t window create end -window .b1
1646    .t insert end "\u30cabar"
1647    set result [list [.t search -count n \u30c9\u30ca 1.0] $n]
1648    destroy .b1
1649    set result
1650} {1.3 3}
1651test text-20.66 {TextSearchCmd, hidden text does not affect match index} {
1652    deleteWindows
1653    pack [text .t2]
1654    .t2 insert end "12345H7890"
1655    .t2 search 7 1.0
1656} 1.6
1657test text-20.67 {TextSearchCmd, hidden text does not affect match index} {
1658    deleteWindows
1659    pack [text .t2]
1660    .t2 insert end "12345H7890"
1661    .t2 tag configure hidden -elide true
1662    .t2 tag add hidden 1.5
1663    .t2 search 7 1.0
1664} 1.6
1665test text-20.68 {TextSearchCmd, hidden text does not affect match index} {
1666    deleteWindows
1667    pack [text .t2]
1668    .t2 insert end "foobar\nbarbaz\nbazboo"
1669    .t2 search boo 1.0
1670} 3.3
1671test text-20.69 {TextSearchCmd, hidden text does not affect match index} {
1672    deleteWindows
1673    pack [text .t2]
1674    .t2 insert end "foobar\nbarbaz\nbazboo"
1675    .t2 tag configure hidden -elide true
1676    .t2 tag add hidden 2.0 3.0
1677    .t2 search boo 1.0
1678} 3.3
1679test text-20.70 {TextSearchCmd, -regexp -nocase searches} {
1680    catch {destroy .t}
1681    pack [text .t]
1682    .t insert end "word1 word2"
1683    set res [.t search -nocase -regexp {\mword.} 1.0 end]
1684    destroy .t
1685    set res
1686} 1.0
1687test text-20.71 {TextSearchCmd, -regexp -nocase searches} {
1688    catch {destroy .t}
1689    pack [text .t]
1690    .t insert end "word1 word2"
1691    set res [.t search -nocase -regexp {word.\M} 1.0 end]
1692    destroy .t
1693    set res
1694} 1.0
1695test text-20.72 {TextSearchCmd, -regexp -nocase searches} {
1696    catch {destroy .t}
1697    pack [text .t]
1698    .t insert end "word1 word2"
1699    set res [.t search -nocase -regexp {word.\W} 1.0 end]
1700    destroy .t
1701    set res
1702} 1.0
1703test text-20.73 {TextSearchCmd, hidden text and start index} {
1704    deleteWindows
1705    pack [text .t2]
1706    .t2 insert end "foobar\nfoobar\nfoobar"
1707    .t2 search bar 1.3
1708} 1.3
1709test text-20.74 {TextSearchCmd, hidden text shouldn't influence start index} {
1710    deleteWindows
1711    pack [text .t2]
1712    .t2 insert end "foobar\nfoobar\nfoobar"
1713    .t2 tag configure hidden -elide true
1714    .t2 tag add hidden 1.0 1.2
1715    .t2 search bar 1.3
1716} 1.3
1717test text-20.75 {TextSearchCmd, hidden text inside match must count in length} {
1718    deleteWindows
1719    pack [text .t2]
1720    .t2 insert end "foobar\nfoobar\nfoobar"
1721    .t2 tag configure hidden -elide true
1722    .t2 tag add hidden 1.2 1.4
1723    list [.t2 search -count foo foar 1.3] $foo
1724} {1.0 6}
1725test text-20.75.1 {TextSearchCmd, hidden text inside match must count in length} {
1726    deleteWindows
1727    pack [text .t2]
1728    .t2 insert end "foobar\nfoobar\nfoobar"
1729    .t2 tag configure hidden -elide true
1730    .t2 tag add hidden 1.2 1.4
1731    list \
1732      [.t2 search -strict -count foo foar 1.3] \
1733      [.t2 search -strict -count foo foar 2.3] $foo
1734} {{} 1.0 6}
1735test text-20.76 {TextSearchCmd, hidden text and start index} {
1736    deleteWindows
1737    pack [text .t2]
1738    .t2 insert end "foobar\nfoobar\nfoobar"
1739    .t2 search -regexp bar 1.3
1740} 1.3
1741test text-20.77 {TextSearchCmd, hidden text shouldn't influence start index} {
1742    deleteWindows
1743    pack [text .t2]
1744    .t2 insert end "foobar\nfoobar\nfoobar"
1745    .t2 tag configure hidden -elide true
1746    .t2 tag add hidden 1.0 1.2
1747    .t2 search -regexp bar 1.3
1748} 1.3
1749test text-20.78 {TextSearchCmd, hidden text inside match must count in length} {
1750    deleteWindows
1751    pack [text .t2]
1752    .t2 insert end "foobar\nfoobar\nfoobar"
1753    .t2 tag configure hidden -elide true
1754    .t2 tag add hidden 1.2 1.4
1755    list [.t2 search -regexp -count foo foar 1.3] $foo
1756} {1.0 6}
1757test text-20.78.1 {TextSearchCmd, hidden text inside match must count in length} {
1758    deleteWindows
1759    pack [text .t2]
1760    .t2 insert end "foobar\nfoobar\nfoobar"
1761    .t2 tag configure hidden -elide true
1762    .t2 tag add hidden 1.2 1.4
1763    list [.t2 search -count foo foar 1.3] $foo
1764} {1.0 6}
1765test text-20.78.2 {TextSearchCmd, hidden text inside match must count in length} {
1766    deleteWindows
1767    pack [text .t2]
1768    .t2 insert end "foobar\nfoobar\nfoobar"
1769    .t2 tag configure hidden -elide true
1770    .t2 tag add hidden 1.2 1.4
1771    .t2 search -strict -count foo foar 1.3
1772} {}
1773test text-20.78.3 {TextSearchCmd, hidden text inside match must count in length} {
1774    deleteWindows
1775    pack [text .t2]
1776    .t2 insert end "foobar\nfoobar\nfoar"
1777    .t2 tag configure hidden -elide true
1778    .t2 tag add hidden 1.2 1.4
1779    .t2 tag add hidden 2.2 2.4
1780    list [.t2 search -regexp -all -count foo foar 1.3] $foo
1781} {{2.0 3.0 1.0} {6 4 6}}
1782test text-20.78.4 {TextSearchCmd, hidden text inside match must count in length} {
1783    deleteWindows
1784    pack [text .t2]
1785    .t2 insert end "foobar\nfoobar\nfoar"
1786    .t2 tag configure hidden -elide true
1787    .t2 tag add hidden 1.2 1.4
1788    .t2 tag add hidden 2.2 2.4
1789    list [.t2 search -all -count foo foar 1.3] $foo
1790} {{2.0 3.0 1.0} {6 4 6}}
1791test text-20.78.5 {TextSearchCmd, hidden text inside match must count in length} {
1792    deleteWindows
1793    pack [text .t2]
1794    .t2 insert end "foobar\nfoobar\nfoar"
1795    .t2 tag configure hidden -elide true
1796    .t2 tag add hidden 1.2 1.4
1797    .t2 tag add hidden 2.2 2.4
1798    list [.t2 search -strict -all -count foo foar 1.3] $foo
1799} {{2.0 3.0} {6 4}}
1800test text-20.78.6 {TextSearchCmd, single line with -all} {
1801    deleteWindows
1802    pack [text .t2]
1803    .t2 insert end " X\n X\n X\n X\n X\n X\n"
1804    .t2 search -all -regexp { +| *\n} 1.0 end
1805} {1.0 1.2 2.0 2.2 3.0 3.2 4.0 4.2 5.0 5.2 6.0 6.2 7.0}
1806test text-20.79 {TextSearchCmd, multiline matching} {
1807    deleteWindows
1808    pack [text .t2]
1809    .t2 insert end "foobar\nfoobar\nfoobar"
1810    list [.t2 search -count foo foobar\nfoo 1.0] $foo
1811} {1.0 10}
1812test text-20.80 {TextSearchCmd, multiline matching} {
1813    deleteWindows
1814    pack [text .t2]
1815    .t2 insert end "foobar\nfoobar\nfoobar"
1816    list [.t2 search -count foo bar\nfoo 1.0] $foo
1817} {1.3 7}
1818test text-20.81 {TextSearchCmd, multiline matching} {
1819    deleteWindows
1820    pack [text .t2]
1821    .t2 insert end "foobar\nfoobar\nfoobar"
1822    list [.t2 search -count foo \nfoo 1.0] $foo
1823} {1.6 4}
1824test text-20.82 {TextSearchCmd, multiline matching} {
1825    deleteWindows
1826    pack [text .t2]
1827    .t2 insert end "foobar\nfoobar\nfoobar"
1828    list [.t2 search -count foo bar\nfoobar\nfoo 1.0] $foo
1829} {1.3 14}
1830test text-20.83 {TextSearchCmd, multiline matching} {
1831    deleteWindows
1832    pack [text .t2]
1833    .t2 insert end "foobar\nfoobar\nfoobar"
1834    .t2 search -count foo bar\nfoobar\nfoobanearly 1.0
1835} {}
1836test text-20.84 {TextSearchCmd, multiline matching} {
1837    deleteWindows
1838    pack [text .t2]
1839    .t2 insert end "foobar\nfoobar\nfoobar"
1840    list [.t2 search -regexp -count foo foobar\nfoo 1.0] $foo
1841} {1.0 10}
1842test text-20.85 {TextSearchCmd, multiline matching} {
1843    deleteWindows
1844    pack [text .t2]
1845    .t2 insert end "foobar\nfoobar\nfoobar"
1846    list [.t2 search -regexp -count foo bar\nfoo 1.0] $foo
1847} {1.3 7}
1848test text-20.86 {TextSearchCmd, multiline matching} {
1849    deleteWindows
1850    pack [text .t2]
1851    .t2 insert end "foobar\nfoobar\nfoobar"
1852    list [.t2 search -regexp -count foo \nfoo 1.0] $foo
1853} {1.6 4}
1854test text-20.87 {TextSearchCmd, multiline matching} {
1855    deleteWindows
1856    pack [text .t2]
1857    .t2 insert end "foobar\nfoobar\nfoobar"
1858    list [.t2 search -regexp -count foo bar\nfoobar\nfoo 1.0] $foo
1859} {1.3 14}
1860test text-20.88 {TextSearchCmd, multiline matching} {
1861    deleteWindows
1862    pack [text .t2]
1863    .t2 insert end "foobar\nfoobar\nfoobar"
1864    .t2 search -regexp -count foo bar\nfoobar\nfoobanearly 1.0
1865} {}
1866test text-20.89 {TextSearchCmd, multiline matching} {
1867    deleteWindows
1868    pack [text .t2]
1869    .t2 insert end "foobar\nfaoobar\nfoobar"
1870    .t2 search -regexp -count foo bar\nfoo 1.0
1871} {2.4}
1872test text-20.90 {TextSearchCmd, multiline matching end of window} {
1873    deleteWindows
1874    pack [text .t2]
1875    .t2 insert end "foobar\nfaoobar\nfoobar"
1876    .t2 search -regexp -count foo bar\nfoobar\n\n 1.0
1877} {}
1878test text-20.91 {TextSearchCmd, multiline matching end of window} {
1879    deleteWindows
1880    pack [text .t2]
1881    .t2 search "\n\n" 1.0
1882} {}
1883test text-20.92 {TextSearchCmd, multiline matching} {
1884    deleteWindows
1885    pack [text .t2]
1886    .t2 insert end "foobar\nfoobar\nfoobar"
1887    list [.t2 search -backwards -count foo foobar\nfoo end] $foo
1888} {2.0 10}
1889test text-20.93 {TextSearchCmd, multiline matching} {
1890    deleteWindows
1891    pack [text .t2]
1892    .t2 insert end "foobar\nfoobar\nfoobar"
1893    list [.t2 search -backwards -count foo bar\nfoo 1.0] $foo
1894} {2.3 7}
1895test text-20.94 {TextSearchCmd, multiline matching} {
1896    deleteWindows
1897    pack [text .t2]
1898    .t2 insert end "foobar\nfoobar\nfoobar"
1899    list [.t2 search -backwards -count foo \nfoo 1.0] $foo
1900} {2.6 4}
1901test text-20.95 {TextSearchCmd, multiline matching} {
1902    deleteWindows
1903    pack [text .t2]
1904    .t2 insert end "foobar\nfoobar\nfoobar"
1905    list [.t2 search -backwards -count foo bar\nfoobar\nfoo 1.0] $foo
1906} {1.3 14}
1907test text-20.96 {TextSearchCmd, multiline matching} {
1908    deleteWindows
1909    pack [text .t2]
1910    .t2 insert end "foobar\nfoobar\nfoobar"
1911    .t2 search -backwards -count foo bar\nfoobar\nfoobanearly 1.0
1912} {}
1913test text-20.97 {TextSearchCmd, multiline matching} {
1914    deleteWindows
1915    pack [text .t2]
1916    .t2 insert end "foobar\nfoobar\nfoobar"
1917    list [.t2 search -backwards -regexp -count foo foobar\nfoo end] $foo
1918} {2.0 10}
1919test text-20.97.1 {TextSearchCmd, multiline matching} {
1920    deleteWindows
1921    pack [text .t2]
1922    .t2 insert end "foobar\nfoobar\nfoobar"
1923    list [.t2 search -backwards -regexp -count foo foobar\nfo end] $foo
1924} {2.0 9}
1925test text-20.98 {TextSearchCmd, multiline matching} {
1926    deleteWindows
1927    pack [text .t2]
1928    .t2 insert end "foobar\nfoobar\nfoobar"
1929    list [.t2 search -backwards -regexp -count foo bar\nfoo 1.0] $foo
1930} {2.3 7}
1931test text-20.99 {TextSearchCmd, multiline matching} {
1932    deleteWindows
1933    pack [text .t2]
1934    .t2 insert end "foobar\nfoobar\nfoobar"
1935    list [.t2 search -backwards -regexp -count foo \nfoo 1.0] $foo
1936} {2.6 4}
1937test text-20.100 {TextSearchCmd, multiline matching} {
1938    deleteWindows
1939    pack [text .t2]
1940    .t2 insert end "foobar\nfoobar\nfoobar"
1941    list [.t2 search -backwards -regexp -count foo bar\nfoobar\nfoo 1.0] $foo
1942} {1.3 14}
1943test text-20.101 {TextSearchCmd, multiline matching} {
1944    deleteWindows
1945    pack [text .t2]
1946    .t2 insert end "foobar\nfoobar\nfoobar"
1947    .t2 search -backwards -regexp -count foo bar\nfoobar\nfoobanearly 1.0
1948} {}
1949test text-20.102 {TextSearchCmd, multiline matching} {
1950    deleteWindows
1951    pack [text .t2]
1952    .t2 insert end "foobar\nfaoobar\nfoobar"
1953    .t2 search -backwards -regexp -count foo bar\nfoo 1.0
1954} {2.4}
1955test text-20.103 {TextSearchCmd, multiline matching end of window} {
1956    deleteWindows
1957    pack [text .t2]
1958    .t2 insert end "foobar\nfaoobar\nfoobar"
1959    .t2 search -backwards -regexp -count foo bar\nfoobar\n\n 1.0
1960} {}
1961test text-20.104 {TextSearchCmd, multiline matching end of window} {
1962    deleteWindows
1963    pack [text .t2]
1964    .t2 search -backwards "\n\n" 1.0
1965} {}
1966test text-20.105 {TextSearchCmd, multiline regexp matching} {
1967    deleteWindows
1968    pack [text .t2]
1969    .t2 insert 1.0 {    Tcl_Obj *objPtr));
1970static Tcl_Obj*         FSNormalizeAbsolutePath 
1971			    _ANSI_ARGS_((Tcl_Interp* interp, Tcl_Obj *pathPtr));}
1972    set markExpr "^(\[A-Za-z0-9~_\]+\[ \t\n\r\]*\\(|(\[^ \t\(#\n\r/@:\*\]\[^=\(\r\n\]*\[ \t\]+\\*?)?"
1973    append markExpr "(\[A-Za-z0-9~_\]+(<\[^>\]*>)?(::)?(\[A-Za-z0-9~_\]+::)*\[-A-Za-z0-9~_+ <>\|\\*/\]+|\[A-Za-z0-9~_\]+)"
1974    append markExpr "\[ \n\t\r\]*\\()"
1975    .t2 search -forwards -regexp $markExpr 1.41 end
1976} {}
1977test text-20.106 {TextSearchCmd, multiline regexp matching} {
1978    # Practical example which used to crash Tk, but only after the
1979    # search is complete.  This is memory corruption caused by
1980    # a bug in Tcl's handling of string objects.
1981    # (Tcl bug 635200)
1982    deleteWindows
1983    pack [text .t2]
1984    .t2 insert 1.0 {static int		SetFsPathFromAny _ANSI_ARGS_((Tcl_Interp *interp,
1985			    Tcl_Obj *objPtr));
1986static Tcl_Obj*         FSNormalizeAbsolutePath 
1987			    _ANSI_ARGS_((Tcl_Interp* interp, Tcl_Obj *pathPtr));}
1988    set markExpr "^(\[A-Za-z0-9~_\]+\[ \t\n\r\]*\\(|(\[^ \t\(#\n\r/@:\*\]\[^=\(\r\n\]*\[ \t\]+\\*?)?"
1989    append markExpr "(\[A-Za-z0-9~_\]+(<\[^>\]*>)?(::)?(\[A-Za-z0-9~_\]+::)*\[-A-Za-z0-9~_+ <>\|\\*/\]+|\[A-Za-z0-9~_\]+)"
1990    append markExpr "\[ \n\t\r\]*\\()"
1991    .t2 search -forwards -regexp $markExpr 1.41 end
1992} {}
1993test text-20.107 {TextSearchCmd, multiline regexp matching} {
1994    deleteWindows
1995    pack [text .t2]
1996    .t2 insert 1.0 {
1997static int		SetFsPathFromAny _ANSI_ARGS_((Tcl_Interp *interp,
1998			    Tcl_Obj *objPtr));
1999static Tcl_Obj*         FSNormalizeAbsolutePath 
2000			    _ANSI_ARGS_((Tcl_Interp* interp, Tcl_Obj *pathPtr));}
2001    set markExpr "^(\[A-Za-z0-9~_\]+\[ \t\n\r\]*\\(|(\[^ \t\(#\n\r/@:\*\]\[^=\(\r\n\]*\[ \t\]+\\*?)?"
2002    append markExpr "(\[A-Za-z0-9~_\]+(<\[^>\]*>)?(::)?(\[A-Za-z0-9~_\]+::)*\[-A-Za-z0-9~_+ <>\|\\*/\]+|\[A-Za-z0-9~_\]+)"
2003    append markExpr "\[ \n\t\r\]*\\()"
2004    .t2 search -backwards -all -regexp $markExpr end
2005} {2.0}
2006test text-20.108 {TextSearchCmd, multiline matching} {
2007    deleteWindows
2008    pack [text .t2]
2009    .t2 insert end "foobar\nfoobar\nfoobar"
2010    .t2 search -all -regexp -count foo bar\nfoo 1.0
2011} {1.3 2.3}
2012test text-20.109 {TextSearchCmd, multiline matching} {
2013    deleteWindows
2014    pack [text .t2]
2015    .t2 insert end "foobar\nfoobar\nfoobar"
2016    .t2 search -all -backwards -regexp -count foo bar\nfoo 1.0
2017} {2.3 1.3}
2018test text-20.110 {TextSearchCmd, wrapping and limits} {
2019    deleteWindows
2020    pack [text .t2]
2021    .t2 insert end "foobar\nfoobar\nfoobar"
2022    .t2 search -- "blah" 3.3 1.3
2023} {}
2024test text-20.111 {TextSearchCmd, wrapping and limits} {
2025    deleteWindows
2026    pack [text .t2]
2027    .t2 insert end "foobar\nfoobar\nfoobar"
2028    .t2 search -backwards -- "blah" 1.3 3.3
2029} {}
2030test text-20.112 {TextSearchCmd, wrapping and limits} {
2031    deleteWindows
2032    pack [text .t2]
2033    .t2 insert end "if (stringPtr->uallocated > 0) \{x"
2034    .t2 search -backwards -regexp -- "\[\]\")\}\[(\{\]" "1.32" 1.0
2035} {1.31}
2036test text-20.113 {TextSearchCmd, wrapping and limits} {
2037    deleteWindows
2038    pack [text .t2]
2039    .t2 insert end "if (stringPtr->uallocated > 0) \{x"
2040    .t2 search -regexp -- "\[\]\")\}\[(\{\]" 1.30 "1.0 lineend"
2041} {1.31}
2042test text-20.114 {TextSearchCmd, wrapping and limits} {
2043    deleteWindows
2044    pack [text .t2]
2045    .t2 insert end "if (stringPtr->uallocated > 0) \{x"
2046    .t2 search -backwards -all -regexp -- "\[\]\")\}\[(\{\]" "1.32" 1.0
2047} {1.31 1.29 1.3}
2048test text-20.115 {TextSearchCmd, wrapping and limits} {
2049    deleteWindows
2050    pack [text .t2]
2051    .t2 insert end "if (stringPtr->uallocated > 0) \{x"
2052    .t2 search -all -regexp -- "\[\]\")\}\[(\{\]" 1.0 "1.0 lineend"
2053} {1.3 1.29 1.31}
2054test text-20.116 {TextSearchCmd, wrapping and limits} {
2055    deleteWindows
2056    pack [text .t2]
2057    .t2 insert end "if (stringPtr->uallocated > 0) \{x"
2058    .t2 search -backwards -- "\{" "1.32" 1.0
2059} {1.31}
2060test text-20.117 {TextSearchCmd, wrapping and limits} {
2061    deleteWindows
2062    pack [text .t2]
2063    .t2 insert end "if (stringPtr->uallocated > 0) \{x"
2064    .t2 search -- "\{" 1.30 "1.0 lineend"
2065} {1.31}
2066test text-20.118 {TextSearchCmd, multiline regexp matching} {
2067    deleteWindows
2068    pack [text .t2]
2069    .t2 insert 1.0 {
2070
2071void
2072Tcl_SetObjLength(objPtr, length)
2073    register Tcl_Obj *objPtr;	/* Pointer to object.  This object must
2074				 * not currently be shared. */
2075    register int length;	/* Number of bytes desired for string
2076				 * representation of object, not including
2077				 * terminating null byte. */
2078\{
2079    char *new;
2080}
2081    set markExpr "^(\[A-Za-z0-9~_\]+\[ \t\n\r\]*\\(|(\[^ \t\(#\n\r/@:\*\]\[^=\(\r\n\]*\[ \t\]+\\*?)?"
2082    append markExpr "(\[A-Za-z0-9~_\]+(<\[^>\]*>)?(::)?(\[A-Za-z0-9~_\]+::)*\[-A-Za-z0-9~_+ <>\|\\*/\]+|\[A-Za-z0-9~_\]+)"
2083    append markExpr "\[ \n\t\r\]*\\()"
2084    .t2 search -all -regexp -- $markExpr 1.0
2085} {4.0}
2086test text-20.119 {TextSearchCmd, multiline regexp matching} {
2087    deleteWindows
2088    pack [text .t2]
2089    .t2 insert 1.0 "first line\nlast line of text"
2090    set markExpr {^[a-z]+}
2091    # This should not match, and should not wrap
2092    .t2 search -regexp -- $markExpr end end
2093} {}
2094test text-20.120 {TextSearchCmd, multiline regexp matching} {
2095    deleteWindows
2096    pack [text .t2]
2097    .t2 insert 1.0 "first line\nlast line of text"
2098    set markExpr {^[a-z]+}
2099    # This should not match, and should not wrap
2100    .t2 search -regexp -- $markExpr end+10c end
2101} {}
2102test text-20.121 {TextSearchCmd, multiline regexp matching} {
2103    deleteWindows
2104    pack [text .t2]
2105    .t2 insert 1.0 "first line\nlast line of text"
2106    set markExpr {^[a-z]+}
2107    # This should not match, and should not wrap
2108    .t2 search -regexp -backwards -- $markExpr 1.0 1.0
2109} {}
2110test text-20.122 {TextSearchCmd, regexp linestop} {
2111    deleteWindows
2112    pack [text .t2]
2113    .t2 insert 1.0 "first line\nlast line of text"
2114    .t2 search -regexp -- {i.*x} 1.0
2115} {2.6}
2116test text-20.123 {TextSearchCmd, multiline regexp nolinestop matching} {
2117    deleteWindows
2118    pack [text .t2]
2119    .t2 insert 1.0 "first line\nlast line of text"
2120    .t2 search -regexp -nolinestop -- {i.*x} 1.0
2121} {1.1}
2122test text-20.124 {TextSearchCmd, regexp linestop} {
2123    deleteWindows
2124    pack [text .t2]
2125    .t2 insert 1.0 "first line\nlast line of text"
2126    .t2 search -regexp -all -overlap -- {i.*x} 1.0
2127} {2.6}
2128test text-20.124.1 {TextSearchCmd, regexp linestop} {
2129    deleteWindows
2130    pack [text .t2]
2131    .t2 insert 1.0 "first line\nlast line of text"
2132    .t2 search -regexp -all -- {i.*x} 1.0
2133} {2.6}
2134test text-20.125 {TextSearchCmd, multiline regexp nolinestop matching} {
2135    deleteWindows
2136    pack [text .t2]
2137    .t2 insert 1.0 "first line\nlast line of text"
2138    list [.t2 search -regexp -all -overlap -count c -nolinestop -- {i.*x} 1.0] $c
2139} {{1.1 2.6} {26 10}}
2140test text-20.125.1 {TextSearchCmd, multiline regexp nolinestop matching} {
2141    deleteWindows
2142    pack [text .t2]
2143    .t2 insert 1.0 "first line\nlast line of text"
2144    list [.t2 search -regexp -all -count c -nolinestop -- {i.*x} 1.0] $c
2145} {1.1 26}
2146test text-20.126 {TextSearchCmd, stop at end of line} {
2147    deleteWindows
2148    pack [text .t2]
2149    .t2 insert 1.0 "  \t\n   last line of text"
2150    .t2 search -regexp -nolinestop -- {[^ \t]} 1.0
2151} {1.3}
2152test text-20.127 {TextSearchCmd, overlapping all matches} {
2153    deleteWindows
2154    pack [text .t2]
2155    .t2 insert 1.0 "abcde abcde"
2156    list [.t2 search -regexp -all -overlap -count c -- {\w+} 1.0] $c
2157} {{1.0 1.6} {5 5}}
2158test text-20.127.1 {TextSearchCmd, non-overlapping all matches} {
2159    deleteWindows
2160    pack [text .t2]
2161    .t2 insert 1.0 "abcde abcde"
2162    list [.t2 search -regexp -all -count c -- {\w+} 1.0] $c
2163} {{1.0 1.6} {5 5}}
2164test text-20.128 {TextSearchCmd, stop at end of line} {
2165    deleteWindows
2166    pack [text .t2]
2167    .t2 insert 1.0 "abcde abcde"
2168    list [.t2 search -backwards -regexp -all -count c -- {\w+} 1.0] $c
2169} {{1.6 1.0} {5 5}}
2170test text-20.129 {TextSearchCmd, backwards search stop index } {
2171    deleteWindows
2172    pack [text .t2]
2173    .t2 insert 1.0 "bla ZabcZdefZghi and some text again"
2174    list [.t2 search -backwards -regexp -count c -- {Z\w+} 1.21 1.5] $c
2175} {1.8 8}
2176test text-20.130 {TextSearchCmd, backwards search stop index } {
2177    deleteWindows
2178    pack [text .t2]
2179    .t2 insert 1.0 "bla ZabcZdefZghi and some text again"
2180    list [.t2 search -backwards -all -overlap -regexp -count c -- {Z\w+} 1.21 1.5] $c
2181} {1.8 8}
2182test text-20.130.1 {TextSearchCmd, backwards search stop index } {
2183    deleteWindows
2184    pack [text .t2]
2185    .t2 insert 1.0 "bla ZabcZdefZghi and some text again"
2186    list [.t2 search -backwards -all -regexp -count c -- {Z\w+} 1.21 1.5] $c
2187} {1.8 8}
2188test text-20.131 {TextSearchCmd, backwards search stop index } {
2189    deleteWindows
2190    pack [text .t2]
2191    .t2 insert 1.0 "bla ZabcZdefZghi and some text again"
2192    list [.t2 search -backwards -overlap -all -regexp -count c -- {Z\w+} 1.21 1.1] $c
2193} {1.4 12}
2194test text-20.131.1 {TextSearchCmd, backwards search stop index } {
2195    deleteWindows
2196    pack [text .t2]
2197    .t2 insert 1.0 "bla ZabcZdefZghi and some text again"
2198    list [.t2 search -backwards -overlap -all -regexp -count c -- {Z[^Z]+Z} 1.21 1.1] $c
2199} {{1.8 1.4} {5 5}}
2200test text-20.131.2 {TextSearchCmd, backwards search stop index } {
2201    deleteWindows
2202    pack [text .t2]
2203    .t2 insert 1.0 "bla ZabcZdefZghi and some text again"
2204    list [.t2 search -backwards -all -regexp -count c -- {Z\w+} 1.21 1.1] $c
2205} {1.4 12}
2206test text-20.132 {TextSearchCmd, backwards search stop index } {
2207    deleteWindows
2208    pack [text .t2]
2209    .t2 insert 1.0 "bla ZabcZdefZghi and some text again"
2210    .t2 insert 1.0 "bla ZabcZdefZghi and some text again\n"
2211    list [.t2 search -backwards -all -overlap -regexp -count c -- {Z\w+} 2.21 1.5] $c
2212} {{2.4 1.8} {12 8}}
2213test text-20.132.1 {TextSearchCmd, backwards search stop index } {
2214    deleteWindows
2215    pack [text .t2]
2216    .t2 insert 1.0 "bla ZabcZdefZghi and some text again"
2217    .t2 insert 1.0 "bla ZabcZdefZghi and some text again\n"
2218    list [.t2 search -backwards -all -regexp -count c -- {Z\w+} 2.21 1.5] $c
2219} {{2.4 1.8} {12 8}}
2220test text-20.133 {TextSearchCmd, backwards search stop index } {
2221    deleteWindows
2222    pack [text .t2]
2223    .t2 insert 1.0 "bla ZabcZdefZghi and some text again"
2224    .t2 insert 1.0 "bla ZabcZdefZghi and some text again\n"
2225    list [.t2 search -backwards -overlap -all -regexp -count c -- {Z\w+} 2.21 1.1] $c
2226} {{2.4 1.4} {12 12}}
2227test text-20.133.1 {TextSearchCmd, backwards search stop index } {
2228    deleteWindows
2229    pack [text .t2]
2230    .t2 insert 1.0 "bla ZabcZdefZghi and some text again"
2231    .t2 insert 1.0 "bla ZabcZdefZghi and some text again\n"
2232    list [.t2 search -backwards -all -regexp -count c -- {Z\w+} 2.21 1.1] $c
2233} {{2.4 1.4} {12 12}}
2234test text-20.134 {TextSearchCmd, search -all example} {
2235    deleteWindows
2236    pack [text .t2]
2237    .t2 insert 1.0 {
2238
2239See the package: supersearch for more information.
2240
2241
2242See the package: incrementalSearch for more information.
2243
2244package: Brws .
2245
2246
2247See the package: marks for more information.
2248
2249}
2250    set pat {package: ([a-zA-Z0-9][-a-zA-Z0-9._+#/]*)}
2251    list [.t2 search -nolinestop -regexp -nocase -all -forwards \
2252      -count c -- $pat 1.0 end] $c
2253} {{3.8 6.8 8.0 11.8} {20 26 13 14}}
2254test text-20.135 {TextSearchCmd, backwards search overlaps} {
2255    deleteWindows
2256    pack [text .t2]
2257    .t2 insert 1.0 "foobarfoobaaaaaaaaaaarfoo"
2258    .t2 search -backwards -regexp {fooba+rfoo} end
2259} {1.6}
2260test text-20.135.1 {TextSearchCmd, backwards search overlaps} {
2261    deleteWindows
2262    pack [text .t2]
2263    .t2 insert 1.0 "foobarfoobaaaaaaaaaaarfoo"
2264    .t2 search -backwards -overlap -all -regexp {fooba+rfoo} end
2265} {1.6 1.0}
2266test text-20.135.2 {TextSearchCmd, backwards search overlaps} {
2267    deleteWindows
2268    pack [text .t2]
2269    .t2 insert 1.0 "foobarfoobaaaaaaaaaaarfoo"
2270    .t2 search -backwards -all -regexp {fooba+rfoo} end
2271} {1.6}
2272test text-20.135.3 {TextSearchCmd, forwards search overlaps} {
2273    deleteWindows
2274    pack [text .t2]
2275    .t2 insert 1.0 "foobarfoobaaaaaaaaaaarfoo"
2276    .t2 search -all -overlap -regexp {fooba+rfoo} end
2277} {1.0 1.6}
2278test text-20.135.4 {TextSearchCmd, forwards search overlaps} {
2279    deleteWindows
2280    pack [text .t2]
2281    .t2 insert 1.0 "foobarfoobaaaaaaaaaaarfoo"
2282    .t2 search -all -regexp {fooba+rfoo} end
2283} {1.0}
2284test text-20.136 {TextSearchCmd, forward exact search overlaps} {
2285    deleteWindows
2286    pack [text .t2]
2287    .t2 insert 1.0 "abababab"
2288    .t2 search -exact -overlap -all {abab} 1.0
2289} {1.0 1.2 1.4}
2290test text-20.136.1 {TextSearchCmd, forward exact search overlaps} {
2291    deleteWindows
2292    pack [text .t2]
2293    .t2 insert 1.0 "abababab"
2294    .t2 search -exact -all {abab} 1.0
2295} {1.0 1.4}
2296test text-20.137 {TextSearchCmd, backward exact search overlaps} {
2297    deleteWindows
2298    pack [text .t2]
2299    .t2 insert 1.0 "ababababab"
2300    .t2 search -exact -overlap -backwards -all {abab} end
2301} {1.6 1.4 1.2 1.0}
2302test text-20.137.1 {TextSearchCmd, backward exact search overlaps} {
2303    deleteWindows
2304    pack [text .t2]
2305    .t2 insert 1.0 "ababababab"
2306    .t2 search -exact -backwards -all {abab} end
2307} {1.6 1.2}
2308test text-20.137.2 {TextSearchCmd, backward exact search overlaps} {
2309    deleteWindows
2310    pack [text .t2]
2311    .t2 insert 1.0 "abababababab"
2312    .t2 search -exact -backwards -all {abab} end
2313} {1.8 1.4 1.0}
2314test text-20.138 {TextSearchCmd, forward exact search overlaps} {
2315    deleteWindows
2316    pack [text .t2]
2317    .t2 insert 1.0 "foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\n"
2318    .t2 search -exact -overlap -all "foo\nbar\nfoo" 1.0
2319} {1.0 3.0 5.0}
2320test text-20.138.1 {TextSearchCmd, forward exact search no-overlaps} {
2321    deleteWindows
2322    pack [text .t2]
2323    .t2 insert 1.0 "foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\n"
2324    .t2 search -exact -all "foo\nbar\nfoo" 1.0
2325} {1.0 5.0}
2326test text-20.139 {TextSearchCmd, backward exact search overlaps} {
2327    deleteWindows
2328    pack [text .t2]
2329    .t2 insert 1.0 "foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\n"
2330    .t2 search -exact -overlap -backward -all "foo\nbar\nfoo" end
2331} {5.0 3.0 1.0}
2332test text-20.140 {TextSearchCmd, backward exact search no-overlaps} {
2333    deleteWindows
2334    pack [text .t2]
2335    .t2 insert 1.0 "foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\n"
2336    .t2 search -exact -backward -all "foo\nbar\nfoo" end
2337} {5.0 1.0}
2338test text-20.141 {TextSearchCmd, backward exact search overlaps} {
2339    deleteWindows
2340    pack [text .t2]
2341    .t2 insert 1.0 "foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\n"
2342    .t2 search -regexp -backward -overlap -all "foo\nbar\nfoo" end
2343} {5.0 3.0 1.0}
2344test text-20.142 {TextSearchCmd, backward regexp search no-overlaps} {
2345    deleteWindows
2346    pack [text .t2]
2347    .t2 insert 1.0 "foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\n"
2348    .t2 search -regexp -backward -all "foo\nbar\nfoo" end
2349} {5.0 1.0}
2350test text-20.142a {TextSearchCmd, backward regexp search no-overlaps} {
2351    deleteWindows
2352    pack [text .t2]
2353    .t2 insert 1.0 " aasda asdj werwer"
2354    .t2 search -regexp -backward -- {(\$)?[\w:_]+} 1.9
2355} {1.7}
2356test text-20.143 {TextSearchCmd, backward regexp search no-overlaps} {
2357    deleteWindows
2358    pack [text .t2]
2359    .t2 insert 1.0 " aasda asdj werwer"
2360    .t2 search -regexp -backward -- {(\$)?[\w:_]+} 1.9 1.5
2361} {1.7}
2362test text-20.144 {TextSearchCmd, backward regexp search no-overlaps} {
2363    deleteWindows
2364    pack [text .t2]
2365    .t2 insert 1.0 " aasda asdj werwer"
2366    .t2 search -regexp -backward -- {(\$)?[\w:_]+} 1.9 1.7
2367} {1.7}
2368test text-20.145 {TextSearchCmd, backward regexp search no-overlaps} {
2369    deleteWindows
2370    pack [text .t2]
2371    .t2 insert 1.0 " aasda asdj werwer"
2372    .t2 search -regexp -backward -- {(\$)?[\w:_]+} 1.9 1.8
2373} {1.8}
2374test text-20.146 {TextSearchCmd, backward regexp search no-overlaps} {
2375    deleteWindows
2376    pack [text .t2]
2377    .t2 insert 1.0 " aasda asdj werwer"
2378    .t2 search -regexp -backward -all -- {(\$)?[\w:_]+} 1.9 1.3
2379} {1.7 1.3}
2380test text-20.147 {TextSearchCmd, backward regexp search no-overlaps} {
2381    deleteWindows
2382    pack [text .t2]
2383    .t2 insert 1.0 " aasda asdj werwer"
2384    .t2 search -regexp -backward -all -- {(\$)?[\w:_]+} 1.9 1.13
2385} {}
2386test text-20.148 {TextSearchCmd, backward regexp search no-overlaps} {
2387    deleteWindows
2388    pack [text .t2]
2389    .t2 insert 1.0 " aasda asdj werwer"
2390    .t2 search -regexp -backward -all -- {(\$)?[\w:_]+} 2.0 1.3
2391} {1.12 1.7 1.3}
2392test text-20.149 {TextSearchCmd, backward regexp search no-overlaps} {
2393    deleteWindows
2394    pack [text .t2]
2395    .t2 insert 1.0 " aasda asdj werwer"
2396    .t2 search -regexp -backward -all -- {(\$)?[\w:_]+} 1.3
2397} {1.1 1.12 1.7 1.3}
2398test text-20.150 {TextSearchCmd, backward regexp search no-overlaps} {
2399    deleteWindows
2400    pack [text .t2]
2401    .t2 insert 1.0 "abcde\nabcde\nabcde\n"
2402    .t2 search -regexp -backward -all -- {(\w+\n)+} end
2403} {1.0}
2404test text-20.151 {TextSearchCmd, backward regexp search no-overlaps} {
2405    deleteWindows
2406    pack [text .t2]
2407    .t2 insert 1.0 "abcde\nabcde\nabcde\n"
2408    .t2 search -regexp -backward -all -- {(\w+\n)+} end 1.5
2409} {2.0}
2410test text-20.152 {TextSearchCmd, backward regexp search no-overlaps} {
2411    deleteWindows
2412    pack [text .t2]
2413    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2414    .t2 search -regexp -backward -all -- {(\w+\n\w)+} end 1.5
2415} {2.0}
2416test text-20.153 {TextSearchCmd, backward regexp search no-overlaps} {
2417    deleteWindows
2418    pack [text .t2]
2419    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2420    list [.t2 search -regexp -all -count foo -- {(\w+\n)+} 1.0] $foo
2421} {1.0 20}
2422test text-20.154 {TextSearchCmd, backward regexp search no-overlaps} {
2423    deleteWindows
2424    pack [text .t2]
2425    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2426    set res {}
2427    lappend res \
2428      [list [.t2 search -regexp -all -count foo -- {(\w+\n)+} 1.0] $foo] \
2429      [list [.t2 search -regexp -all -count foo -- {(\w+)+} 1.0] $foo]
2430} {{1.0 20} {{1.0 2.0 3.0 4.0} {5 5 5 1}}}
2431test text-20.155 {TextSearchCmd, regexp search greedy} {
2432    deleteWindows
2433    pack [text .t2]
2434    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2435    list [.t2 search -regexp -all -nolinestop -count foo -- {.*} 1.0] $foo
2436} {1.0 20}
2437test text-20.156 {TextSearchCmd, regexp search greedy} {
2438    deleteWindows
2439    pack [text .t2]
2440    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2441    list [.t2 search -regexp -all -count foo -- {.*} 1.0] $foo
2442} {{1.0 2.0 3.0 4.0} {5 5 5 1}}
2443test text-20.157 {TextSearchCmd, regexp search greedy multi-line} {
2444    deleteWindows
2445    pack [text .t2]
2446    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2447    list [.t2 search -regexp -count foo -- {(\w+\n\w)+} 1.0] $foo
2448} {1.0 19}
2449test text-20.158 {TextSearchCmd, regexp search greedy multi-line} {
2450    deleteWindows
2451    pack [text .t2]
2452    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2453    list [.t2 search -regexp -backwards -count foo -- {(\w+\n\w)+} end] $foo
2454} {1.0 19}
2455test text-20.159 {TextSearchCmd, regexp search greedy multi-line} {
2456    deleteWindows
2457    pack [text .t2]
2458    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2459    list [.t2 search -regexp -all -backwards -count foo -- {(\w+\n\w)+} end] $foo
2460} {1.0 19}
2461test text-20.160 {TextSearchCmd, backward regexp search no-overlaps} {
2462    deleteWindows
2463    pack [text .t2]
2464    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2465    .t2 search -regexp -backward -all -- {(\w+\n\w)+} end 1.5
2466} {2.0}
2467test text-20.161 {TextSearchCmd, backward regexp search no-overlaps} {
2468    deleteWindows
2469    pack [text .t2]
2470    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2471    .t2 search -regexp -backward -all -- {(\w+\n\w)+} end 1.3
2472} {1.3}
2473test text-20.162 {TextSearchCmd, backward regexp search no-overlaps} {
2474    deleteWindows
2475    pack [text .t2]
2476    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2477    list [.t2 search -regexp -forward -count foo -- {(\w+\n\w)+} 1.3] $foo
2478} {1.3 16}
2479test text-20.163 {TextSearchCmd, backward regexp search no-overlaps} {
2480    deleteWindows
2481    pack [text .t2]
2482    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2483    list [.t2 search -regexp -forward -all -count foo -- {(\w+\n\w)+} 1.3] $foo
2484    # This result is somewhat debatable -- the two results do overlap,
2485    # but only because the search has totally wrapped around back to
2486    # the start.
2487} {{1.3 1.0} {16 19}}
2488test text-20.164 {TextSearchCmd, backward regexp search no-overlaps} {
2489    deleteWindows
2490    pack [text .t2]
2491    .t2 insert 1.0 "abcde\nabcde\nabcde\na"
2492    list [.t2 search -regexp -forward -all -count foo -- {(\w+\n\w)+} 1.0 1.3] $foo
2493} {1.0 19}
2494test text-20.165 {TextSearchCmd, regexp search multi-line} {
2495    deleteWindows
2496    pack [text .t2]
2497    .t2 insert 1.0 "aaaa\nbbbb\naaaa\nbbbb\n"
2498    list [.t2 search -regexp -forward -all -count foo -- {(a+\n(b+\n))+} 1.0] $foo
2499} {1.0 20}
2500test text-20.166 {TextSearchCmd, regexp search complex cases} {
2501    deleteWindows
2502    pack [text .t2]
2503    .t2 insert 1.0 "aaaa\nbbbb\naaaa\nbbbb\n"
2504    list [.t2 search -regexp -forward -all -count foo \
2505      -- {(a+\n(b+\n))+} 1.0] $foo
2506} {1.0 20}
2507test text-20.167 {TextSearchCmd, regexp search multi-line} {
2508    deleteWindows
2509    pack [text .t2]
2510    .t2 insert 1.0 "aaaa\nbbbb\ncccc\nbbbb\naaaa\n"
2511    set foo {}
2512    list [.t2 search -regexp -forward -all -count foo \
2513      -- {(b+\nc+\nb+)\na+} 1.0] $foo
2514} {2.0 19}
2515test text-20.168 {TextSearchCmd, regexp search multi-line} {knownBug} {
2516    deleteWindows
2517    pack [text .t2]
2518    .t2 insert 1.0 "aaaa\nbbbb\ncccc\nbbbb\naaaa\n"
2519    set foo {}
2520    list [.t2 search -regexp -forward -all -count foo \
2521      -- {(a+|b+\nc+\nb+)\na+} 1.0] $foo
2522} {2.0 19}
2523test text-20.169 {TextSearchCmd, regexp search multi-line} {knownBug} {
2524    deleteWindows
2525    pack [text .t2]
2526    .t2 insert 1.0 "aaaa\nbbbb\ncccc\nbbbb\naaaa\n"
2527    set foo {}
2528    list [.t2 search -regexp -forward -all -count foo \
2529      -- {(a+|b+\nc+\nb+)+\na+} 1.0] $foo
2530} {2.0 19}
2531test text-20.170 {TextSearchCmd, regexp search multi-line} {
2532    deleteWindows
2533    pack [text .t2]
2534    .t2 insert 1.0 "aaaa\nbbbb\ncccc\nbbbb\naaaa\n"
2535    set foo {}
2536    list [.t2 search -regexp -forward -all -count foo \
2537      -- {((a+|b+\nc+\nb+)+\n)+a+} 1.0] $foo
2538} {1.0 24}
2539test text-20.171 {TextSearchCmd, regexp search multi-line} {knownBug} {
2540    deleteWindows
2541    pack [text .t2]
2542    .t2 insert 1.0 "aaaa\nbbbb\nbbbb\nbbbb\nbbbb\n"
2543    list [.t2 search -regexp -backward -all -count foo \
2544      -- {b+\n|a+\n(b+\n)+} end] $foo
2545} {1.0 25}
2546test text-20.172 {TextSearchCmd, regexp search multi-line} {knownBug} {
2547    deleteWindows
2548    pack [text .t2]
2549    .t2 insert 1.0 "aaaa\nbbbb\nbbbb\nbbbb\nbbbb\n"
2550    .t2 search -regexp -backward -- {b+\n|a+\n(b+\n)+} end
2551    # Should match at 1.0 for a true greedy match
2552} {1.0}
2553test text-20.172.1 {TextSearchCmd, regexp search multi-line} {
2554    deleteWindows
2555    pack [text .t2]
2556    .t2 insert 1.0 "line0\nline1\nline1\nline1\nline1\nline2\nline2\nline2\nline3\n"
2557    .t2 search -nolinestop -regexp -nocase -forwards -- {^(.*)\n(\1\n)+} 1.0 end
2558    # Matches at 6.0 currently
2559} {2.0}
2560test text-20.173 {TextSearchCmd, regexp search multi-line} {
2561    deleteWindows
2562    pack [text .t2]
2563    .t2 insert 1.0 "\naaaxxx\nyyy\n"
2564    set res {}
2565    lappend res [.t2 search -count c -regexp -- {x*\ny*} 2.0] $c
2566    lappend res [.t2 search -count c -regexp -- {x*\ny*} 2.1] $c
2567    set res
2568} {2.3 7 2.3 7}
2569test text-20.174 {TextSearchCmd, regexp search multi-line} {
2570    deleteWindows
2571    pack [text .t2]
2572    .t2 insert 1.0 "\naaa\n\n\n\n\nxxx\n"
2573    set res {}
2574    lappend res [.t2 search -count c -regexp -- {\n+} 2.0] $c
2575    lappend res [.t2 search -count c -regexp -- {\n+} 2.1] $c
2576    set res
2577} {2.3 5 2.3 5}
2578test text-20.175 {TextSearchCmd, regexp search multi-line} {
2579    deleteWindows
2580    pack [text .t2]
2581    .t2 insert 1.0 "\naaa\n\n\t  \n\t\t\t  \n\nxxx\n"
2582    set res {}
2583    lappend res [.t2 search -count c -regexp -- {(\n+(\t+ *)*)+} 2.0] $c
2584    set res
2585} {2.3 13}
2586test text-20.176 {TextSearchCmd, empty search range} {
2587    deleteWindows
2588    pack [text .t2]
2589    .t2 insert 1.0 "a\na\na\n"
2590    .t2 search -- a 2.0 1.0
2591} {}
2592test text-20.177 {TextSearchCmd, empty search range} {
2593    deleteWindows
2594    pack [text .t2]
2595    .t2 insert 1.0 "a\na\na\n"
2596    .t2 search -backwards -- a 1.0 2.0
2597} {}
2598test text-20.178 {TextSearchCmd, empty search range} {
2599    deleteWindows
2600    pack [text .t2]
2601    .t2 insert 1.0 "a\na\na\n"
2602    .t2 search -- a 1.0 1.0
2603} {}
2604test text-20.179 {TextSearchCmd, empty search range} {
2605    deleteWindows
2606    pack [text .t2]
2607    .t2 insert 1.0 "a\na\na\n"
2608    .t2 search -backwards -- a 2.0 2.0
2609} {}
2610test text-20.180 {TextSearchCmd, elide up to match} {
2611    deleteWindows
2612    pack [text .t2]
2613    .t2 insert 1.0 "a\nb\nc"
2614    .t2 tag configure e -elide 1
2615    set res {}
2616    lappend res [.t2 search -regexp a 1.0]
2617    lappend res [.t2 search -regexp b 1.0]
2618    lappend res [.t2 search -regexp c 1.0]
2619    .t2 tag add e 1.0 2.0
2620    lappend res [.t2 search -regexp a 1.0]
2621    lappend res [.t2 search -regexp b 1.0]
2622    lappend res [.t2 search -regexp c 1.0]
2623    lappend res [.t2 search -elide -regexp a 1.0]
2624    lappend res [.t2 search -elide -regexp b 1.0]
2625    lappend res [.t2 search -elide -regexp c 1.0]
2626} {1.0 2.0 3.0 {} 2.0 3.0 1.0 2.0 3.0}
2627test text-20.181 {TextSearchCmd, elide up to match, backwards} {
2628    deleteWindows
2629    pack [text .t2]
2630    .t2 insert 1.0 "a\nb\nc"
2631    .t2 tag configure e -elide 1
2632    set res {}
2633    lappend res [.t2 search -backward -regexp a 1.0]
2634    lappend res [.t2 search -backward -regexp b 1.0]
2635    lappend res [.t2 search -backward -regexp c 1.0]
2636    .t2 tag add e 1.0 2.0
2637    lappend res [.t2 search -backward -regexp a 1.0]
2638    lappend res [.t2 search -backward -regexp b 1.0]
2639    lappend res [.t2 search -backward -regexp c 1.0]
2640    lappend res [.t2 search -backward -elide -regexp a 1.0]
2641    lappend res [.t2 search -backward -elide -regexp b 1.0]
2642    lappend res [.t2 search -backward -elide -regexp c 1.0]
2643} {1.0 2.0 3.0 {} 2.0 3.0 1.0 2.0 3.0}
2644test text-20.182 {TextSearchCmd, elide up to match} {
2645    deleteWindows
2646    pack [text .t2]
2647    .t2 insert 1.0 "a\nb\nc"
2648    .t2 tag configure e -elide 1
2649    set res {}
2650    lappend res [.t2 search a 1.0]
2651    lappend res [.t2 search b 1.0]
2652    lappend res [.t2 search c 1.0]
2653    .t2 tag add e 1.0 2.0
2654    lappend res [.t2 search a 1.0]
2655    lappend res [.t2 search b 1.0]
2656    lappend res [.t2 search c 1.0]
2657    lappend res [.t2 search -elide a 1.0]
2658    lappend res [.t2 search -elide b 1.0]
2659    lappend res [.t2 search -elide c 1.0]
2660} {1.0 2.0 3.0 {} 2.0 3.0 1.0 2.0 3.0}
2661test text-20.183 {TextSearchCmd, elide up to match, backwards} {
2662    deleteWindows
2663    pack [text .t2]
2664    .t2 insert 1.0 "a\nb\nc"
2665    .t2 tag configure e -elide 1
2666    set res {}
2667    lappend res [.t2 search -backward a 1.0]
2668    lappend res [.t2 search -backward b 1.0]
2669    lappend res [.t2 search -backward c 1.0]
2670    .t2 tag add e 1.0 2.0
2671    lappend res [.t2 search -backward a 1.0]
2672    lappend res [.t2 search -backward b 1.0]
2673    lappend res [.t2 search -backward c 1.0]
2674    lappend res [.t2 search -backward -elide a 1.0]
2675    lappend res [.t2 search -backward -elide b 1.0]
2676    lappend res [.t2 search -backward -elide c 1.0]
2677} {1.0 2.0 3.0 {} 2.0 3.0 1.0 2.0 3.0}
2678test text-20.184 {TextSearchCmd, elide up to match} {
2679    deleteWindows
2680    pack [text .t2]
2681    .t2 insert 1.0 "aa\nbb\ncc"
2682    .t2 tag configure e -elide 1
2683    set res {}
2684    lappend res [.t2 search ab 1.0]
2685    lappend res [.t2 search bc 1.0]
2686    .t2 tag add e 1.1 2.1
2687    lappend res [.t2 search ab 1.0]
2688    lappend res [.t2 search b 1.0]
2689    .t2 tag remove e 1.0 end
2690    .t2 tag add e 2.1 3.1
2691    lappend res [.t2 search bc 1.0]
2692    lappend res [.t2 search c 1.0]
2693    .t2 tag remove e 1.0 end
2694    .t2 tag add e 2.1 3.0
2695    lappend res [.t2 search bc 1.0]
2696    lappend res [.t2 search c 1.0]
2697} {{} {} 1.0 2.1 2.0 3.1 2.0 3.0}
2698test text-20.185 {TextSearchCmd, elide up to match} {
2699    deleteWindows
2700    pack [text .t2]
2701    .t2 insert 1.0 "aa\nbb\ncc"
2702    .t2 tag configure e -elide 1
2703    set res {}
2704    lappend res [.t2 search -regexp ab 1.0]
2705    lappend res [.t2 search -regexp bc 1.0]
2706    .t2 tag add e 1.1 2.1
2707    lappend res [.t2 search -regexp ab 1.0]
2708    lappend res [.t2 search -regexp b 1.0]
2709    .t2 tag remove e 1.0 end
2710    .t2 tag add e 2.1 3.1
2711    lappend res [.t2 search -regexp bc 1.0]
2712    lappend res [.t2 search -regexp c 1.0]
2713    .t2 tag remove e 1.0 end
2714    .t2 tag add e 2.1 3.0
2715    lappend res [.t2 search -regexp bc 1.0]
2716    lappend res [.t2 search -regexp c 1.0]
2717} {{} {} 1.0 2.1 2.0 3.1 2.0 3.0}
2718test text-20.186 {TextSearchCmd, strict limits} {
2719    deleteWindows
2720    pack [text .t2]
2721    .t2 insert 1.0 "Hello world!\nThis is a test\n"
2722    .t2 search -strictlimits -- "world" 1.3 1.8
2723} {}
2724test text-20.187 {TextSearchCmd, strict limits} {
2725    deleteWindows
2726    pack [text .t2]
2727    .t2 insert 1.0 "Hello world!\nThis is a test\n"
2728    .t2 search -strictlimits -- "world" 1.3 1.10
2729} {}
2730test text-20.188 {TextSearchCmd, strict limits} {
2731    deleteWindows
2732    pack [text .t2]
2733    .t2 insert 1.0 "Hello world!\nThis is a test\n"
2734    .t2 search -strictlimits -- "world" 1.3 1.11
2735} {1.6}
2736test text-20.189 {TextSearchCmd, strict limits backwards} {
2737    deleteWindows
2738    pack [text .t2]
2739    .t2 insert 1.0 "Hello world!\nThis is a test\n"
2740    .t2 search -strictlimits -backward -- "world" 2.3 1.8
2741} {}
2742test text-20.190 {TextSearchCmd, strict limits backwards} {
2743    deleteWindows
2744    pack [text .t2]
2745    .t2 insert 1.0 "Hello world!\nThis is a test\n"
2746    .t2 search -strictlimits -backward -- "world" 2.3 1.6
2747} {1.6}
2748test text-20.191 {TextSearchCmd, strict limits backwards} {
2749    deleteWindows
2750    pack [text .t2]
2751    .t2 insert 1.0 "Hello world!\nThis is a test\n"
2752    .t2 search -strictlimits -backward -- "world" 2.3 1.7
2753} {}
2754test text-20.192 {TextSearchCmd, strict limits} {
2755    deleteWindows
2756    pack [text .t2]
2757    .t2 insert 1.0 "Hello world!\nThis is a test\n"
2758    .t2 search -regexp -strictlimits -- "world" 1.3 1.8
2759} {}
2760test text-20.193 {TextSearchCmd, strict limits} {
2761    deleteWindows
2762    pack [text .t2]
2763    .t2 insert 1.0 "Hello world!\nThis is a test\n"
2764    .t2 search -regexp -strictlimits -backward -- "world" 2.3 1.8
2765} {}
2766
2767deleteWindows
2768text .t2 -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 100
2769pack .t2
2770.t2 insert end "1\t2\t3\t4\t55.5"
2771
2772test text-21.1 {TkTextGetTabs procedure} {
2773    list [catch {.t2 configure -tabs "\{{}"} msg] $msg
2774} {1 {unmatched open brace in list}}
2775test text-21.2 {TkTextGetTabs procedure} {
2776    list [catch {.t2 configure -tabs xyz} msg] $msg
2777} {1 {bad screen distance "xyz"}}
2778test text-21.3 {TkTextGetTabs procedure} {
2779    .t2 configure -tabs {100 200}
2780    update idletasks
2781    list [lindex [.t2 bbox 1.2] 0] [lindex [.t2 bbox 1.4] 0]
2782} {100 200}
2783test text-21.4 {TkTextGetTabs procedure} {
2784    .t2 configure -tabs {100 right 200 left 300 center 400 numeric}
2785    update idletasks
2786    list [expr [lindex [.t2 bbox 1.2] 0] + [lindex [.t2 bbox 1.2] 2]] \
2787	    [lindex [.t2 bbox 1.4] 0] \
2788	    [expr [lindex [.t2 bbox 1.6] 0] + [lindex [.t2 bbox 1.6] 2]/2] \
2789	    [lindex [.t2 bbox 1.10] 0]
2790} {100 200 300 400}
2791test text-21.5 {TkTextGetTabs procedure} {
2792    .t2 configure -tabs {105 r 205 l 305 c 405 n}
2793    update idletasks
2794    list [expr [lindex [.t2 bbox 1.2] 0] + [lindex [.t2 bbox 1.2] 2]] \
2795	    [lindex [.t2 bbox 1.4] 0] \
2796	    [expr [lindex [.t2 bbox 1.6] 0] + [lindex [.t2 bbox 1.6] 2]/2] \
2797	    [lindex [.t2 bbox 1.10] 0]
2798} {105 205 305 405}
2799test text-21.6 {TkTextGetTabs procedure} {
2800    list [catch {.t2 configure -tabs {100 left 200 lork}} msg] $msg
2801} {1 {bad tab alignment "lork": must be left, right, center, or numeric}}
2802test text-21.7 {TkTextGetTabs procedure} {
2803    list [catch {.t2 configure -tabs {100 !44 200 lork}} msg] $msg
2804} {1 {bad screen distance "!44"}}
2805
2806deleteWindows
2807text .t
2808pack .t
2809.t insert 1.0 "One Line"
2810.t mark set insert 1.0
2811
2812test text-22.1 {TextDumpCmd procedure, bad args} {
2813    list [catch {.t dump} msg] $msg
2814} {1 {Usage: .t dump ?-all -image -text -mark -tag -window? ?-command script? index ?index2?}}
2815test text-22.2 {TextDumpCmd procedure, bad args} {
2816    list [catch {.t dump -all} msg] $msg
2817} {1 {Usage: .t dump ?-all -image -text -mark -tag -window? ?-command script? index ?index2?}}
2818test text-22.3 {TextDumpCmd procedure, bad args} {
2819    list [catch {.t dump -command} msg] $msg
2820} {1 {Usage: .t dump ?-all -image -text -mark -tag -window? ?-command script? index ?index2?}}
2821test text-22.4 {TextDumpCmd procedure, bad args} {
2822    list [catch {.t dump -bogus} msg] $msg
2823} {1 {bad option "-bogus": must be -all, -command, -image, -mark, -tag, -text, or -window}}
2824test text-22.5 {TextDumpCmd procedure, bad args} {
2825    list [catch {.t dump bogus} msg] $msg
2826} {1 {bad text index "bogus"}}
2827test text-22.6 {TextDumpCmd procedure, one index} {
2828    .t dump -text 1.2
2829} {text e 1.2}
2830test text-22.7 {TextDumpCmd procedure, two indices} {
2831    .t dump -text 1.0 1.end
2832} {text {One Line} 1.0}
2833test text-22.8 {TextDumpCmd procedure, "end" index} {
2834    .t dump -text 1.end end
2835} {text {
2836} 1.8}
2837test text-22.9 {TextDumpCmd procedure, same indices} {
2838    .t dump 1.5 1.5
2839} {}
2840test text-22.10 {TextDumpCmd procedure, negative range} {
2841    .t dump 1.5 1.0
2842} {}
2843.t delete 1.0 end
2844.t insert end "Line One\nLine Two\nLine Three\nLine Four"
2845.t mark set insert 1.0
2846.t mark set current 1.0
2847test text-22.11 {TextDumpCmd procedure, stop at begin-line} {
2848    .t dump -text 1.0 2.0
2849} {text {Line One
2850} 1.0}
2851test text-22.12 {TextDumpCmd procedure, span multiple lines} {
2852    .t dump -text 1.5 3.end
2853} {text {One
2854} 1.5 text {Line Two
2855} 2.0 text {Line Three} 3.0}
2856.t tag add x 2.0 2.end
2857.t tag add y 1.0 end
2858.t mark set m 2.4
2859.t mark set n 4.0
2860.t mark set END end
2861test text-22.13 {TextDumpCmd procedure, tags only} {
2862    .t dump -tag 2.1 2.8
2863} {}
2864test text-22.14 {TextDumpCmd procedure, tags only} {
2865    .t dump -tag 2.0 2.8
2866} {tagon x 2.0}
2867test text-22.15 {TextDumpCmd procedure, tags only} {
2868    .t dump -tag 1.0 4.end
2869} {tagon y 1.0 tagon x 2.0 tagoff x 2.8}
2870test text-22.16 {TextDumpCmd procedure, tags only} {
2871    .t dump -tag 1.0 end
2872} {tagon y 1.0 tagon x 2.0 tagoff x 2.8 tagoff y 5.0}
2873.t mark set insert 1.0
2874.t mark set current 1.0
2875test text-22.17 {TextDumpCmd procedure, marks only} {
2876    .t dump -mark 1.1 1.8
2877} {}
2878test text-22.18 {TextDumpCmd procedure, marks only} {
2879    .t dump -mark 2.0 2.8
2880} {mark m 2.4}
2881test text-22.19 {TextDumpCmd procedure, marks only} {
2882    .t dump -mark 1.1 4.end
2883} {mark m 2.4 mark n 4.0}
2884test text-22.20 {TextDumpCmd procedure, marks only} {
2885    .t dump -mark 1.0 end
2886} {mark current 1.0 mark insert 1.0 mark m 2.4 mark n 4.0 mark END 5.0}
2887button .hello -text Hello
2888.t window create 3.end -window .hello
2889for {set i 0} {$i < 100} {incr i} {
2890    .t insert end "-\n"
2891}
2892.t window create 100.0 -create { }
2893test text-22.21 {TextDumpCmd procedure, windows only} {
2894    .t dump -window 1.0 5.0
2895} {window .hello 3.10}
2896test text-22.22 {TextDumpCmd procedure, windows only} {
2897    .t dump -window 5.0 end
2898} {window {} 100.0}
2899.t delete 1.0 end
2900eval {.t mark unset} [.t mark names]
2901.t insert end "Line One\nLine Two\nLine Three\nLine Four"
2902.t mark set insert 1.0
2903.t mark set current 1.0
2904.t tag add x 2.0 2.end
2905.t mark set m 2.4
2906proc Append {varName key value index} {
2907    upvar #0 $varName x
2908    lappend x $key $index $value
2909}
2910test text-22.23 {TextDumpCmd procedure, command script} {
2911    set x {}
2912    .t dump -command {Append x} -all 1.0 end
2913    set x
2914} {mark 1.0 current mark 1.0 insert text 1.0 {Line One
2915} tagon 2.0 x text 2.0 Line mark 2.4 m text 2.4 { Two} tagoff 2.8 x text 2.8 {
2916} text 3.0 {Line Three
2917} text 4.0 {Line Four
2918}}
2919test text-22.24 {TextDumpCmd procedure, command script} {
2920    set x {}
2921    .t dump -mark -command {Append x} 1.0 end
2922    set x
2923} {mark 1.0 current mark 1.0 insert mark 2.4 m}
2924catch {unset x}
2925test text-22.25 {TextDumpCmd procedure, unicode characters} {
2926    catch {destroy .t}
2927    text .t
2928    .t delete 1.0 end
2929    .t insert 1.0 \xb1\xb1\xb1
2930    .t dump -all 1.0 2.0
2931} "text \xb1\xb1\xb1 1.0 mark insert 1.3 mark current 1.3 text {\n} 1.3"
2932test text-22.26 {TextDumpCmd procedure, unicode characters} {
2933    catch {destroy .t}
2934    text .t
2935    .t delete 1.0 end
2936    .t insert 1.0 abc\xb1\xb1\xb1
2937    .t dump -all 1.0 2.0
2938} "text abc\xb1\xb1\xb1 1.0 mark insert 1.6 mark current 1.6 text {\n} 1.6"
2939test text-22.27 {TextDumpCmd procedure, peer present} -setup {
2940    destroy .t
2941} -body {
2942    text .t
2943    .t peer create .t.t
2944    .t dump -all 1.0 end
2945} -cleanup {
2946    destroy .t
2947} -result "mark insert 1.0 mark current 1.0 text {\n} 1.0"
2948
2949set l [interp hidden]
2950deleteWindows
2951
2952test text-23.1 {text widget vs hidden commands} {
2953    catch {destroy .t}
2954    text .t
2955    interp hide {} .t
2956    destroy .t
2957    list [winfo children .] [interp hidden]
2958} [list {} $l]
2959
2960test text-24.1 {bug fix - 1642} {
2961    catch {destroy .t}
2962    text .t
2963    pack .t
2964    .t insert end "line 1\n"
2965    .t insert end "line 2\n"
2966    .t insert end "line 3\n"
2967    .t insert end "line 4\n"
2968    .t insert end "line 5\n"
2969    tk::TextSetCursor .t 3.0
2970    .t search -backward -regexp "\$" insert 1.0
2971} {2.6}
2972
2973test text-25.1 {TextEditCmd procedure, argument parsing} {
2974    list [catch {.t edit} msg] $msg
2975} {1 {wrong # args: should be ".t edit option ?arg arg ...?"}}
2976test text-25.2 {TextEditCmd procedure, argument parsing} {
2977    list [catch {.t edit gorp} msg] $msg
2978} {1 {bad edit option "gorp": must be modified, redo, reset, separator, or undo}}
2979test text-25.3 {TextEditUndo procedure, undoing changes} {
2980    catch {destroy .t}
2981    text .t -undo 1
2982    pack .t
2983    .t insert end "line 1\n"
2984    .t delete 1.4 1.6
2985    .t insert end "should be gone after undo\n"
2986    .t edit undo
2987    .t get 1.0 end
2988} "line\n\n"
2989test text-25.4 {TextEditRedo procedure, redoing changes} {
2990    catch {destroy .t}
2991    text .t -undo 1
2992    pack .t
2993    .t insert end "line 1\n"
2994    .t delete 1.4 1.6
2995    .t insert end "should be back after redo\n"
2996    .t edit undo
2997    .t edit redo
2998    .t get 1.0 end
2999} "line\nshould be back after redo\n\n"
3000test text-25.5 {TextEditUndo procedure, resetting stack} {
3001    catch {destroy .t}
3002    text .t -undo 1
3003    pack .t
3004    .t insert end "line 1\n"
3005    .t delete 1.4 1.6
3006    .t insert end "should be back after redo\n"
3007    .t edit reset
3008    catch {.t edit undo} msg
3009    set msg
3010} "nothing to undo"
3011test text-25.6 {TextEditCmd procedure, insert separator} {
3012    catch {destroy .t}
3013    text .t -undo 1
3014    pack .t
3015    .t insert end "line 1\n"
3016    .t edit separator
3017    .t insert end "line 2\n"
3018    .t edit undo
3019    .t get 1.0 end
3020} "line 1\n\n"
3021test text-25.7 {-autoseparators configuration option} {
3022    catch {destroy .t}
3023    text .t -undo 1 -autoseparators 0
3024    pack .t
3025    .t insert end "line 1\n"
3026    .t delete 1.4 1.6
3027    .t insert end "line 2\n"
3028    .t edit undo
3029    .t get 1.0 end
3030} "\n"
3031test text-25.8 {TextEditCmd procedure, modified flag} {
3032    catch {destroy .t}
3033    text .t
3034    pack .t
3035    .t insert end "line 1\n"
3036    .t edit modified
3037} {1}
3038test text-25.9 {TextEditCmd procedure, reset modified flag} {
3039    catch {destroy .t}
3040    text .t
3041    pack .t
3042    .t insert end "line 1\n"
3043    .t edit modified 0
3044    .t edit modified
3045} {0}
3046test text-25.10 {TextEditCmd procedure, set modified flag} {
3047    catch {destroy .t}
3048    text .t
3049    pack .t
3050    .t edit modified 1
3051    .t edit modified
3052} {1}
3053test text-25.10.1 {TextEditCmd procedure, set modified flag repeat} {
3054    catch {destroy .t}
3055    text .t
3056    pack .t
3057    set ::retval {}
3058    bind .t <<Modified>> "lappend ::retval modified"
3059    # Shouldn't require [update idle] to trigger event [Bug 1809538]
3060    lappend ::retval [.t edit modified]
3061    .t edit modified 1
3062    update idletasks
3063    lappend ::retval [.t edit modified]
3064    .t edit modified 1 ; # binding should only fire once [Bug 1799782]
3065    update idletasks
3066    lappend ::retval [.t edit modified]
3067} {0 modified 1 1}
3068test text-25.11 {<<Modified>> virtual event} {
3069    set ::retval unmodified
3070    catch {destroy .t}
3071    text .t -undo 1
3072    pack .t
3073    bind .t <<Modified>> "set ::retval modified"
3074    update idletasks
3075    .t insert end "nothing special\n"
3076    set ::retval
3077} {modified}
3078test text-25.11.1 {<<Modified>> virtual event - insert before Modified} {
3079    set ::retval {}
3080    destroy .t
3081    pack [text .t -undo 1]
3082    bind .t <<Modified>> { set ::retval [.t get 1.0 end-1c] }
3083    update idletasks
3084    .t insert end "nothing special"
3085    set ::retval
3086} {nothing special}
3087test text-25.11.2 {<<Modified>> virtual event - delete before Modified} {
3088    # Bug 1737288, make sure we delete chars before triggering <<Modified>>
3089    set ::retval {}
3090    destroy .t
3091    pack [text .t -undo 1]
3092    bind .t <<Modified>> { set ::retval [.t get 1.0 end-1c] }
3093    .t insert end "nothing special"
3094    .t edit modified 0
3095    .t delete 1.0 1.2
3096    set ::retval
3097} {thing special}
3098test text-25.12 {<<Selection>> virtual event} {
3099    set ::retval no_selection
3100    catch {destroy .t}
3101    text .t -undo 1
3102    pack .t
3103    bind .t <<Selection>> "set ::retval selection_changed"
3104    update idletasks
3105    .t insert end "nothing special\n"
3106    .t tag add sel 1.0 1.1
3107    set ::retval
3108} {selection_changed}
3109test text-25.13 {-maxundo configuration option} {
3110    catch {destroy .t}
3111    text .t -undo 1  -autoseparators 1 -maxundo 2
3112    pack .t
3113    .t insert end "line 1\n"
3114    .t delete 1.4 1.6
3115    .t insert end "line 2\n"
3116    catch {.t edit undo}
3117    catch {.t edit undo}
3118    catch {.t edit undo}
3119    .t get 1.0 end
3120} "line 1\n\n"
3121test text-25.15 {bug fix 1536735 - undo with empty text} {
3122    catch {destroy .t}
3123    text .t -undo 1
3124    set r [.t edit modified]
3125    .t delete 1.0
3126    lappend r [.t edit modified]
3127    lappend r [catch {.t edit undo}]
3128    lappend r [.t edit modified]
3129} {0 0 1 0}
3130test text-25.18 {patch 1469210 - inserting after undo} -setup {
3131    destroy .t
3132} -body {
3133    text .t -undo 1
3134    .t insert end foo
3135    .t edit modified 0
3136    .t edit undo
3137    .t insert end bar
3138    .t edit modified
3139} -cleanup {
3140    destroy .t
3141} -result 1
3142
3143test text-26.1 {bug fix - 624372, ControlUtfProc long lines} {
3144    destroy .t
3145    pack [text .t -wrap none]
3146    .t insert end [string repeat "\1" 500]
3147} {}
3148
3149test text-27.1 {tabs - must be positive and must be increasing} {
3150    destroy .t
3151    pack [text .t -wrap none]
3152    list [catch {.t configure -tabs {0}} msg] $msg
3153} {1 {tab stop "0" is not at a positive distance}}
3154test text-27.2 {tabs - must be positive and must be increasing} {
3155    destroy .t
3156    pack [text .t -wrap none]
3157    list [catch {.t configure -tabs {-5}} msg] $msg
3158} {1 {tab stop "-5" is not at a positive distance}}
3159test text-27.3 {tabs - must be positive and must be increasing} {knownBug} {
3160    # This bug will be fixed in Tk 9.0, when we can allow a minor
3161    # incompatibility with Tk 8.x
3162    destroy .t
3163    pack [text .t -wrap none]
3164    list [catch {.t configure -tabs {10c 5c}} msg] $msg
3165} {1 {tabs must be monotonically increasing, but "5c" is smaller than or equal to the previous tab}}
3166test text-27.4 {tabs - must be positive and must be increasing} {
3167    destroy .t
3168    pack [text .t -wrap none]
3169    .t insert end "a\tb\tc\td\te"
3170    catch {.t configure -tabs {10c 5c}}
3171    update ; update ; update
3172    # This test must simply not go into an infinite loop to succeed
3173    set result 1
3174} {1}
3175
3176test text-28.0 {repeated insert and scroll} {
3177    foreach subcmd {
3178	{moveto 1}
3179	{scroll 1 pages}
3180	{scroll 100 pixels}
3181	{scroll 10 units}
3182    } {
3183	destroy .t
3184	pack [text .t]
3185	for {set i 0} {$i < 30} {incr i} {
3186	    .t insert end "blabla\n"
3187	    eval .t yview $subcmd
3188	}
3189    }
3190    # This test must simply not crash to succeed
3191    set result 1
3192} {1}
3193
3194test text-29.0 {peer widgets} {
3195    destroy .t .tt
3196    toplevel .tt
3197    pack [text .t]
3198    pack [.t peer create .tt.t]
3199    destroy .t .tt
3200} {}
3201test text-29.1 {peer widgets} {
3202    destroy .t .t1 .t2
3203    toplevel .t1
3204    toplevel .t2
3205    pack [text .t]
3206    pack [.t peer create .t1.t]
3207    pack [.t peer create .t2.t]
3208    .t insert end "abcd\nabcd"
3209    update
3210    destroy .t1
3211    update
3212    .t insert end "abcd\nabcd"
3213    update
3214    destroy .t .t2
3215    update
3216} {}
3217test text-29.2 {peer widgets} {
3218    destroy .t .t1 .t2
3219    toplevel .t1
3220    toplevel .t2
3221    pack [text .t]
3222    pack [.t peer create .t1.t]
3223    pack [.t peer create .t2.t]
3224    .t insert end "abcd\nabcd"
3225    update
3226    destroy .t
3227    update
3228    .t2.t insert end "abcd\nabcd"
3229    update
3230    destroy .t .t2
3231    update
3232} {}
3233test text-29.3 {peer widgets} {
3234    destroy .t .tt
3235    toplevel .tt
3236    pack [text .t]
3237    for {set i 1} {$i < 20} {incr i} {
3238	.t insert end "Line $i\n"
3239    }
3240    pack [.t peer create .tt.t -start 5 -end 11]
3241    update
3242    destroy .t .tt
3243} {}
3244test text-29.4 {peer widgets} {
3245    destroy .t .tt
3246    toplevel .tt
3247    pack [text .t]
3248    for {set i 1} {$i < 20} {incr i} {
3249	.t insert end "Line $i\n"
3250    }
3251    pack [.t peer create .tt.t -start 5 -end 11]
3252    pack [.tt.t peer create .tt.t2]
3253    set res [list [.tt.t index end] [.tt.t2 index end]]
3254    update
3255    destroy .t .tt
3256    set res
3257} {7.0 7.0}
3258test text-29.4.1 {peer widgets} {
3259    destroy .t .tt
3260    toplevel .tt
3261    pack [text .t]
3262    for {set i 1} {$i < 20} {incr i} {
3263	.t insert end "Line $i\n"
3264    }
3265    pack [.t peer create .tt.t -start 5 -end 11]
3266    pack [.tt.t peer create .tt.t2 -start {} -end {}]
3267    set res [list [.tt.t index end] [.tt.t2 index end]]
3268    update
3269    destroy .t .tt
3270    set res
3271} {7.0 21.0}
3272test text-29.5 {peer widgets} {
3273    destroy .t .tt
3274    toplevel .tt
3275    pack [text .t]
3276    for {set i 1} {$i < 20} {incr i} {
3277	.t insert end "Line $i\n"
3278    }
3279    pack [.t peer create .tt.t -start 5 -end 11]
3280    update ; update
3281    set p1 [.tt.t count -update -ypixels 1.0 end]
3282    set p2 [.t count -update -ypixels 5.0 11.0]
3283    if {$p1 == $p2} { 
3284	set res "ok" 
3285    } else {
3286        set res "$p1 and $p2 not equal"
3287    }
3288    destroy .t .tt
3289    set res
3290} {ok}
3291test text-29.6 {peer widgets} {
3292    destroy .t .tt
3293    toplevel .tt
3294    pack [text .t]
3295    for {set i 1} {$i < 20} {incr i} {
3296	.t insert end "Line $i\n"
3297    }
3298    pack [.t peer create .tt.t -start 5 -end 11]
3299    update ; update
3300    .t delete 3.0 6.0
3301    set res [.tt.t index end]
3302    destroy .t .tt
3303    set res
3304} {6.0}
3305test text-29.7 {peer widgets} {
3306    destroy .t .tt
3307    toplevel .tt
3308    pack [text .t]
3309    for {set i 1} {$i < 20} {incr i} {
3310	.t insert end "Line $i\n"
3311    }
3312    pack [.t peer create .tt.t -start 5 -end 11]
3313    update ; update
3314    .t delete 8.0 12.0
3315    set res [.tt.t index end]
3316    destroy .t .tt
3317    set res
3318} {4.0}
3319test text-29.8 {peer widgets} {
3320    destroy .t .tt
3321    toplevel .tt
3322    pack [text .t]
3323    for {set i 1} {$i < 20} {incr i} {
3324	.t insert end "Line $i\n"
3325    }
3326    pack [.t peer create .tt.t -start 5 -end 11]
3327    update ; update
3328    .t delete 3.0 13.0
3329    set res [.tt.t index end]
3330    destroy .t .tt
3331    set res
3332} {1.0}
3333test text-29.9 {peer widgets} {
3334    destroy .t
3335    pack [text .t]
3336    for {set i 1} {$i < 100} {incr i} {
3337	.t insert end "Line $i\n"
3338    }
3339    .t tag add sel 1.0 end-1c
3340    set res {}
3341    lappend res [.t tag ranges sel]
3342    .t configure -start 10 -end 20
3343    lappend res [.t tag ranges sel]
3344    destroy .t
3345    set res
3346} {{1.0 100.0} {1.0 11.0}}
3347test text-29.10 {peer widgets} {
3348    destroy .t
3349    pack [text .t]
3350    for {set i 1} {$i < 100} {incr i} {
3351	.t insert end "Line $i\n"
3352    }
3353    .t tag add sel 1.0 end-1c
3354    set res {}
3355    lappend res [.t tag ranges sel]
3356    .t configure -start 11
3357    lappend res [.t tag ranges sel]
3358    destroy .t
3359    set res
3360} {{1.0 100.0} {1.0 90.0}}
3361test text-29.11 {peer widgets} {
3362    destroy .t
3363    pack [text .t]
3364    for {set i 1} {$i < 100} {incr i} {
3365	.t insert end "Line $i\n"
3366    }
3367    .t tag add sel 1.0 end-1c
3368    set res {}
3369    lappend res [.t tag ranges sel]
3370    .t configure -end 90
3371    lappend res [.t tag ranges sel]
3372    destroy .t
3373    set res
3374} {{1.0 100.0} {1.0 90.0}}
3375test text-29.12 {peer widgets} {
3376    destroy .t
3377    pack [text .t]
3378    for {set i 1} {$i < 20} {incr i} {
3379	.t insert end "Line $i\n"
3380    }
3381    .t tag add sel 1.0 3.0 5.0 7.0 9.0 11.0 13.0 15.0 17.0 19.0 
3382    set res {}
3383    lappend res [.t tag prevrange sel 1.0]
3384    .t configure -start 6 -end 12
3385    lappend res [.t tag ranges sel]
3386    lappend res "next" [.t tag nextrange sel 4.0] \
3387      [.t tag nextrange sel 5.0] [.t tag nextrange sel 6.0] \
3388      [.t tag nextrange sel 7.0]
3389    lappend res "prev" [.t tag prevrange sel 1.0] \
3390      [.t tag prevrange sel 2.0] [.t tag prevrange sel 3.0] \
3391      [.t tag prevrange sel 4.0]
3392    destroy .t
3393    set res
3394} {{} {1.0 2.0 4.0 6.0} next {4.0 6.0} {} {} {} prev {} {1.0 2.0} {1.0 2.0} {1.0 2.0}}
3395test text-29.13 {peer widgets} {
3396    destroy .t
3397    pack [text .t]
3398    for {set i 1} {$i < 20} {incr i} {
3399	.t insert end "Line $i\n"
3400    }
3401    .t tag add sel 1.0 3.0 9.0 11.0 13.0 15.0 17.0 19.0 
3402    set res {}
3403    .t configure -start 6 -end 12
3404    lappend res [.t tag ranges sel]
3405    lappend res "next" [.t tag nextrange sel 4.0] \
3406      [.t tag nextrange sel 5.0] [.t tag nextrange sel 6.0] \
3407      [.t tag nextrange sel 7.0]
3408    lappend res "prev" [.t tag prevrange sel 1.0] \
3409      [.t tag prevrange sel 2.0] [.t tag prevrange sel 3.0] \
3410      [.t tag prevrange sel 4.0]
3411    destroy .t
3412    set res
3413} {{4.0 6.0} next {4.0 6.0} {} {} {} prev {} {} {} {}}
3414test text-29.14 {peer widgets} {
3415    destroy .t
3416    pack [text .t]
3417    for {set i 1} {$i < 20} {incr i} {
3418	.t insert end "Line $i\n"
3419    }
3420    .t tag add sel 1.0 7.0 9.0 11.0 13.0 15.0 17.0 19.0 
3421    set res {}
3422    .t configure -start 6 -end 12
3423    lappend res [.t tag ranges sel]
3424    lappend res "next" [.t tag nextrange sel 4.0] \
3425      [.t tag nextrange sel 5.0] [.t tag nextrange sel 6.0] \
3426      [.t tag nextrange sel 7.0]
3427    lappend res "prev" [.t tag prevrange sel 1.0] \
3428      [.t tag prevrange sel 2.0] [.t tag prevrange sel 3.0] \
3429      [.t tag prevrange sel 4.0]
3430    destroy .t
3431    set res
3432} {{1.0 2.0 4.0 6.0} next {4.0 6.0} {} {} {} prev {} {1.0 2.0} {1.0 2.0} {1.0 2.0}}
3433test text-29.15 {peer widgets} {
3434    destroy .t
3435    pack [text .t]
3436    for {set i 1} {$i < 20} {incr i} {
3437	.t insert end "Line $i\n"
3438    }
3439    set res {}
3440    .t tag add sel 1.0 11.0
3441    lappend res [.t tag ranges sel]
3442    lappend res [catch {.t configure -start 15 -end 10}]
3443    lappend res [.t tag ranges sel]
3444    .t configure -start 6 -end 12
3445    lappend res [.t tag ranges sel]
3446    .t configure -start {} -end {}
3447    lappend res [.t tag ranges sel]
3448    destroy .t
3449    set res
3450} {{1.0 11.0} 1 {1.0 11.0} {1.0 6.0} {1.0 11.0}}
3451test text-29.16 {peer widgets} {
3452    destroy .t
3453    pack [text .t]
3454    for {set i 1} {$i < 20} {incr i} {
3455	.t insert end "Line $i\n"
3456    }
3457    set res {}
3458    .t tag add sel 1.0 11.0
3459    lappend res [.t index sel.first]
3460    lappend res [.t index sel.last]
3461    destroy .t
3462    set res
3463} {1.0 11.0} 
3464test text-29.17 {peer widgets} {
3465    destroy .t
3466    pack [text .t]
3467    for {set i 1} {$i < 20} {incr i} {
3468	.t insert end "Line $i\n"
3469    }
3470    set res {}
3471    .t tag delete sel
3472    set res [list [catch {.t index sel.first} msg] $msg]
3473    destroy .t
3474    set res
3475} {1 {text doesn't contain any characters tagged with "sel"}} 
3476
3477proc makeText {} {
3478    set w .g
3479    set font "Times 11"
3480    destroy .g
3481    toplevel .g
3482    frame $w.f -highlightthickness 2 -borderwidth 2 -relief sunken
3483    set t $w.f.text
3484    text $t -yscrollcommand "$w.scroll set" -setgrid true -font $font -width 70 \
3485	    -height 35 -wrap word -highlightthickness 0 -borderwidth 0
3486    pack $t -expand  yes -fill both
3487    scrollbar $w.scroll -command "$t yview"
3488    pack $w.scroll -side right -fill y
3489    pack $w.f -expand yes -fill both
3490    $t tag configure center -justify center -spacing1 5m -spacing3 5m
3491    $t tag configure buttons -lmargin1 1c -lmargin2 1c -rmargin 1c \
3492	    -spacing1 3m -spacing2 0 -spacing3 0
3493    for {set i 0} {$i < 40} {incr i} {
3494	$t insert end "${i}word "
3495    }
3496    return $t
3497}
3498
3499test text-30.1 {line heights on creation} {
3500    set w [makeText]
3501    update ; after 1000 ; update
3502    set before [$w count -ypixels 1.0 2.0]
3503    $w insert 1.0 "a"
3504    update
3505    set after [$w count -ypixels 1.0 2.0]
3506    destroy .g
3507    if {$before != $after} {
3508	set res "Count changed: $before $after"
3509    } else {
3510        set res "ok"
3511    }
3512} {ok}
3513
3514destroy .t
3515text .t
3516test text-31.1 {TextWidgetCmd procedure, "peer" option} {
3517    list [catch {.t peer foo 1} msg] $msg
3518} {1 {bad peer option "foo": must be create or names}}
3519test text-31.2 {TextWidgetCmd procedure, "peer" option} {
3520    list [catch {.t peer names foo} msg] $msg
3521} {1 {wrong # args: should be ".t peer names"}}
3522test text-31.3 {TextWidgetCmd procedure, "peer" option} {
3523    list [catch {.t p names} msg] $msg
3524} {0 {}}
3525test text-31.4 {TextWidgetCmd procedure, "peer" option} {
3526    .t peer names
3527} {}
3528test text-31.5 {TextWidgetCmd procedure, "peer" option} {
3529    list [catch {.t peer create foo} msg] $msg
3530} {1 {bad window path name "foo"}}
3531test text-31.6 {TextWidgetCmd procedure, "peer" option} {
3532    .t peer create .t2
3533    set res {}
3534    lappend res [.t peer names]
3535    lappend res [.t2 peer names]
3536    destroy .t2
3537    lappend res [.t peer names]
3538} {.t2 .t {}}
3539test text-31.7 {peer widget -start, -end} {
3540    set res [list [catch {.t configure -start 10 -end 5} msg] $msg]
3541    .t configure -start {} -end {}
3542    set res
3543} {0 {}}
3544test text-31.8 {peer widget -start, -end} {
3545    .t delete 1.0 end
3546    for {set i 1} {$i < 100} {incr i} {
3547	.t insert end "Line $i\n"
3548    }
3549    list [catch {.t configure -start 10 -end 5} msg] $msg
3550} {1 {-startline must be less than or equal to -endline}}
3551test text-31.9 {peer widget -start, -end} {
3552    .t delete 1.0 end
3553    for {set i 1} {$i < 100} {incr i} {
3554	.t insert end "Line $i\n"
3555    }
3556    set res [list [catch {.t configure -start 5 -end 10} msg] $msg]
3557    .t configure -start {} -end {}
3558    set res
3559} {0 {}}
3560test text-31.10 {peer widget -start, -end} {
3561    .t delete 1.0 end
3562    for {set i 1} {$i < 100} {incr i} {
3563	.t insert end "Line $i\n"
3564    }
3565    set res [.t index end]
3566    lappend res [catch {.t configure -start 5 -end 10 -tab foo}]
3567    lappend res [.t index end]
3568    lappend res [catch {.t configure -tab foo -start 15 -end 20}]
3569    lappend res [.t index end]
3570    .t configure -start {} -end {}
3571    lappend res [.t index end]
3572    set res
3573} {101.0 1 101.0 1 101.0 101.0}
3574test text-31.11 {peer widget -start, -end} {
3575    .t delete 1.0 end
3576    for {set i 1} {$i < 100} {incr i} {
3577	.t insert end "Line $i\n"
3578    }
3579    set res [.t index end]
3580    lappend res [catch {.t configure -start 5 -end 15}]
3581    lappend res [.t index end]
3582    lappend res [catch {.t configure -start 10 -end 40}]
3583    lappend res [.t index end]
3584    .t configure -start {} -end {}
3585    lappend res [.t index end]
3586    set res
3587} {101.0 0 11.0 0 31.0 101.0}
3588
3589test text-32.1 {peer widget -start, -end and selection} {
3590    .t delete 1.0 end
3591    for {set i 1} {$i < 100} {incr i} {
3592	.t insert end "Line $i\n"
3593    }
3594    .t tag add sel 10.0 20.0
3595    set res {}
3596    lappend res [.t tag ranges sel]
3597    .t configure -start 5 -end 30
3598    lappend res [.t tag ranges sel]
3599    .t configure -start 5 -end 15
3600    lappend res [.t tag ranges sel]
3601    .t configure -start 15 -end 30
3602    lappend res [.t tag ranges sel]
3603    .t configure -start 15 -end 16
3604    lappend res [.t tag ranges sel]
3605    .t configure -start 25 -end 30
3606    lappend res [.t tag ranges sel]
3607    .t configure -start {} -end {}
3608    lappend res [.t tag ranges sel]
3609    set res
3610} {{10.0 20.0} {6.0 16.0} {6.0 11.0} {1.0 6.0} {1.0 2.0} {} {10.0 20.0}}
3611
3612test text-33.1 {widget dump -command alters tags} {
3613    .t delete 1.0 end
3614    .t insert end "abc\n" a "---" {} "def" b "   \n" {} "ghi\n" c
3615    .t tag configure b -background red
3616    proc Dumpy {key value index} {
3617      #puts "KK: $key, $value"
3618      .t tag add $value [list $index linestart] [list $index lineend]
3619    }
3620    .t dump -all -command Dumpy 1.0 end
3621    set result "ok"
3622} {ok}
3623test text-33.2 {widget dump -command makes massive changes} {
3624    .t delete 1.0 end
3625    .t insert end "abc\n" a "---" {} "def" b "   \n" {} "ghi\n" c
3626    .t tag configure b -background red
3627    proc Dumpy {key value index} {
3628      #puts "KK: $key, $value"
3629      .t delete 1.0 end
3630    }
3631    .t dump -all -command Dumpy 1.0 end
3632    set result "ok"
3633} {ok}
3634test text-33.3 {widget dump -command destroys widget} {
3635    .t delete 1.0 end
3636    .t insert end "abc\n" a "---" {} "def" b "   \n" {} "ghi\n" c
3637    .t tag configure b -background red
3638    proc Dumpy {key value index} {
3639      #puts "KK: $key, $value"
3640      destroy .t
3641    }
3642    .t dump -all -command Dumpy 1.0 end
3643    set result "ok"
3644} {ok}
3645
3646deleteWindows
3647option clear
3648
3649test text-36.1 "bug #1777362: event handling with hyphenated windows" -setup {
3650    proc bgerror {m} {set ::my_error $m}
3651    set ::my_error {}
3652    pack [set w [text .t-1]]
3653} -body {
3654    tkwait visibility $w
3655    event generate $w <1>
3656    event generate $w <1>
3657    update
3658    set ::my_error
3659} -cleanup {
3660    destroy .t-1
3661} -result {}
3662
3663test text-36.2 "bug #1777362: event handling with hyphenated windows" -setup {
3664    proc bgerror {m} {set ::my_error $m}
3665    set ::my_error {}
3666    pack [set w [text .t+1]]
3667} -body {
3668    tkwait visibility $w
3669    event generate $w <1>
3670    event generate $w <1>
3671    update
3672    set ::my_error
3673} -cleanup {
3674    destroy $w
3675} -result {}
3676
3677test text-36.3 "bug #1777362: event handling with hyphenated windows" -setup {
3678    proc bgerror {m} {set ::my_error $m}
3679    set ::my_error {}
3680    pack [set w [text .t*1]]
3681} -body {
3682    tkwait visibility $w
3683    event generate $w <1>
3684    event generate $w <1>
3685    update
3686    set ::my_error
3687} -cleanup {
3688    destroy $w
3689} -result {}
3690
3691# cleanup
3692cleanupTests
3693return
3694