summaryrefslogtreecommitdiffstats
path: root/tests/textBTree.test
blob: ebd6c5079a7bd8a66b2f8e734dc74ce4173d6906 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
# This file is a Tcl script to test out the B-tree facilities of
# Tk's text widget (the contents of the file "tkTextBTree.c".  There are
# several file with additional tests for other features of text widgets.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

proc setup {} {
    .t delete 1.0 100000.0
    .t tag delete x y
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 1.1
    .t tag add x 1.5 1.13
    .t tag add x 2.2 2.6
    .t tag add y 1.5
}

# setup procedure for tests 10.*, 11.*, 12.*
proc msetup {} {
    .t delete 1.0 100000.0
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t mark set m1 1.2
    .t mark set l1 1.2
    .t mark gravity l1 left
    .t mark set next 1.6
    .t mark set x 1.6
    .t mark set m2 2.0
    .t mark set m3 2.100
    .t tag add x 1.3 1.8
}

# setup procedure for tests 16.*, 17.*, 18.9
proc setupBig {} {
    .t delete 1.0 end
    .t tag delete x y
    .t tag configure x -foreground blue
    .t tag configure y -underline true
    # Create a Btree with 2002 lines (2000 + already existing + phantom at end)
    # This generates a level 3 node with 9 children
    # Most level 2 nodes cover 216 lines and have 6 children, except the last
    # level 2 node covers 274 lines and has 7 children.
    # Most level 1 nodes cover 36 lines and have 6 children, except the
    # rightmost node has 58 lines and 9 children.
    # Level 2: 2002 = 8*216 + 274
    # Level 1: 2002 = 54*36 + 58
    # Level 0: 2002 = 332*6 + 10
    for {set i 0} {$i < 2000} {incr i} {
        append x "Line $i abcd efgh ijkl\n"
    }
    .t insert insert $x
    .t debug 1
}

# Widget used in tests 1.* - 13.*
destroy .t
text .t
.t debug on

test btree-1.1 {basic insertions} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nLine 3\n"
test btree-1.2 {basic insertions} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t insert 1.3 XXX
    .t get 1.0 1000000.0
} -result "LinXXXe 1\nLine 2\nLine 3\n"
test btree-1.3 {basic insertions} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t insert 3.0 YYY
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nYYYLine 3\n"
test btree-1.4 {basic insertions} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t insert 2.1 X\nYY
    .t get 1.0 1000000.0
} -result "Line 1\nLX\nYYine 2\nLine 3\n"
test btree-1.5 {basic insertions} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t insert 2.0 X\n\n\n
    .t get 1.0 1000000.0
} -result "Line 1\nX\n\n\nLine 2\nLine 3\n"
test btree-1.6 {basic insertions} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t insert 2.6 X\n
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2X\n\nLine 3\n"
test btree-1.7 {insertion before start of text} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t insert 0.4 XXX
    .t get 1.0 1000000.0
} -result "XXXLine 1\nLine 2\nLine 3\n"
test btree-1.8 {insertion past end of text} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t insert 100.0 ZZ
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nLine 3ZZ\n"
test btree-1.9 {insertion before start of line} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t insert 2.-3 Q
    .t get 1.0 1000000.0
} -result "Line 1\nQLine 2\nLine 3\n"
test btree-1.10 {insertion past end of line} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t insert 2.40 XYZZY
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2XYZZY\nLine 3\n"
test btree-1.11 {insertion past end of last line} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t insert 3.40 ABC
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nLine 3ABC\n"


