summaryrefslogtreecommitdiffstats
path: root/tests/spinbox.test
blob: 5b5811768ab3af0d34366f6b4e29282d738c5d6c (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
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
# This file is a Tcl script to test spinbox widgets in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright (c) 1998-2000 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands

proc scroll args {
    global scrollInfo
    set scrollInfo $args
}

# Create additional widget that's used to hold the selection at times.

spinbox .sel
.sel insert end "This is some sample text"

# Font names

set big -adobe-helvetica-medium-r-normal--24-240-75-75-p-*-iso8859-1
set fixed -adobe-courier-medium-r-normal--12-120-75-75-m-*-iso8859-1

# Create entries in the option database to be sure that geometry options
# like border width have predictable values.

option add *Spinbox.borderWidth 2
option add *Spinbox.highlightThickness 2
option add *Spinbox.font {Helvetica -12}

spinbox .e -bd 2 -relief sunken
pack .e
update

set i 1
foreach test {
    {-activebackground #ff0000 #ff0000 non-existent
	    {unknown color name "non-existent"}}
    {-background #ff0000 #ff0000 non-existent
	    {unknown color name "non-existent"}}
    {-bd 4 4 badValue {bad screen distance "badValue"}}
    {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
    {-borderwidth 1.3 1 badValue {bad screen distance "badValue"}}
    {-buttonbackground #ff0000 #ff0000 non-existent
	    {unknown color name "non-existent"}}
    {-buttoncursor arrow arrow badValue {bad cursor spec "badValue"}}
    {-command {a command} {a command} {} {}}
    {-cursor arrow arrow badValue {bad cursor spec "badValue"}}
    {-disabledbackground green green non-existent
	{unknown color name "non-existent"}}
    {-disabledforeground #110022 #110022 bogus {unknown color name "bogus"}}
    {-exportselection yes 1 xyzzy {expected boolean value but got "xyzzy"}}
    {-fg #110022 #110022 bogus {unknown color name "bogus"}}
    {-font -Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*
	-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-* {}
	{font "" doesn't exist}}
    {-foreground #110022 #110022 bogus {unknown color name "bogus"}}
    {-format %0.5f %0.5f %d {bad spinbox format specifier "%d"}}
    {-from -10 -10.0 bogus {expected floating-point number but got "bogus"}}
    {-highlightbackground #123456 #123456 ugly {unknown color name "ugly"}}
    {-highlightcolor #123456 #123456 bogus {unknown color name "bogus"}}
    {-highlightthickness 6 6 bogus {bad screen distance "bogus"}}
    {-highlightthickness -2 0 {} {}}
    {-increment 1.0 1.0 bogus {expected floating-point number but got "bogus"}}
    {-insertbackground #110022 #110022 bogus {unknown color name "bogus"}}
    {-insertborderwidth 1.3 1 2.6x {bad screen distance "2.6x"}}
    {-insertofftime 100 100 3.2 {expected integer but got "3.2"}}
    {-insertontime 100 100 3.2 {expected integer but got "3.2"}}
    {-invalidcommand "a command" "a command" {} {}}
    {-invcmd "a command" "a command" {} {}}
    {-justify right right bogus {bad justification "bogus": must be left, right, or center}}
    {-readonlybackground green green non-existent
	{unknown color name "non-existent"}}
    {-relief groove groove 1.5 {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}}
    {-repeatdelay 500 500 3p {expected integer but got "3p"}}
    {-repeatinterval -500 -500 3p {expected integer but got "3p"}}
    {-selectbackground #110022 #110022 bogus {unknown color name "bogus"}}
    {-selectborderwidth 1.3 1 badValue {bad screen distance "badValue"}}
    {-selectforeground #654321 #654321 bogus {unknown color name "bogus"}}
    {-state n normal bogus {bad state "bogus": must be disabled, normal, or readonly}}
    {-takefocus "any string" "any string" {} {}}
    {-textvariable i i {} {}}
    {-to 14.9 14.9 bogus {expected floating-point number but got "bogus"}}
    {-validate "key" "key" "bogus" {bad validate "bogus": must be all, key, focus, focusin, focusout, or none}}
    {-validatecommand "a command" "a command" {} {}}
    {-values {mon tue wed thur} {mon tue wed thur} {bad {}list} {list element in braces followed by "list" instead of space}}
    {-vcmd "a command" "a command" {} {}}
    {-width 402 402 3p {expected integer but got "3p"}}
    {-wrap yes 1 xyzzy {expected boolean value but got "xyzzy"}}
    {-xscrollcommand {Some command} {Some command} {} {}}
} {
    set name [lindex $test 0]
    test spinbox-1.$i {configuration options} {
	.e configure $name [lindex $test 1]
	list [lindex [.e configure $name] 4] [.e cget $name]
    } [list [lindex $test 2] [lindex $test 2]]
    incr i
    if {[lindex $test 3] != ""} {
	test spinbox-1.$i {configuration options} {
	    list [catch {.e configure $name [lindex $test 3]} msg] $msg
	} [list 1 [lindex $test 4]]
    }
    .e configure $name [lindex [.e configure $name] 3]
    incr i
}

test spinbox-2.1 {Tk_SpinboxCmd procedure} {
    list [catch {spinbox} msg] $msg
} {1 {wrong # args: should be "spinbox pathName ?options?"}}
test spinbox-2.2 {Tk_SpinboxCmd procedure} {
    list [catch {spinbox gorp} msg] $msg
} {1 {bad window path name "gorp"}}
test spinbox-2.3 {Tk_SpinboxCmd procedure} {
    catch {destroy .e}
    spinbox .e
    list [winfo exists .e] [winfo class .e] [info commands .e]
} {1 Spinbox .e}
test spinbox-2.4 {Tk_SpinboxCmd procedure} {
    catch {destroy .e}
    list [catch {spinbox .e -gorp foo} msg] $msg [winfo exists .e] \
	    [info commands .e]
} {1 {unknown option "-gorp"} 0 {}}
test spinbox-2.5 {Tk_SpinboxCmd procedure} {
    catch {destroy .e}
    spinbox .e
} {.e}

catch {destroy .e}
spinbox .e -font $fixed
pack .e
update

set cx [font measure $fixed a]
set cy [font metrics $fixed -linespace]
set ux [font measure $fixed \u4e4e]

test spinbox-3.1 {SpinboxWidgetCmd procedure} {
    list [catch {.e} msg] $msg
} {1 {wrong # args: should be ".e option ?arg arg ...?"}}
test spinbox-3.2 {SpinboxWidgetCmd procedure, "bbox" widget command} {
    list [catch {.e bbox} msg] $msg
} {1 {wrong # args: should be ".e bbox index"}}
test spinbox-3.3 {SpinboxWidgetCmd procedure, "bbox" widget command} {
    list [catch {.e bbox a b} msg] $msg
} {1 {wrong # args: should be ".e bbox index"}}
test spinbox-3.4 {SpinboxWidgetCmd procedure, "bbox" widget command} {
    list [catch {.e bbox bogus} msg] $msg
} {1 {bad spinbox index "bogus"}}
test spinbox-3.5 {SpinboxWidgetCmd procedure, "bbox" widget command} {
    .e delete 0 end
    .e bbox 0
} [list 5 5 0 $cy]
test spinbox-3.6 {SpinboxWidgetCmd procedure, "bbox" widget command} {
    # Tcl_UtfAtIndex(): no utf chars

    .e delete 0 end
    .e insert 0 "abc"
    list [.e bbox 3] [.e bbox end]
} [list "[expr 5+2*$cx] 5 $cx $cy" "[expr 5+2*$cx] 5 $cx $cy"]
test spinbox-3.7 {SpinboxWidgetCmd procedure, "bbox" widget command} {
    # Tcl_UtfAtIndex(): utf at end
    .e delete 0 end
    .e insert 0 "ab\u4e4e"
    .e bbox end
} "[expr 5+2*$cx] 5 $ux $cy"
test spinbox-3.8 {SpinboxWidgetCmd procedure, "bbox" widget command} {
    # Tcl_UtfAtIndex(): utf before index
    .e delete 0 end
    .e insert 0 "ab\u4e4ec"
    .e bbox 3
} "[expr 5+2*$cx+$ux] 5 $cx $cy"
test spinbox-3.9 {SpinboxWidgetCmd procedure, "bbox" widget command} {
    # Tcl_UtfAtIndex(): no chars
    .e delete 0 end
    .e bbox end
} "5 5 0 $cy"
test spinbox-3.10 {SpinboxWidgetCmd procedure, "bbox" widget command} {
    .e delete 0 end
    .e insert 0 "abcdefghij\u4e4eklmnop"
    list [.e bbox 0] [.e bbox 1] [.e bbox 10] [.e bbox end]
} [list "5 5 $cx $cy" "[expr 5+$cx] 5 $cx $cy" "[expr 5+10*$cx] 5 $ux $cy" "[expr 5+$ux+15*$cx] 5 $cx $cy"]
test spinbox-3.11 {SpinboxWidgetCmd procedure, "cget" widget command} {
    list [catch {.e cget} msg] $msg
} {1 {wrong # args: should be ".e cget option"}}
test spinbox-3.12 {SpinboxWidgetCmd procedure, "cget" widget command} {
    list [catch {.e cget a b} msg] $msg
} {1 {wrong # args: should be ".e cget option"}}
test spinbox-3.13 {SpinboxWidgetCmd procedure, "cget" widget command} {
    list [catch {.e cget -gorp} msg] $msg
} {1 {unknown option "-gorp"}}
test spinbox-3.14 {SpinboxWidgetCmd procedure, "cget" widget command} {
    .e configure -bd 4
    .e cget -bd
} {4}
test spinbox-3.15 {SpinboxWidgetCmd procedure, "configure" widget command} {
    llength [.e configure]
} {49}
test spinbox-3.16 {SpinboxWidgetCmd procedure, "configure" widget command} {
    list [catch {.e configure -foo} msg] $msg
} {1 {unknown option "-foo"}}
test spinbox-3.17 {SpinboxWidgetCmd procedure, "configure" widget command} {
    .e configure -bd 4
    .e configure -bg #ffffff
    lindex [.e configure -bd] 4
} {4}
test spinbox-3.18 {SpinboxWidgetCmd procedure, "delete" widget command} {
    list [catch {.e delete} msg] $msg
} {1 {wrong # args: should be ".e delete firstIndex ?lastIndex?"}}
test spinbox-3.19 {SpinboxWidgetCmd procedure, "delete" widget command} {
    list [catch {.e delete a b c} msg] $msg
} {1 {wrong # args: should be ".e delete firstIndex ?lastIndex?"}}
test spinbox-3.20 {SpinboxWidgetCmd procedure, "delete" widget command} {
    list [catch {.e delete foo} msg] $msg
} {1 {bad spinbox index "foo"}}
test spinbox-3.21 {SpinboxWidgetCmd procedure, "delete" widget command} {
    list [catch {.e delete 0 bar} msg] $msg
} {1 {bad spinbox index "bar"}}
test spinbox-3.22 {SpinboxWidgetCmd procedure, "delete" widget command} {
    .e delete 0 end
    .e insert end "01234567890"
    .e delete 2 4
    .e get
} {014567890}
test spinbox-3.23 {SpinboxWidgetCmd procedure, "delete" widget command} {
    .e delete 0 end
    .e insert end "01234567890"
    .e delete 6
    .e get
} {0123457890}
test spinbox-3.24 {SpinboxWidgetCmd procedure, "delete" widget command} {
    # UTF
    set x {}
    .e delete 0 end
    .e insert end "01234\u4e4e67890"
    .e delete 6
    lappend x [.e get]
    .e delete 0 end
    .e insert end "012345\u4e4e7890"
    .e delete 6
    lappend x [.e get]
    .e delete 0 end
    .e insert end "0123456\u4e4e890"
    .e delete 6
    lappend x [.e get]
} [list "01234\u4e4e7890" "0123457890" "012345\u4e4e890"]
test spinbox-3.25 {SpinboxWidgetCmd procedure, "delete" widget command} {
    .e delete 0 end
    .e insert end "01234567890"
    .e delete 6 5
    .e get
} {01234567890}
test spinbox-3.26 {SpinboxWidgetCmd procedure, "delete" widget command} {
    .e delete 0 end
    .e insert end "01234567890"
    .e configure -state disabled
    .e delete 2 8
    .e configure -state normal
    .e get
} {01234567890}
test spinbox-3.27 {SpinboxWidgetCmd procedure, "get" widget command} {
    list [catch {.e get foo} msg] $msg
} {1 {wrong # args: should be ".e get"}}
test spinbox-3.28 {SpinboxWidgetCmd procedure, "icursor" widget command} {
    list [catch {.e icursor} msg] $msg
} {1 {wrong # args: should be ".e icursor pos"}}
test spinbox-3.29 {SpinboxWidgetCmd procedure, "icursor" widget command} {
    list [catch {.e icursor foo} msg] $msg
} {1 {bad spinbox index "foo"}}
test spinbox-3.30 {SpinboxWidgetCmd procedure, "icursor" widget command} {
    .e delete 0 end
    .e insert end "01234567890"
    .e icursor 4
    .e index insert
} {4}
test spinbox-3.31 {SpinboxWidgetCmd procedure, "index" widget command} {
    list [catch {.e in} msg] $msg
} {1 {ambiguous option "in": must be bbox, cget, configure, delete, get, icursor, identify, index, insert, invoke, scan, selection, set, validate, or xview}}
test spinbox-3.32 {SpinboxWidgetCmd procedure, "index" widget command} {
    list [catch {.e index} msg] $msg
} {1 {wrong # args: should be ".e index string"}}
test spinbox-3.33 {SpinboxWidgetCmd procedure, "index" widget command} {
    list [catch {.e index foo} msg] $msg
} {1 {bad spinbox index "foo"}}
test spinbox-3.34 {SpinboxWidgetCmd procedure, "index" widget command} {
    list [catch {.e index 0} msg] $msg
} {0 0}
test spinbox-3.35 {SpinboxWidgetCmd procedure, "index" widget command} {
    # UTF
    .e delete 0 end
    .e insert 0 abc\u4e4e\u0153def
    list [.e index 3] [.e index 4] [.e index end]
} {3 4 8}
test spinbox-3.36 {SpinboxWidgetCmd procedure, "insert" widget command} {
    list [catch {.e insert a} msg] $msg
} {1 {wrong # args: should be ".e insert index text"}}
test spinbox-3.37 {SpinboxWidgetCmd procedure, "insert" widget command} {
    list [catch {.e insert a b c} msg] $msg
} {1 {wrong # args: should be ".e insert index text"}}
test spinbox-3.38 {SpinboxWidgetCmd procedure, "insert" widget command} {
    list [catch {.e insert foo Text} msg] $msg
} {1 {bad spinbox index "foo"}}
test spinbox-3.39 {SpinboxWidgetCmd procedure, "insert" widget command} {
    .e delete 0 end
    .e insert end "01234567890"
    .e insert 3 xxx
    .e get
} {012xxx34567890}
test spinbox-3.40 {SpinboxWidgetCmd procedure, "insert" widget command} {
    .e delete 0 end
    .e insert end "01234567890"
    .e configure -state disabled
    .e insert 3 xxx
    .e configure -state normal
    .e get
} {01234567890}
test spinbox-3.41 {SpinboxWidgetCmd procedure, "insert" widget command} {
    list [catch {.e insert a b c} msg] $msg
} {1 {wrong # args: should be ".e insert index text"}}
test spinbox-3.42 {SpinboxWidgetCmd procedure, "scan" widget command} {
    list [catch {.e scan a} msg] $msg
} {1 {wrong # args: should be ".e scan mark|dragto x"}}
test spinbox-3.43 {SpinboxWidgetCmd procedure, "scan" widget command} {
    list [catch {.e scan a b c} msg] $msg
} {1 {wrong # args: should be ".e scan mark|dragto x"}}
test spinbox-3.44 {SpinboxWidgetCmd procedure, "scan" widget command} {
    list [catch {.e scan foobar 20} msg] $msg
} {1 {bad scan option "foobar": must be mark or dragto}}
test spinbox-3.45 {SpinboxWidgetCmd procedure, "scan" widget command} {
    list [catch {.e scan mark 20.1} msg] $msg
} {1 {expected integer but got "20.1"}}
# This test is non-portable because character sizes vary.

test spinbox-3.46 {SpinboxWidgetCmd procedure, "scan" widget command} {fonts} {
    .e delete 0 end
    update
    .e insert end "This is quite a long string, in fact a "
    .e insert end "very very long string"
    .e scan mark 30
    .e scan dragto 28
    .e index @0
} {2}
test spinbox-3.47 {SpinboxWidgetCmd procedure, "select" widget command} {
    list [catch {.e select} msg] $msg
} {1 {wrong # args: should be ".e selection option ?index?"}}
test spinbox-3.48 {SpinboxWidgetCmd procedure, "select" widget command} {
    list [catch {.e select foo} msg] $msg
} {1 {bad selection option "foo": must be adjust, clear, element, from, present, range, or to}}
test spinbox-3.49 {SpinboxWidgetCmd procedure, "select clear" widget command} {
    list [catch {.e select clear gorp} msg] $msg
} {1 {wrong # args: should be ".e selection clear"}}
test spinbox-3.50 {SpinboxWidgetCmd procedure, "select clear" widget command} {
    .e delete 0 end
    .e insert end "0123456789"
    .e select from 1
    .e select to 4
    update
    .e select clear
    list [catch {selection get} msg] $msg [selection own]
} {1 {PRIMARY selection doesn't exist or form "STRING" not defined} .e}
test spinbox-3.51 {SpinboxWidgetCmd procedure, "selection present" widget command} {
    list [catch {.e selection present foo} msg] $msg
} {1 {wrong # args: should be ".e selection present"}}
test spinbox-3.52 {SpinboxWidgetCmd procedure, "selection present" widget command} {
    .e delete 0 end
    .e insert end 0123456789
    .e select from 3
    .e select to 6
    .e selection present
} {1}
test spinbox-3.53 {SpinboxWidgetCmd procedure, "selection present" widget command} {
    .e delete 0 end
    .e insert end 0123456789
    .e select from 3
    .e select to 6
    .e configure -exportselection false
    .e selection present
} {1}
.e configure -exportselection true
test spinbox-3.54 {SpinboxWidgetCmd procedure, "selection present" widget command} {
    .e delete 0 end
    .e insert end 0123456789
    .e select from 3
    .e select to 6
    .e delete 0 end
    .e selection present
} {0}
test spinbox-3.55 {SpinboxWidgetCmd procedure, "selection adjust" widget command} {
    list [catch {.e select adjust x} msg] $msg
} {1 {bad spinbox index "x"}}
test spinbox-3.56 {SpinboxWidgetCmd procedure, "selection adjust" widget command} {
    list [catch {.e select adjust 2 3} msg] $msg
} {1 {wrong # args: should be ".e selection adjust index"}}
test spinbox-3.57 {SpinboxWidgetCmd procedure, "selection adjust" widget command} {
    .e delete 0 end
    .e insert end "0123456789"
    .e select from 1
    .e select to 5
    update
    .e select adjust 4
    selection get
} {123}
test spinbox-3.58 {SpinboxWidgetCmd procedure, "selection adjust" widget command} {
    .e delete 0 end
    .e insert end "0123456789"
    .e select from 1
    .e select to 5
    update
    .e select adjust 2
    selection get
} {234}
test spinbox-3.59 {SpinboxWidgetCmd procedure, "selection from" widget command} {
    list [catch {.e select from 2 3} msg] $msg
} {1 {wrong # args: should be ".e selection from index"}}
test spinbox-3.60 {SpinboxWidgetCmd procedure, "selection range" widget command} {
    list [catch {.e select range 2} msg] $msg
} {1 {wrong # args: should be ".e selection range start end"}}
test spinbox-3.61 {SpinboxWidgetCmd procedure, "selection range" widget command} {
    list [catch {.e selection range 2 3 4} msg] $msg
} {1 {wrong # args: should be ".e selection range start end"}}
test spinbox-3.62 {SpinboxWidgetCmd procedure, "selection range" widget command} {
    .e delete 0 end
    .e insert end 0123456789
    .e select from 1
    .e select to 5
    .e select range 4 4
    list [catch {.e index sel.first} msg] $msg
} {1 {selection isn't in widget .e}}
test spinbox-3.63 {SpinboxWidgetCmd procedure, "selection range" widget command} {
    .e delete 0 end
    .e insert end 0123456789
    .e select from 3
    .e select to 7
    .e select range 2 9
    list [.e index sel.first] [.e index sel.last] [.e index anchor]
} {2 9 3}
.e delete 0 end
.e insert end "This is quite a long text string, so long that it "
.e insert end "runs off the end of the window quite a bit."
test spinbox-3.64 {SpinboxWidgetCmd procedure, "selection to" widget command} {
    list [catch {.e select to 2 3} msg] $msg
} {1 {wrong # args: should be ".e selection to index"}}
test spinbox-3.65 {SpinboxWidgetCmd procedure, "xview" widget command} {
    .e xview 5
    format {%.6f %.6f} {*}[.e xview]
} {0.053763 0.268817}
test spinbox-3.66 {SpinboxWidgetCmd procedure, "xview" widget command} {
    list [catch {.e xview gorp} msg] $msg
} {1 {bad spinbox index "gorp"}}
test spinbox-3.67 {SpinboxWidgetCmd procedure, "xview" widget command} {
    .e xview 0
    .e icursor 10
    .e xview insert
    format {%.6f %.6f} {*}[.e xview]
} {0.107527 0.322581}
test spinbox-3.68 {SpinboxWidgetCmd procedure, "xview" widget command} {
    list [catch {.e xview moveto foo bar} msg] $msg
} {1 {wrong # args: should be ".e xview moveto fraction"}}
test spinbox-3.69 {SpinboxWidgetCmd procedure, "xview" widget command} {
    list [catch {.e xview moveto foo} msg] $msg
} {1 {expected floating-point number but got "foo"}}
test spinbox-3.70 {SpinboxWidgetCmd procedure, "xview" widget command} {
    .e xview moveto 0.5
    format {%.6f %.6f} {*}[.e xview]
} {0.505376 0.720430}
test spinbox-3.71 {SpinboxWidgetCmd procedure, "xview" widget command} {
    list [catch {.e xview scroll 24} msg] $msg
} {1 {wrong # args: should be ".e xview scroll number units|pages"}}
test spinbox-3.72 {SpinboxWidgetCmd procedure, "xview" widget command} {
    list [catch {.e xview scroll gorp units} msg] $msg
} {1 {expected integer but got "gorp"}}
test spinbox-3.73 {SpinboxWidgetCmd procedure, "xview" widget command} {
    .e xview moveto 0
    .e xview scroll 1 pages
    format {%.6f %.6f} {*}[.e xview]
} {0.193548 0.408602}
test spinbox-3.74 {SpinboxWidgetCmd procedure, "xview" widget command} {
    .e xview moveto .9
    update
    .e xview scroll -2 p
    format {%.6f %.6f} {*}[.e xview]
} {0.397849 0.612903}
test spinbox-3.75 {SpinboxWidgetCmd procedure, "xview" widget command} {
    .e xview 30
    update
    .e xview scroll 2 units
    .e index @0
} {32}
test spinbox-3.76 {SpinboxWidgetCmd procedure, "xview" widget command} {
    .e xview 30
    update
    .e xview scroll -1 units
    .e index @0
} {29}
test spinbox-3.77 {SpinboxWidgetCmd procedure, "xview" widget command} {
    list [catch {.e xview scroll 23 foobars} msg] $msg
} {1 {bad argument "foobars": must be units or pages}}
test spinbox-3.78 {SpinboxWidgetCmd procedure, "xview" widget command} {
    list [catch {.e xview eat 23 hamburgers} msg] $msg
} {1 {unknown option "eat": must be moveto or scroll}}
test spinbox-3.79 {SpinboxWidgetCmd procedure, "xview" widget command} {
    .e xview 0
    update
    .e xview -4
    .e index @0
} {0}
test spinbox-3.80 {SpinboxWidgetCmd procedure, "xview" widget command} {
    .e xview 300
    .e index @0
} {73}
.e insert 10 \u4e4e
test spinbox-3.81 {SpinboxWidgetCmd procedure, "xview" widget command} {
    # UTF
    # If Tcl_NumUtfChars wasn't used, wrong answer would be:
    # 0.106383 0.117021 0.117021

    set x {}
    .e xview moveto .1
    lappend x [format {%.6f} [lindex [.e xview] 0]]
    .e xview moveto .11
    lappend x [format {%.6f} [lindex [.e xview] 0]]
    .e xview moveto .12
    lappend x [format {%.6f} [lindex [.e xview] 0]]
} {0.095745 0.106383 0.117021}
test spinbox-3.82 {SpinboxWidgetCmd procedure} {
    list [catch {.e gorp} msg] $msg
} {1 {bad option "gorp": must be bbox, cget, configure, delete, get, icursor, identify, index, insert, invoke, scan, selection, set, validate, or xview}}

frame .f -width 200 -height 50 -relief raised -bd 2
pack .f -side right
test spinbox-5.1 {ConfigureSpinbox procedure, -textvariable} {
    catch {destroy .e}
    set x 12345
    spinbox .e -textvariable x
    .e get
} {12345}
test spinbox-5.2 {ConfigureSpinbox procedure, -textvariable} {
    catch {destroy .e}
    set x 12345
    spinbox .e -textvariable x
    set y abcde
    .e configure -textvariable y
    set x 54321
    .e get
} {abcde}
test spinbox-5.3 {ConfigureSpinbox procedure, -textvariable} {
    catch {destroy .e}
    catch {unset x}
    spinbox .e
    .e insert 0 "Some text"
    .e configure -textvariable x
    set x
} {Some text}
test spinbox-5.4 {ConfigureSpinbox procedure, -textvariable} {
    proc override args {
	global x
	set x 12345
    }
    catch {destroy .e}
    catch {unset x}
    trace variable x w override
    spinbox .e
    .e insert 0 "Some text"
    .e configure -textvariable x
    set result [list $x [.e get]]
    unset x;  rename override {}
    set result
} {12345 12345}
test spinbox-5.5 {ConfigureSpinbox procedure} {
    catch {destroy .e}
    spinbox .e -exportselection false
    pack .e
    .e insert end "0123456789"
    .sel select from 0
    .sel select to 10
    set x {}
    lappend x [selection get]
    .e select from 1
    .e select to 5
    lappend x [selection get]
    .e configure -exportselection 1
    lappend x [selection get]
    set x
} {{This is so} {This is so} 1234}
test spinbox-5.6 {ConfigureSpinbox procedure} {
    catch {destroy .e}
    spinbox .e
    pack .e
    .e insert end "0123456789"
    .e select from 1
    .e select to 5
    .e configure -exportselection 0
    list [catch {selection get} msg] $msg [.e index sel.first] \
	    [.e index sel.last]
} {1 {PRIMARY selection doesn't exist or form "STRING" not defined} 1 5}
test spinbox-5.7 {ConfigureSpinbox procedure} {
    catch {destroy .e}
    spinbox .e -font $fixed -width 4 -xscrollcommand scroll
    pack .e
    .e insert end "01234567890"
    update
    .e configure -width 5
    format {%.6f %.6f} {*}$scrollInfo
} {0.000000 0.363636}
test spinbox-5.8 {ConfigureSpinbox procedure} {fonts} {
    catch {destroy .e}
    spinbox .e -width 0
    pack .e
    .e insert end "0123"
    update
    .e configure -font $big
    update
    winfo geom .e
} {79x37+0+0}
test spinbox-5.9 {ConfigureSpinbox procedure} {fonts} {
    catch {destroy .e}
    spinbox .e -font $fixed -bd 2 -relief raised
    pack .e
    .e insert end "0123"
    update
    list [.e index @10] [.e index @11] [.e index @12] [.e index @13]
} {0 0 1 1}
test spinbox-5.10 {ConfigureSpinbox procedure} {fonts} {
    catch {destroy .e}
    spinbox .e -font $fixed -bd 2 -relief flat
    pack .e
    .e insert end "0123"
    update
    list [.e index @10] [.e index @11] [.e index @12] [.e index @13]
} {0 0 1 1}
test spinbox-5.11 {ConfigureSpinbox procedure} {
    # If "0" in selected font had 0 width, caused divide-by-zero error.

    catch {destroy .e}
    pack [spinbox .e -font {{open look glyph}}]
    .e scan dragto 30
    update
} {}

# No tests for DisplaySpinbox.

test spinbox-6.1 {SpinboxComputeGeometry procedure} {fonts} {
    catch {destroy .e}
    spinbox .e -font $fixed -bd 2 -relief raised -width 20 -highlightthickness 3
    pack .e
    .e insert end 012\t45
    update
    list [.e index @61] [.e index @62]
} {3 4}
test spinbox-6.2 {SpinboxComputeGeometry procedure} {fonts} {
    catch {destroy .e}
    spinbox .e -font $fixed -bd 2 -relief raised -width 20 -justify center \
	    -highlightthickness 3
    pack .e
    .e insert end 012\t45
    update
    list [.e index @96] [.e index @97]
} {3 4}
test spinbox-6.3 {SpinboxComputeGeometry procedure} {fonts} {
    catch {destroy .e}
    spinbox .e -font $fixed -bd 2 -relief raised -width 20 -justify right \
	    -highlightthickness 3
    pack .e
    .e insert end 012\t45
    update
    list [.e index @131] [.e index @132]
} {3 4}
test spinbox-6.4 {SpinboxComputeGeometry procedure} {
    catch {destroy .e}
    spinbox .e -font $fixed -bd 2 -relief raised -width 5
    pack .e
    .e insert end "01234567890"
    update
    .e xview 6
    .e index @0
} {6}
test spinbox-6.5 {SpinboxComputeGeometry procedure} {
    catch {destroy .e}
    spinbox .e -font $fixed -bd 2 -relief raised -width 5
    pack .e
    .e insert end "01234567890"
    update
    .e xview 7
    .e index @0
} {6}
test spinbox-6.6 {SpinboxComputeGeometry procedure} {fonts} {
    catch {destroy .e}
    spinbox .e -font $fixed -bd 2 -relief raised -width 10
    pack .e
    .e insert end "01234\t67890"
    update
    .e xview 3
    list [.e index @39] [.e index @40]
} {5 6}
test spinbox-6.7 {SpinboxComputeGeometry procedure} {fonts} {
    catch {destroy .e}
    spinbox .e -font $big -bd 3 -relief raised -width 5
    pack .e
    .e insert end "01234567"
    update
    list [winfo reqwidth .e] [winfo reqheight .e]
} {94 39}
test spinbox-6.8 {SpinboxComputeGeometry procedure} {fonts} {
    catch {destroy .e}
    spinbox .e -font $big -bd 3 -relief raised -width 0
    pack .e
    .e insert end "01234567"
    update
    list [winfo reqwidth .e] [winfo reqheight .e]
} {133 39}
test spinbox-6.9 {SpinboxComputeGeometry procedure} {fonts} {
    catch {destroy .e}
    spinbox .e -font $big -bd 3 -relief raised -width 0 -highlightthickness 2
    pack .e
    update
    list [winfo reqwidth .e] [winfo reqheight .e]
} {42 39}

catch {destroy .e}
spinbox .e -width 10 -font $fixed -textvariable contents -xscrollcommand scroll
pack .e
focus .e
test spinbox-7.1 {InsertChars procedure} {
    .e delete 0 end
    .e insert 0 abcde
    .e insert 2 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} {abXXXcde abXXXcde {0.000000 1.000000}}
test spinbox-7.2 {InsertChars procedure} {
    .e delete 0 end
    .e insert 0 abcde
    .e insert 500 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} {abcdeXXX abcdeXXX {0.000000 1.000000}}
test spinbox-7.3 {InsertChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 2 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} {5 9 5 8}
test spinbox-7.4 {InsertChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 3 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} {2 9 2 8}
test spinbox-7.5 {InsertChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 5 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} {2 9 2 8}
test spinbox-7.6 {InsertChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 6 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend x [.e index sel.first] [.e index sel.last]
} {2 6 2 5}
test spinbox-7.7 {InsertChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789
    .e icursor 4
    .e insert 4 XXX
    .e index insert
} {7}
test spinbox-7.8 {InsertChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789
    .e icursor 4
    .e insert 5 XXX
    .e index insert
} {4}
test spinbox-7.9 {InsertChars procedure} {
    .e delete 0 end
    .e insert 0 "This is a very long string"
    update
    .e xview 4
    .e insert 3 XXX
    .e index @0
} {7}
test spinbox-7.10 {InsertChars procedure} {
    .e delete 0 end
    .e insert 0 "This is a very long string"
    update
    .e xview 4
    .e insert 4 XXX
    .e index @0
} {4}
.e configure -width 0
test spinbox-7.11 {InsertChars procedure} {fonts} {
    .e delete 0 end
    .e insert 0 "xyzzy"
    update
    .e insert 2 00
    winfo reqwidth .e
} {70}

.e configure -width 10
test spinbox-8.1 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 abcde
    .e delete 2 4
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} {abe abe {0.000000 1.000000}}
test spinbox-8.2 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 abcde
    .e delete -2 2
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} {cde cde {0.000000 1.000000}}
test spinbox-8.3 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 abcde
    .e delete 3 1000
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} {abc abc {0.000000 1.000000}}
test spinbox-8.4 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 3
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend x [.e index sel.first] [.e index sel.last]
} {1 6 1 5}
test spinbox-8.5 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 4
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 4
    lappend x [.e index sel.first] [.e index sel.last]
} {1 5 1 4}
test spinbox-8.6 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 7
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend x [.e index sel.first] [.e index sel.last]
} {1 2 1 5}
test spinbox-8.7 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 8
    list [catch {.e index sel.first} msg] $msg
} {1 {selection isn't in widget .e}}
test spinbox-8.8 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 3 7
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} {3 4 3 8}
test spinbox-8.9 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 3 8
    list [catch {.e index sel.first} msg] $msg
} {1 {selection isn't in widget .e}}
test spinbox-8.10 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789abcde
    .e select from 8
    .e select to 3
    .e delete 5 8
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} {3 5 5 8}
test spinbox-8.11 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789abcde
    .e select from 8
    .e select to 3
    .e delete 8 10
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 4
    lappend x [.e index sel.first] [.e index sel.last]
} {3 8 4 8}
test spinbox-8.12 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789abcde
    .e icursor 4
    .e delete 1 4
    .e index insert
} {1}
test spinbox-8.13 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789abcde
    .e icursor 4
    .e delete 1 5
    .e index insert
} {1}
test spinbox-8.14 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 0123456789abcde
    .e icursor 4
    .e delete 4 6
    .e index insert
} {4}
test spinbox-8.15 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 "This is a very long string"
    .e xview 4
    .e delete 1 4
    .e index @0
} {1}
test spinbox-8.16 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 "This is a very long string"
    .e xview 4
    .e delete 1 5
    .e index @0
} {1}
test spinbox-8.17 {DeleteChars procedure} {
    .e delete 0 end
    .e insert 0 "This is a very long string"
    .e xview 4
    .e delete 4 6
    .e index @0
} {4}
.e configure -width 0
test spinbox-8.18 {DeleteChars procedure} {fonts} {
    .e delete 0 end
    .e insert 0 "xyzzy"
    update
    .e delete 2 4
    winfo reqwidth .e
} {42}

test spinbox-9.1 {SpinboxValueChanged procedure} {
    catch {destroy .e}
    proc override args {
	global x
	set x 12345
    }
    catch {unset x}
    trace variable x w override
    spinbox .e -textvariable x
    .e insert 0 foo
    set result [list $x [.e get]]
    unset x; rename override {}
    set result
} {12345 12345}

catch {destroy .e}
spinbox .e
pack .e
.e configure -width 0
test spinbox-10.1 {SpinboxSetValue procedure} {fonts} {
    set x abcde
    set y ab
    .e configure -textvariable x
    update
    .e configure -textvariable y
    update
    list [.e get] [winfo reqwidth .e]
} {ab 35}
test spinbox-10.2 {SpinboxSetValue procedure, updating selection} {
    catch {destroy .e}
    spinbox .e -textvariable x
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set x "a"
    list [catch {.e index sel.first} msg] $msg
} {1 {selection isn't in widget .e}}
test spinbox-10.3 {SpinboxSetValue procedure, updating selection} {
    catch {destroy .e}
    spinbox .e -textvariable x
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set x "abcdefg"
    list [.e index sel.first] [.e index sel.last]
} {4 7}
test spinbox-10.4 {SpinboxSetValue procedure, updating selection} {
    catch {destroy .e}
    spinbox .e -textvariable x
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set x "abcdefghijklmn"
    list [.e index sel.first] [.e index sel.last]
} {4 10}
test spinbox-10.5 {SpinboxSetValue procedure, updating display position} {
    catch {destroy .e}
    spinbox .e -width 10 -font $fixed -textvariable x
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set x "abcdefg"
    update
    .e index @0
} {0}
test spinbox-10.6 {SpinboxSetValue procedure, updating display position} {
    catch {destroy .e}
    spinbox .e -width 10 -font $fixed -textvariable x
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set x "1234567890123456789012"
    update
    .e index @0
} {10}
test spinbox-10.7 {SpinboxSetValue procedure, updating insertion cursor} {
    catch {destroy .e}
    spinbox .e -width 10 -font $fixed -textvariable x
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set x "123"
    .e index insert
} {3}
test spinbox-10.8 {SpinboxSetValue procedure, updating insertion cursor} {
    catch {destroy .e}
    spinbox .e -width 10 -font $fixed -textvariable x
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set x "123456"
    .e index insert
} {5}

test spinbox-11.1 {SpinboxEventProc procedure} {
    catch {destroy .e}
    spinbox .e
    .e insert 0 abcdefg
    destroy .e
    update
} {}
test spinbox-11.2 {SpinboxEventProc procedure} {
    deleteWindows
    spinbox .e1 -fg #112233
    rename .e1 .e2
    set x {}
    lappend x [winfo children .]
    lappend x [.e2 cget -fg]
    destroy .e1
    lappend x [info command .e*] [winfo children .]
} {.e1 #112233 {} {}}

test spinbox-12.1 {SpinboxCmdDeletedProc procedure} {
    deleteWindows
    button .e1 -text "xyz_123"
    rename .e1 {}
    list [info command .e*] [winfo children .]
} {{} {}}

catch {destroy .e}
spinbox .e -font $fixed -width 5 -bd 2 -relief sunken
pack .e
.e insert 0 012345678901234567890
.e xview 4
update
test spinbox-13.1 {GetSpinboxIndex procedure} {
    .e index end
} {21}
test spinbox-13.2 {GetSpinboxIndex procedure} {
    list [catch {.e index abogus} msg] $msg
} {1 {bad spinbox index "abogus"}}
test spinbox-13.3 {GetSpinboxIndex procedure} {
    .e select from 1
    .e select to 6
    .e index anchor
} {1}
test spinbox-13.4 {GetSpinboxIndex procedure} {
    .e select from 4
    .e select to 1
    .e index anchor
} {4}
test spinbox-13.5 {GetSpinboxIndex procedure} {
    .e select from 3
    .e select to 15
    .e select adjust 4
    .e index anchor
} {15}
test spinbox-13.6 {GetSpinboxIndex procedure} {
    list [catch {.e index ebogus} msg] $msg
} {1 {bad spinbox index "ebogus"}}
test spinbox-13.7 {GetSpinboxIndex procedure} {
    .e icursor 2
    .e index insert
} {2}
test spinbox-13.8 {GetSpinboxIndex procedure} {
    list [catch {.e index ibogus} msg] $msg
} {1 {bad spinbox index "ibogus"}}
test spinbox-13.9 {GetSpinboxIndex procedure} {
    .e select from 1
    .e select to 6
    list [.e index sel.first] [.e index sel.last]
} {1 6}
selection clear .e
test spinbox-13.10 {GetSpinboxIndex procedure} unix {
    # On unix, when selection is cleared, spinbox widget's internal
    # selection range is reset.

    list [catch {.e index sel.first} msg] $msg
} {1 {selection isn't in widget .e}}
test spinbox-13.11 {GetSpinboxIndex procedure} win {
    # On mac and pc, when selection is cleared, spinbox widget remembers
    # last selected range.  When selection ownership is restored to
    # spinbox, the old range will be rehighlighted.

    list [catch {selection get}] [.e index sel.first]
} {1 1}
test spinbox-13.12 {GetSpinboxIndex procedure} unix {
    list [catch {.e index sbogus} msg] $msg
} {1 {selection isn't in widget .e}}
test spinbox-13.13 {GetSpinboxIndex procedure} win {
    list [catch {.e index sbogus} msg] $msg
} {1 {bad spinbox index "sbogus"}}
test spinbox-13.14 {GetSpinboxIndex procedure} win {
    list [catch {selection get}] [catch {.e index sbogus}]
} {1 1}
test spinbox-13.15 {GetSpinboxIndex procedure} {
    list [catch {.e index @xyz} msg] $msg
} {1 {bad spinbox index "@xyz"}}
test spinbox-13.16 {GetSpinboxIndex procedure} {fonts} {
    .e index @4
} {4}
test spinbox-13.17 {GetSpinboxIndex procedure} {fonts} {
    .e index @11
} {4}
test spinbox-13.18 {GetSpinboxIndex procedure} {fonts} {
    .e index @12
} {5}
test spinbox-13.19 {GetSpinboxIndex procedure} {fonts} {
    # 11 is the minimum button width
    .e index @[expr [winfo width .e] - 6 - 11]
} {8}
test spinbox-13.20 {GetSpinboxIndex procedure} {fonts} {
    .e index @[expr [winfo width .e] - 5]
} {9}
test spinbox-13.21 {GetSpinboxIndex procedure} {
    .e index @1000
} {9}
test spinbox-13.22 {GetSpinboxIndex procedure} {
    list [catch {.e index 1xyz} msg] $msg
} {1 {bad spinbox index "1xyz"}}
test spinbox-13.23 {GetSpinboxIndex procedure} {
    .e index -10
} {0}
test spinbox-13.24 {GetSpinboxIndex procedure} {
    .e index 12
} {12}
test spinbox-13.25 {GetSpinboxIndex procedure} {
    .e index 49
} {21}

# XXX Still need to write tests for SpinboxScanTo and SpinboxSelectTo.

set x {}
for {set i 1} {$i <= 500} {incr i} {
    append x "This is line $i, out of 500\n"
}
test spinbox-14.1 {SpinboxFetchSelection procedure} {
    catch {destroy .e}
    spinbox .e
    .e insert end "This is a test string"
    .e select from 1
    .e select to 18
    selection get
} {his is a test str}
test spinbox-14.3 {SpinboxFetchSelection procedure} {
    catch {destroy .e}
    spinbox .e
    .e insert end $x
    .e select from 0
    .e select to end
    string compare [selection get] $x
} 0

test spinbox-15.1 {SpinboxLostSelection} {
    catch {destroy .e}
    spinbox .e
    .e insert 0 "Text"
    .e select from 0
    .e select to 4
    set result [selection get]
    selection clear
    .e select from 0
    .e select to 4
    lappend result [selection get]
} {Text Text}

# No tests for EventuallyRedraw.

catch {destroy .e}
spinbox .e -width 10 -xscrollcommand scroll
pack .e
update

test spinbox-16.1 {SpinboxVisibleRange procedure} {fonts} {
    .e delete 0 end
    .e insert 0 .............................
    format {%.6f %.6f} {*}[.e xview]
} {0.000000 0.827586}
test spinbox-16.2 {SpinboxVisibleRange procedure} {
    .e delete 0 end
    format {%.6f %.6f} {*}[.e xview]
} {0.000000 1.000000}

catch {destroy .e}
spinbox .e -width 10 -xscrollcommand scroll -font $fixed
pack .e
update
test spinbox-17.1 {SpinboxUpdateScrollbar procedure} {
    .e delete 0 end
    .e insert 0 123
    update
    format {%.6f %.6f} {*}$scrollInfo
} {0.000000 1.000000}
test spinbox-17.2 {SpinboxUpdateScrollbar procedure} {
    .e delete 0 end
    .e insert 0 0123456789abcdef
    .e xview 3
    update
    format {%.6f %.6f} {*}$scrollInfo
} {0.187500 0.812500}
test spinbox-17.3 {SpinboxUpdateScrollbar procedure} {
    .e delete 0 end
    .e insert 0 abcdefghijklmnopqrs
    .e xview 6
    update
    format {%.6f %.6f} {*}$scrollInfo
} {0.315789 0.842105}
test spinbox-17.4 {SpinboxUpdateScrollbar procedure} {
    destroy .e
    set x "Background error did not happen"
    proc bgerror msg {
	global x
	set x $msg
    }
    spinbox .e -width 5 -xscrollcommand thisisnotacommand
    pack .e
    update
    rename bgerror {}
    list $x $errorInfo
} {{invalid command name "thisisnotacommand"} {invalid command name "thisisnotacommand"
    while executing
"thisisnotacommand 0.0 1.0"
    (horizontal scrolling command executed by .e)}}

set l [interp hidden]
deleteWindows

test spinbox-18.1 {Spinbox widget vs hiding} {
    destroy .e
    spinbox .e
    interp hide {} .e
    destroy .e
    list [winfo children .] [interp hidden]
} [list {} $l]

##
## Spinbox widget VALIDATION tests
##

destroy .e
catch {unset ::e}
catch {unset ::vVals}
spinbox .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
pack .e
proc doval {W d i P s S v V} {
    set ::vVals [list $W $d $i $P $s $S $v $V]
    return 1
}

# The validation tests build each one upon the previous, so cascading
# failures aren't good
#
test spinbox-19.1 {spinbox widget validation} {
    .e insert 0 a
    set ::vVals
} {.e 1 0 a {} a all key}
test spinbox-19.2 {spinbox widget validation} {
    .e insert 1 b
    set ::vVals
} {.e 1 1 ab a b all key}
test spinbox-19.3 {spinbox widget validation} {
    .e insert end c
    set ::vVals
} {.e 1 2 abc ab c all key}
test spinbox-19.4 {spinbox widget validation} {
    .e insert 1 123
    list $::vVals $::e
} {{.e 1 1 a123bc abc 123 all key} a123bc}
test spinbox-19.5 {spinbox widget validation} {
    .e delete 2
    set ::vVals
} {.e 0 2 a13bc a123bc 2 all key}
test spinbox-19.6 {spinbox widget validation} {
    .e configure -validate key
    .e delete 1 3
    set ::vVals
} {.e 0 1 abc a13bc 13 key key}
test spinbox-19.7 {spinbox widget validation} {
    set ::vVals {}
    .e configure -validate focus
    .e insert end d
    set ::vVals
} {}
test spinbox-19.8 {spinbox widget validation} {
    focus -force .e
    # update necessary to process FocusIn event
    update
    set ::vVals
} {.e -1 -1 abcd abcd {} focus focusin}
test spinbox-19.9 {spinbox widget validation} {
    focus -force .
    # update necessary to process FocusOut event
    update
    set ::vVals
} {.e -1 -1 abcd abcd {} focus focusout}
.e configure -validate all
test spinbox-19.10 {spinbox widget validation} {
    focus -force .e
    # update necessary to process FocusIn event
    update
    set ::vVals
} {.e -1 -1 abcd abcd {} all focusin}
test spinbox-19.11 {spinbox widget validation} {
    focus -force .
    # update necessary to process FocusOut event
    update
    set ::vVals
} {.e -1 -1 abcd abcd {} all focusout}
.e configure -validate focusin
test spinbox-19.12 {spinbox widget validation} {
    focus -force .e
    # update necessary to process FocusIn event
    update
    set ::vVals
} {.e -1 -1 abcd abcd {} focusin focusin}
test spinbox-19.13 {spinbox widget validation} {
    set ::vVals {}
    focus -force .
    # update necessary to process FocusOut event
    update
    set ::vVals
} {}
.e configure -validate focuso
test spinbox-19.14 {spinbox widget validation} {
    focus -force .e
    # update necessary to process FocusIn event
    update
    set ::vVals
} {}
test spinbox-19.15 {spinbox widget validation} {
    focus -force .
    # update necessary to process FocusOut event
    update
    set ::vVals
} {.e -1 -1 abcd abcd {} focusout focusout}
test spinbox-19.16 {spinbox widget validation} {
    list [.e validate] $::vVals
} {1 {.e -1 -1 abcd abcd {} all forced}}
test spinbox-19.17 {spinbox widget validation} {
    set ::e newdata
    list [.e cget -validate] $::vVals
} {focusout {.e -1 -1 newdata abcd {} focusout forced}}

proc doval {W d i P s S v V} {
    set ::vVals [list $W $d $i $P $s $S $v $V]
    return 0
}
.e configure -validate all

test spinbox-19.18 {spinbox widget validation} {
    set ::e nextdata
    list [.e cget -validate] $::vVals
} {none {.e -1 -1 nextdata newdata {} all forced}}

proc doval {W d i P s S v V} {
    set ::vVals [list $W $d $i $P $s $S $v $V]
    set ::e mydata
    return 1
}
.e configure -validate all

## This sets validate to none because it shows that we prevent a possible
## loop condition in the validation, when the spinbox textvar is also set
test spinbox-19.19 {spinbox widget validation} {
    .e validate
    list [.e cget -validate] [.e get] $::vVals
} {none mydata {.e -1 -1 nextdata nextdata {} all forced}}

.e configure -validate all

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the spinbox widget shown as is in the textvar.
test spinbox-19.20 {spinbox widget validation} {
    set ::e testdata
    list [.e cget -validate] [.e get] $::e $::vVals
} {all testdata mydata {.e -1 -1 testdata mydata {} all forced}}

# A format specifier is allowed to be of the form %[-+ 0]{0,1}\d.?\d?f
#
destroy .e
spinbox .e
test spinbox-20.1 {spinbox config, -format specifier} {
    list [catch {.e config -format %2f} msg] $msg
} {0 {}}
test spinbox-20.2 {spinbox config, -format specifier} {
    list [catch {.e config -format %2.2f} msg] $msg
} {0 {}}
test spinbox-20.3 {spinbox config, -format specifier} {
    list [catch {.e config -format %.2f} msg] $msg
} {0 {}}
test spinbox-20.4 {spinbox config, -format specifier} {
    list [catch {.e config -format %2.f} msg] $msg
} {0 {}}
test spinbox-20.5 {spinbox config, -format specifier} {
    list [catch {.e config -format %2e-1f} msg] $msg
} {1 {bad spinbox format specifier "%2e-1f"}}
test spinbox-20.6 {spinbox config, -format specifier} {
    list [catch {.e config -format 2.2} msg] $msg
} {1 {bad spinbox format specifier "2.2"}}
test spinbox-20.7 {spinbox config, -format specifier} {
    list [catch {.e config -format %2.-2f} msg] $msg
} {1 {bad spinbox format specifier "%2.-2f"}}
test spinbox-20.8 {spinbox config, -format specifier} {
    list [catch {.e config -format %-2.02f} msg] $msg
} {0 {}}
test spinbox-20.9 {spinbox config, -format specifier} {
    list [catch {.e config -format "% 2.02f"} msg] $msg
} {0 {}}
test spinbox-20.10 {spinbox config, -format specifier} {
    list [catch {.e config -format "% -2.200f"} msg] $msg
} {0 {}}
test spinbox-20.11 {spinbox config, -format specifier} {
    list [catch {.e config -format "%09.200f"} msg] $msg
} {0 {}}
test spinbox-20.12 {spinbox config, -format specifier does something} {
    set out {}
    .e config -format "%02.f"
    .e config -values {} -from 0 -to 10 -increment 1
    lappend out [.e set 0]; # set currently doesn't force format
    .e invoke buttonup
    lappend out [.e set]; # but after invoke it should be formatted
    lappend out [.e set 3]; # set currently doesn't force format
    .e config -format "%03.f"
    lappend out [.e set]; # changing -format should cause formatting
} {0 01 3 003}

test spinbox-21.1 {spinbox button, out of range checking} {
    destroy .e
    spinbox .e -from -10 -to 20 -increment 2
    set out {}
    lappend out [.e get]; # -10
    .e delete 0 end
    .e insert 0 25; # set outside of range
    .e invoke buttondown; # should constrain
    lappend out [.e get]; # 20
    .e delete 0 end
    .e insert 0 25; # set outside of range
    .e invoke buttonup; # should constrain
    lappend out [.e get]; # 20
    .e delete 0 end
    .e insert 0 -100; # set outside of range
    .e invoke buttonup; # should constrain
    lappend out [.e get]; # -10
    .e delete 0 end
    .e insert 0 -100; # set outside of range
    .e invoke buttondown; # should constrain
    lappend out [.e get]; # -10
    .e delete 0 end
    .e insert 0 bogus; # set to a bogus value
    .e invoke buttondown; # should use fromValue
    lappend out [.e get]; # -10
    .e delete 0 end
    .e insert 0 19; # set just inside of range
    .e invoke buttonup; # no wrap
    lappend out [.e get]; # 20
    .e invoke buttonup; # no wrap
    lappend out [.e get]; # 20
    .e invoke buttondown
    lappend out [.e get]; # 18
    .e delete 0 end
    .e insert 0 -9; # set just inside of range
    .e invoke buttondown; # no wrap
    lappend out [.e get]; # -10
    .e invoke buttondown; # no wrap
    lappend out [.e get]; # -10
    .e invoke buttonup; # no wrap
    lappend out [.e get]; # -8

    .e configure -wrap 1
    .e delete 0 end
    .e insert 0 19; # set just inside of range
    .e invoke buttonup; # wrap
    lappend out [.e get]; # -10
    .e invoke buttonup
    lappend out [.e get]; # -8
    .e invoke buttondown
    lappend out [.e get]; # -10
    .e delete 0 end
    .e insert 0 -9; # set just inside of range
    .e invoke buttondown; # wrap
    lappend out [.e get]; # 20
    .e invoke buttondown
    lappend out [.e get]; # 18
    .e invoke buttonup; # no wrap
    lappend out [.e get]; # 20

} {-10 20 20 -10 -10 -10 20 20 18 -10 -10 -8 -10 -8 -10 20 18 20}

test spinbox-22.1 {spinbox config, -from changes SF bug 559078} {
    set val 5
    destroy .s
    spinbox .s -from 1 -to 10 -textvariable val
    set val
} {5}
test spinbox-22.2 {spinbox config, -from changes SF bug 559078} {
    .s configure -from 3 -to 10
    set val
} {5}
test spinbox-22.3 {spinbox config, -from changes SF bug 559078} {
    .s configure -from 6 -to 10
    set val
} {6}

test spinbox-23.1 {selection present while disabled, bug 637828} {
    destroy .e
    spinbox .e
    .e insert end 0123456789
    .e select from 3
    .e select to 6
    set out [.e selection present]
    .e configure -state disabled
    # still return 1 when disabled, because 'selection get' will work,
    # but selection cannot be changed (new behavior since 8.4)
    .e select to 9
    lappend out [.e selection present] [selection get]
} {1 1 345}

destroy .e

test spinbox-24.1 {error in trace proc attached to the textvariable} {
    destroy .s
    trace variable myvar w traceit
    proc traceit args {error "Intentional error here!"}
    spinbox .s -textvariable myvar -from 1 -to 10
    catch {.s set mystring} result1
    catch {.s insert 0 mystring} result2
    catch {.s delete 0} result3
    catch {.s invoke buttonup} result4
    list $result1 $result2 $result3 $result4
} [list {can't set "myvar": Intentional error here!} \
    {can't set "myvar": Intentional error here!} \
    {can't set "myvar": Intentional error here!} \
    {can't set "myvar": Intentional error here!}]

test spinbox-25.1 {textvariable lives in a non-existing namespace} {
    destroy .s
    catch {spinbox .s -textvariable thisnsdoesntexist::myvar} result1
    set result1
} {can't trace "thisnsdoesntexist::myvar": parent namespace doesn't exist}

catch {unset ::e ::vVals}

##
## End validation tests
##

# XXX Still need to write tests for SpinboxBlinkProc, SpinboxFocusProc,
# and SpinboxTextVarProc.

option clear

# cleanup
cleanupTests
return