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