test btree-2.1 {basic deletions} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 1.0 1.3
    .t get 1.0 1000000.0
} -result "e 1\nLine 2\nLine 3\n"
test btree-2.2 {basic deletions} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 2.2
    .t get 1.0 1000000.0
} -result "Line 1\nLie 2\nLine 3\n"
test btree-2.3 {basic deletions} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 2.0 2.3
    .t get 1.0 1000000.0
} -result "Line 1\ne 2\nLine 3\n"
test btree-2.4 {deleting whole lines} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 1.2 3.0
    .t get 1.0 1000000.0
} -result "LiLine 3\n"
test btree-2.5 {deleting whole lines} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\n\n\nLine 5"
    .t delete 1.0 5.2
    .t get 1.0 1000000.0
} -result "ne 5\n"
test btree-2.6 {deleting before start of file} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 0.3 1.2
    .t get 1.0 1000000.0
} -result "ne 1\nLine 2\nLine 3\n"
test btree-2.7 {deleting after end of file} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 10.3
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nLine 3\n"
test btree-2.8 {deleting before start of line} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 3.-1 3.3
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\ne 3\n"
test btree-2.9 {deleting before start of line} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 1.-1 1.0
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nLine 3\n"
test btree-2.10 {deleting after end of line} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 1.8 2.1
    .t get 1.0 1000000.0
} -result "Line 1ine 2\nLine 3\n"
test btree-2.11 {deleting after end of last line} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 3.8 4.1
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nLine 3\n"
test btree-2.12 {deleting before start of file} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 1.8 0.0
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nLine 3\n"
test btree-2.13 {deleting past end of file} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 1.8 4.0
    .t get 1.0 1000000.0
} -result "Line 1\n"
test btree-2.14 {deleting with end before start of line} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 1.3 2.-3
    .t get 1.0 1000000.0
} -result "LinLine 2\nLine 3\n"
test btree-2.15 {deleting past end of line} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 1.3 1.9
    .t get 1.0 1000000.0
} -result "Lin\nLine 2\nLine 3\n"
test btree-2.16 {deleting past end of line} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 3.2 3.15
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nLi\n"
test btree-2.17 {deleting past end of line} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 3.0 3.15
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\n\n"
test btree-2.18 {deleting past end of line} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 1.0 3.15
    .t get 1.0 1000000.0
} -result "\n"
test btree-2.19 {deleting with negative range} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 3.2 2.4
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nLine 3\n"
test btree-2.20 {deleting with negative range} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 3.2 3.1
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nLine 3\n"
test btree-2.21 {deleting with negative range} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 3.2 3.2
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nLine 3\n"


test btree-3.1 {inserting with tags} -body {
    setup
    .t insert 1.0 XXX
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.4 1.5 1.8 1.16 2.2 2.6} {1.8 1.9}}
test btree-3.2 {inserting with tags} -body {
    setup
    .t insert 1.15 YYY
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.1 1.2 1.5 1.13 2.2 2.6} {1.5 1.6}}
test btree-3.3 {inserting with tags} -body {
    setup
    .t insert 1.7 ZZZZ
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.1 1.2 1.5 1.17 2.2 2.6} {1.5 1.6}}
test btree-3.4 {inserting with tags} -body {
    setup
    .t insert 1.7 \n\n
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.1 1.2 1.5 3.6 4.2 4.6} {1.5 1.6}}
test btree-3.5 {inserting with tags} -body {
    setup
    .t insert 1.5 A\n
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.1 1.2 2.0 2.8 3.2 3.6} {2.0 2.1}}
test btree-3.6 {inserting with tags} -body {
    setup
    .t insert 1.13 A\n
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.1 1.2 1.5 1.13 3.2 3.6} {1.5 1.6}}


test btree-4.1 {deleting with tags} -body {
    setup
    .t delete 1.6 1.9
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.1 1.2 1.5 1.10 2.2 2.6} {1.5 1.6}}
test btree-4.2 {deleting with tags} -body {
    setup
    .t delete 1.1 2.3
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.1 1.4} {}}
test btree-4.3 {deleting with tags} -body {
    setup
    .t delete 1.4 2.1
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.1 1.2 1.5 1.9} {}}
test btree-4.4 {deleting with tags} -body {
    setup
    .t delete 1.14 2.1
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.1 1.2 1.5 1.13 1.15 1.19} {1.5 1.6}}
test btree-4.5 {deleting with tags} -body {
    setup
    .t delete 1.0 2.10
    list [.t tag ranges x] [.t tag ranges y]
} -result {{} {}}
test btree-4.6 {deleting with tags} -body {
    setup
    .t delete 1.0 1.5
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.0 1.8 2.2 2.6} {1.0 1.1}}
test btree-4.7 {deleting with tags} -body {
    setup
    .t delete 1.6 1.9
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.1 1.2 1.5 1.10 2.2 2.6} {1.5 1.6}}
test btree-4.8 {deleting with tags} -body {
    setup
    .t delete 1.5 1.13
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.1 1.2 2.2 2.6} {}}


test btree-5.1 {very large inserts, with tags} -setup {
    set bigText1 {}
    for {set i 0} {$i < 10} {incr i} {
        append bigText1 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.0 $bigText1
    list [.t tag ranges x] [.t tag ranges y]
} -result {{11.1 11.2 11.5 11.13 12.2 12.6} {11.5 11.6}}
test btree-5.2 {very large inserts, with tags} -setup {
    set bigText2 {}
    for {set i 0} {$i < 200} {incr i} {
        append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.2 $bigText2
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.1 1.2 201.3 201.11 202.2 202.6} {201.3 201.4}}
test btree-5.3 {very large inserts, with tags} -body {
    setup
    for {set i 0} {$i < 200} {incr i} {
        .t insert 1.8 "longer line $i\n"
    }
    list [.t tag ranges x] [.t tag ranges y] [.t get 1.0 1.100] \
        [.t get 198.0 198.100]
} -result {{1.1 1.2 1.5 201.5 202.2 202.6} {1.5 1.6} {Text forlonger line 199} {longer line 2}}


test btree-6.1 {very large deletes, with tags}  -setup {
    set bigText2 {}
    for {set i 0} {$i < 200} {incr i} {
        append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.1 $bigText2
    .t delete 1.2 201.2
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.4 1.12 2.2 2.6} {1.4 1.5}}
test btree-6.2 {very large deletes, with tags}  -setup {
    set bigText2 {}
    for {set i 0} {$i < 200} {incr i} {
        append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.1 $bigText2
    for {set i 0} {$i < 200} {incr i} {
        .t delete 1.2 2.2
    }
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.4 1.12 2.2 2.6} {1.4 1.5}}
test btree-6.3 {very large deletes, with tags}  -setup {
    set bigText2 {}
     for {set i 0} {$i < 200} {incr i} {
            append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.1 $bigText2
    .t delete 2.3 10000.0
    .t get 1.0 1000.0
} -result {TLine 0
Lin
}
test btree-6.4 {very large deletes, with tags} -setup {
    set bigText2 {}
    for {set i 0} {$i < 200} {incr i} {
        append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.1 $bigText2
    for {set i 0} {$i < 100} {incr i} {
        .t delete 30.0 31.0
    }
    list [.t tag ranges x] [.t tag ranges y]
} -result {{101.0 101.1 101.4 101.12 102.2 102.6} {101.4 101.5}}
test btree-6.5 {very large deletes, with tags} -setup {
    set bigText2 {}
    for {set i 0} {$i < 200} {incr i} {
        append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.1 $bigText2
    for {set i 0} {$i < 100} {incr i} {
        set j [expr $i+2]
        set k [expr 1+2*$i]
        .t tag add x $j.1 $j.3
        .t tag add y $k.1 $k.6
    }
    .t delete 2.0 200.0
    list [.t tag ranges x] [.t tag ranges y]
} -result {{3.0 3.1 3.4 3.12 4.2 4.6} {1.1 1.6 3.4 3.5}}
test btree-6.6 {very large deletes, with tags} -setup {
    set bigText2 {}
    for {set i 0} {$i < 200} {incr i} {
        append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.1 $bigText2
    for {set i 0} {$i < 100} {incr i} {
        set j [expr $i+2]
        set k [expr 1+2*$i]
        .t tag add x $j.1 $j.3
        .t tag add y $k.1 $k.6
    }
    for {set i 199} {$i >= 2} {incr i -1} {
        .t delete $i.0 [expr $i+1].0
    }
    list [.t tag ranges x] [.t tag ranges y]
} -result {{3.0 3.1 3.4 3.12 4.2 4.6} {1.1 1.6 3.4 3.5}}


test btree-7.1 {tag addition and removal} -setup {
    .t delete 1.0 end
    .t tag remove x 1.0 end
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    set check {1.3 1.6 1.7 2.0}
    while {[llength $check]} {
        .t tag add x [lindex $check 0] [lindex $check 1]
        set check [lrange $check 2 end]
    }
    .t tag ranges x
} -result {1.3 1.6 1.7 2.0}
test btree-7.2 {tag addition and removal} -setup {
    .t delete 1.0 end
    .t tag remove x 1.0 end
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    set check {1.3 1.6 1.6 2.0}
    while {[llength $check]} {
        .t tag add x [lindex $check 0] [lindex $check 1]
        set check [lrange $check 2 end]
    }
    .t tag ranges x
} -result {1.3 2.0}
test btree-7.3 {tag addition and removal} -setup {
    .t delete 1.0 end
    .t tag remove x 1.0 end
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    set check {1.3 1.6 1.4 2.0}
    while {[llength $check]} {
        .t tag add x [lindex $check 0] [lindex $check 1]
        set check [lrange $check 2 end]
    }
    .t tag ranges x
} -result {1.3 2.0}
test btree-7.4 {tag addition and removal} -setup {
    .t delete 1.0 end
    .t tag remove x 1.0 end
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    set check {2.0 4.3 1.4 1.10}
    while {[llength $check]} {
        .t tag add x [lindex $check 0] [lindex $check 1]
        set check [lrange $check 2 end]
    }
    .t tag ranges x
} -result {1.4 1.10 2.0 4.3}
test btree-7.5 {tag addition and removal} -setup {
    .t delete 1.0 end
    .t tag remove x 1.0 end
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    set check {2.0 4.3 1.4 1.end}
    while {[llength $check]} {
        .t tag add x [lindex $check 0] [lindex $check 1]
        set check [lrange $check 2 end]
    }
    .t tag ranges x
} -result {1.4 1.19 2.0 4.3}
test btree-7.6 {tag addition and removal} -setup {
    .t delete 1.0 end
    .t tag remove x 1.0 end
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    set check {2.0 4.3 1.4 2.0}
    while {[llength $check]} {
        .t tag add x [lindex $check 0] [lindex $check 1]
        set check [lrange $check 2 end]
    }
    .t tag ranges x
} -result {1.4 4.3}
test btree-7.7 {tag addition and removal} -setup {
    .t delete 1.0 end
    .t tag remove x 1.0 end
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    set check {2.0 4.3 1.4 3.0}
    while {[llength $check]} {
        .t tag add x [lindex $check 0] [lindex $check 1]
        set check [lrange $check 2 end]
    }
    .t tag ranges x
} -result {1.4 4.3}
test btree-7.8 {tag addition and removal} -setup {
    .t delete 1.0 end
    .t tag remove x 1.0 end
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    set check {1.2 1.3 1.6 1.7 1.end 2.0 2.4 2.7 3.0 4.0 1.1 4.2}
    while {[llength $check]} {
        .t tag add x [lindex $check 0] [lindex $check 1]
        set check [lrange $check 2 end]
    }
    .t tag ranges x
} -result {1.1 4.2}
test btree-7.9 {tag addition and removal} -setup {
    .t delete 1.0 end
    .t tag remove x 1.0 end
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    set check {1.2 1.3 1.6 1.7 1.end 2.0 2.4 2.7 3.0 4.0 1.3 4.2}
    while {[llength $check]} {
        .t tag add x [lindex $check 0] [lindex $check 1]
        set check [lrange $check 2 end]
    }
    .t tag ranges x
} -result {1.2 4.2}
test btree-7.10 {tag addition and removal} -setup {
    .t delete 1.0 end
    .t tag remove x 1.0 end
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    set check {1.2 1.3 1.6 1.7 1.end 2.0 2.4 2.7 3.0 4.0 1.1 3.0}
    while {[llength $check]} {
        .t tag add x [lindex $check 0] [lindex $check 1]
        set check [lrange $check 2 end]
    }
    .t tag ranges x
} -result {1.1 4.0}
test btree-7.11 {tag addition and removal} -setup {
    .t delete 1.0 end
    .t tag remove x 1.0 end
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    set check {1.2 1.3 1.6 1.7 1.end 2.0 2.4 2.7 3.0 4.0 1.2 3.0}
    while {[llength $check]} {
        .t tag add x [lindex $check 0] [lindex $check 1]
        set check [lrange $check 2 end]
    }
    .t tag ranges x
} -result {1.2 4.0}


test btree-8.1 {tag addition and removal, weird ranges} -body {
    .t delete 1.0 100000.0
    .t tag delete x
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 0.0 1.3
    .t tag ranges x
} -result {1.0 1.3}
test btree-8.2 {tag addition and removal, weird ranges} -body {
    .t delete 1.0 100000.0
    .t tag delete x
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 1.40 2.4
    .t tag ranges x
} -result {1.19 2.4}
test btree-8.3 {tag addition and removal, weird ranges} -body {
    .t delete 1.0 100000.0
    .t tag delete x
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 4.40 4.41
    .t tag ranges x
} -result {}
test btree-8.4 {tag addition and removal, weird ranges} -body {
    .t delete 1.0 100000.0
    .t tag delete x
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 5.1 5.2
    .t tag ranges x
} -result {}
test btree-8.5 {tag addition and removal, weird ranges} -body {
    .t delete 1.0 100000.0
    .t tag delete x
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 1.1 9.0
    .t tag ranges x
} -result {1.1 5.0}
test btree-8.6 {tag addition and removal, weird ranges} -body {
    .t delete 1.0 100000.0
    .t tag delete x
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 1.1 1.90
    .t tag ranges x
} -result {1.1 1.19}
test btree-8.7 {tag addition and removal, weird ranges} -body {
    .t delete 1.0 100000.0
    .t tag delete x
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 1.1 4.90
    .t tag ranges x
} -result {1.1 4.17}
test btree-8.8 {tag addition and removal, weird ranges} -body {
    .t delete 1.0 100000.0
    .t tag delete x
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 3.0 3.0
    .t tag ranges x
} -result {}


test btree-9.1 {tag names} -body {
    setup
    .t tag names
} -result {sel x y}
test btree-9.2 {tag names} -body {
    setup
    .t tag add tag1 1.8
    .t tag add tag2 1.8
    .t tag add tag3 1.7 1.9
    .t tag names 1.8
} -result {x tag1 tag2 tag3}
test btree-9.3 {lots of tag names} -setup {
    set bigText2 {}
    for {set i 0} {$i < 200} {incr i} {
        append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.2 $bigText2
    foreach i {tag1 foo ThisOne {x space} q r s t} {
    .t tag add $i 150.2
    }
    foreach i {u tagA tagB tagC and more {$} \{} {
    .t tag add $i 150.1 150.3
    }
    .t tag names 150.2
} -result {tag1 foo ThisOne {x space} q r s t u tagA tagB tagC and more {$} \{}
test btree-9.4 {lots of tag names} -setup {
    set bigText2 {}
    for {set i 0} {$i < 200} {incr i} {
        append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.2 $bigText2
    .t tag delete tag1 foo ThisOne more {x space} q r s t u
    .t tag delete tagA tagB tagC and {$} \{ more
    foreach i {tag1 foo ThisOne more {x space} q r s t} {
    .t tag add $i 150.2
    }
    foreach i {foo ThisOne u tagA tagB tagC and more {$} \{} {
    .t tag add $i 150.4
    }
    .t tag delete tag1 more q r tagA
    .t tag names 150.2
} -result {foo ThisOne {x space} s t}


test btree-10.1 {basic mark facilities} -body {
    msetup
    list [lsort [.t mark names]] [.t index m1] [.t index m2] [.t index m3]
} -result {{current insert l1 m1 m2 m3 next x} 1.2 2.0 2.11}
test btree-10.2 {basic mark facilities} -body {
    msetup
    .t mark unset m2
    lsort [.t mark names]
} -result {current insert l1 m1 m3 next x}
test btree-10.3 {basic mark facilities} -body {
    msetup
    .t mark set m2 1.8
    list [lsort [.t mark names]] [.t index m1] [.t index m2] [.t index m3]
} -result {{current insert l1 m1 m2 m3 next x} 1.2 1.8 2.11}


test btree-11.1 {marks and inserts} -body {
    msetup
    .t insert 1.1 abcde
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {1.7 1.7 1.11 1.11 2.0 2.11}
test btree-11.2 {marks and inserts} -body {
    msetup
    .t insert 1.2 abcde
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {1.2 1.7 1.11 1.11 2.0 2.11}
test btree-11.3 {marks and inserts} -body {
    msetup
    .t insert 1.3 abcde
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {1.2 1.2 1.11 1.11 2.0 2.11}
test btree-11.4 {marks and inserts} -body {
    msetup
    .t insert 1.1 ab\n\ncde
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {3.4 3.4 3.8 3.8 4.0 4.11}
test btree-11.5 {marks and inserts} -body {
    msetup
    .t insert 1.4 ab\n\ncde
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {1.2 1.2 3.5 3.5 4.0 4.11}
test btree-11.6 {marks and inserts} -body {
    msetup
    .t insert 1.7 ab\n\ncde
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {1.2 1.2 1.6 1.6 4.0 4.11}


test btree-12.1 {marks and deletes} -body {
    msetup
    .t delete 1.3 1.5
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {1.2 1.2 1.4 1.4 2.0 2.11}
test btree-12.2 {marks and deletes} -body {
    msetup
    .t delete 1.3 1.8
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {1.2 1.2 1.3 1.3 2.0 2.11}
test btree-12.3 {marks and deletes} -body {
    msetup
    .t delete 1.2 1.8
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {1.2 1.2 1.2 1.2 2.0 2.11}
test btree-12.4 {marks and deletes} -body {
    msetup
    .t delete 1.1 1.8
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {1.1 1.1 1.1 1.1 2.0 2.11}
test btree-12.5 {marks and deletes} -body {
    msetup
    .t delete 1.5 3.1
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {1.2 1.2 1.5 1.5 1.5 1.5}
test btree-12.6 {marks and deletes} -body {
    msetup
    .t mark set m2 4.5
    .t delete 1.5 4.1
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {1.2 1.2 1.5 1.5 1.9 1.5}
test btree-12.7 {marks and deletes} -body {
    msetup
    .t mark set m2 4.5
    .t mark set m3 4.5
    .t mark set m1 4.7
    .t delete 1.5 4.1
    list [.t index l1] [.t index m1] [.t index next] [.t index x] [.t index m2] [.t index m3]
} -result {1.2 1.11 1.5 1.5 1.9 1.9}


test btree-13.1 {tag searching} -setup {
    .t delete 1.0 100000.0
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag next x 2.2 2.1
} -result {}
test btree-13.2 {tag searching} -setup {
    .t delete 1.0 100000.0
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 2.2 2.4
    .t tag next x 2.2 2.3
} -result {2.2 2.4}
test btree-13.3 {tag searching} -setup {
    .t delete 1.0 100000.0
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 2.2 2.4
    .t tag next x 2.3 2.6
} -result {}
test btree-13.4 {tag searching} -setup {
    .t delete 1.0 100000.0
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 2.5 2.8
    .t tag next x 2.1 2.6
} -result {2.5 2.8}
test btree-13.5 {tag searching} -setup {
    .t delete 1.0 100000.0
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 2.5 2.8
    .t tag next x 2.1 2.5
} -result {}
test btree-13.6 {tag searching} -setup {
    .t delete 1.0 100000.0
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 2.1 2.4
    .t tag next x 2.5 2.8
} -result {}
test btree-13.7 {tag searching} -setup {
    .t delete 1.0 100000.0
} -body {
    .t insert 1.0 "Text for first line\nSecond line\n\nLast line of info"
    .t tag add x 2.5 2.8
    .t tag next x 2.1 2.4
} -result {}
test btree-13.8 {tag searching} -setup {
    set bigText2 {}
    for {set i 0} {$i < 200} {incr i} {
        append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.2 $bigText2
    .t tag add x 190.3 191.2
    .t tag next x 3.5
} -result {190.3 191.2}
destroy .t


test btree-14.1 {check tag presence} -setup {
    destroy .t
    text .t
    set bigText2 {}
    for {set i 0} {$i < 200} {incr i} {
        append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.2 $bigText2
    .t tag add x 3.5 3.7
    .t tag add y 133.9 141.5
    .t tag add z 1.5 180.2
    .t tag add q 141.4 142.3
    .t tag add x 130.2 145.1
    .t tag add a 141.0
    .t tag add b 4.3
    .t tag add b 7.5
    .t tag add b 140.3
    for {set i 120} {$i < 160} {incr i} {
    .t tag add c $i.4
    }
    foreach i {a1 a2 a3 a4 a5 a6 a7 a8 a9 10 a11 a12 a13} {
    .t tag add $i 122.2
    }
    .t tag add x 141.3
    .t tag names 141.1
} -cleanup {
    destroy .t
} -result {x y z}
test btree-14.2 {TkTextIsElided} -setup {
    destroy .t
    text .t
} -body {
    .t delete 1.0 end
    .t tag config hidden -elide 1
    .t insert end "Line1\nLine2\nLine3\n"
    .t tag add hidden 2.0 3.0
    .t tag add sel 1.2 3.2
    # next line used to panic because of "Bad tag priority being toggled on"
    # (see bug [382da038c9])
    .t index "2.0 - 1 display line linestart"
} -cleanup {
    destroy .t
} -result {1.0}

test btree-15.1 {rebalance with empty node} -setup {
    destroy .t
} -body {
    text .t
    .t debug 1
    .t insert end "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23"
    .t delete 6.0 12.0
    .t get 1.0 end
} -cleanup {
    destroy .t
} -result "1\n2\n3\n4\n5\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n"


test btree-16.1 {add tag does not push root above level 0} -setup {
    destroy .t
    text .t
} -body {
    setupBig
    .t debug 0
    .t tag add x 1.1 1.10
    .t tag add x 5.1 5.10
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {1.1 1.10 5.1 5.10}
test btree-16.2 {add tag pushes root up to level 1 node} -setup {
    destroy .t
    text .t
} -body {
    setupBig
    .t tag add x 1.1 1.10
    .t tag add x 8.1 8.10
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {1.1 1.10 8.1 8.10}
test btree-16.3 {add tag pushes root up to level 2 node} -setup {
    destroy .t
    text .t
} -body {
    setupBig
    .t tag add x 8.1 9.10
    .t tag add x 180.1 180.end
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {8.1 9.10 180.1 180.23}
test btree-16.4 {add tag pushes root up to level 3 node} -setup {
    destroy .t
    text .t
} -body {
    setupBig
    .t tag add y 1.1 2000.0
    .t tag add x 1.1 8.10
    .t tag add x 180.end 217.0
    list [.t tag ranges x] [.t tag ranges y]
} -cleanup {
    destroy .t
} -result {{1.1 8.10 180.23 217.0} {1.1 2000.0}}
test btree-16.5 {add tag doesn't push root up} -setup {
    destroy .t
    text .t
} -body {
    setupBig
    .t tag add x 1.1 8.10
    .t tag add x 2000.0 2000.3
    .t tag add x 180.end 217.0
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {1.1 8.10 180.23 217.0 2000.0 2000.3}
test btree-16.6 {two node splits at once pushes root up} -setup {
    destroy .t
    text .t
} -body {
    for {set i 1} {$i < 10} {incr i} {
        .t insert end "Line $i\n"
    }
    .t tag add x 8.0 8.end
    .t tag add y 9.0 end
    set x {}
    for {} {$i < 50} {incr i} {
        append x "Line $i\n"
    }
    .t insert end $x y
    list [.t tag ranges x] [.t tag ranges y]
} -cleanup {
    destroy .t
} -result {{8.0 8.6} {9.0 51.0}}
# The following find bugs in the SearchStart procedures
test btree-16.7 {Partial tag remove from before first range} -setup {
    destroy .t
    text .t
    for {set i 1} {$i < 10} {incr i} {
        .t insert end "Line $i\n"
    }
} -body {
    .t tag add x 2.0 2.6
    .t tag remove x 1.0 2.0
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {2.0 2.6}
test btree-16.8 {Partial tag remove from before first range} -setup {
    destroy .t
    text .t
    for {set i 1} {$i < 10} {incr i} {
        .t insert end "Line $i\n"
    }
} -body {
    .t tag add x 2.0 2.6
    .t tag remove x 1.0 2.1
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {2.1 2.6}
test btree-16.9 {Partial tag remove from before first range} -setup {
    destroy .t
    text .t
    for {set i 1} {$i < 10} {incr i} {
        .t insert end "Line $i\n"
    }
} -body {
    .t tag add x 2.0 2.6
    .t tag remove x 1.0 2.3
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {2.3 2.6}
test btree-16.10 {Partial tag remove from before first range} -setup {
    destroy .t
    text .t
    for {set i 1} {$i < 10} {incr i} {
        .t insert end "Line $i\n"
    }
} -body {
    .t tag add x 1.0 2.6
    .t tag remove x 1.0 2.5
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {2.5 2.6}
test btree-16.11 {StartSearchBack boundary case} -setup {
    destroy .t
    text .t
    for {set i 1} {$i < 10} {incr i} {
        .t insert end "Line $i\n"
    }
} -body {
    .t tag add x 1.3 1.4
    .t tag prevr x 2.0 1.4
} -cleanup {
    destroy .t
} -result {}
test btree-16.12 {StartSearchBack boundary case} -setup {
    destroy .t
    text .t
    for {set i 1} {$i < 10} {incr i} {
        .t insert end "Line $i\n"
    }
} -body {
    .t tag add x 1.3 1.4
    .t tag prevr x 2.0 1.3
} -cleanup {
    destroy .t
} -result {1.3 1.4}
test btree-16.13 {StartSearchBack boundary case} -setup {
    destroy .t
    text .t
    for {set i 1} {$i < 10} {incr i} {
        .t insert end "Line $i\n"
    }
} -body {
    .t tag add x 1.0 1.4
    .t tag prevr x 1.3
} -cleanup {
    destroy .t
} -result {1.0 1.4}


test btree-17.1 {remove tag does not push root down} -setup {
    destroy .t
    text .t
} -body {
    .t debug 0
    setupBig
    .t tag add x 1.1 5.10
    .t tag remove x 3.1 5.end
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {1.1 3.1}
test btree-17.2 {remove tag pushes root from level 1 to level 0} -setup {
    destroy .t
    text .t
} -body {
    setupBig
    .t tag add x 1.1 8.10
    .t tag remove x 3.1 end
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {1.1 3.1}
test btree-17.3 {remove tag pushes root from level 2 to level 1} -setup {
    destroy .t
    text .t
} -body {
    setupBig
    .t tag add x 1.1 180.10
    .t tag remove x 35.1 end
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {1.1 35.1}
test btree-17.4 {remove tag doesn't change level 2} -setup {
    destroy .t
    text .t
} -body {
    setupBig
    .t tag add x 1.1 180.10
    .t tag remove x 35.1 180.0
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {1.1 35.1 180.0 180.10}
test btree-17.5 {remove tag pushes root from level 3 to level 0} -setup {
    destroy .t
    text .t
} -body {
    setupBig
    .t tag add x 1.1 1.10
    .t tag add x 2000.1 2000.10
    .t tag remove x 1.0 2000.0
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {2000.1 2000.10}
test btree-17.6 {text deletion pushes root from level 3 to level 0} -setup {
    destroy .t
    text .t
} -body {
    setupBig
    .t tag add x 1.1 1.10
    .t tag add x 2000.1 2000.10
    .t delete 1.0 "1000.0 lineend +1 char"
    .t tag ranges x
} -cleanup {
    destroy .t
} -result {1000.1 1000.10}


test btree-18.1 {tag search back, no tag} -setup {
    destroy .t
    text .t
} -body {
    .t insert 1.0 "Line 1 abcd efgh ijkl\n"
    .t tag prev x 1.1 1.1
} -cleanup {
    destroy .t
} -result {}
test btree-18.2 {tag search back, start at existing range} -setup {
    destroy .t
    text .t
} -body {
    .t insert 1.0 "Line 1 abcd efgh ijkl\n"
    .t tag add x 1.1 1.4
    .t tag add x 1.8 1.11
    .t tag add x 1.16
    .t tag prev x 1.1
} -cleanup {
    destroy .t
} -result {}
test btree-18.3 {tag search back, end at existing range} -setup {
    destroy .t
    text .t
} -body {
    .t insert 1.0 "Line 1 abcd efgh ijkl\n"
    .t tag add x 1.1 1.4
    .t tag add x 1.8 1.11
    .t tag add x 1.16
    .t tag prev x 1.3 1.1
} -cleanup {
    destroy .t
} -result {1.1 1.4}
test btree-18.4 {tag search back, start within range} -setup {
    destroy .t
    text .t
} -body {
    .t insert 1.0 "Line 1 abcd efgh ijkl\n"
    .t tag add x 1.1 1.4
    .t tag add x 1.8 1.11
    .t tag add x 1.16
    .t tag prev x 1.10 1.0
} -cleanup {
    destroy .t
} -result {1.8 1.11}
test btree-18.5 {tag search back, start at end of range} -setup {
    destroy .t
    text .t
} -body {
    .t insert 1.0 "Line 1 abcd efgh ijkl\n"
    .t tag add x 1.1 1.4
    .t tag add x 1.8 1.11
    .t tag add x 1.16
    list [.t tag prev x 1.4 1.0] [.t tag prev x 1.11 1.0]
} -cleanup {
    destroy .t
} -result {{1.1 1.4} {1.8 1.11}}
test btree-18.6 {tag search back, start beyond range, same level 0 node} -setup {
    destroy .t
    text .t
} -body {
    .t insert 1.0 "Line 1 abcd efgh ijkl\n"
    .t tag add x 1.1 1.4
    .t tag add x 1.8 1.11
    .t tag add x 1.16
    .t tag prev x 3.0
} -cleanup {
    destroy .t
} -result {1.16 1.17}
test btree-18.7 {tag search back, outside any range} -setup {
    destroy .t
    text .t
} -body {
    .t insert 1.0 "Line 1 abcd efgh ijkl\n"
    .t tag add x 1.1 1.4
    .t tag add x 1.16
    .t tag prev x 1.8 1.5
} -cleanup {
    destroy .t
} -result {}
test btree-18.8 {tag search back, start at start of node boundary} -setup {
    destroy .t
    text .t
} -body {
    setupBig
    .t tag add x 2.5 2.8
    .t tag prev x 19.0
} -cleanup {
    destroy .t
} -result {2.5 2.8}
test btree-18.9 {tag search back, large complex btree spans} -setup {
    destroy .t
    text .t
} -body {
    setupBig
    .t tag add x 1.3 1.end
    .t tag add x 200.0 220.0
    .t tag add x 500.0 520.0
    list [.t tag prev x end] [.t tag prev x 433.0]
} -cleanup {
    destroy .t
} -result {{500.0 520.0} {200.0 220.0}}

# cleanup
cleanupTests
return