home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tk4.0 / tests / text.test < prev    next >
Encoding:
Text File  |  1995-06-29  |  31.8 KB  |  978 lines

  1. # This file is a Tcl script to test the code in the file tkText.c.
  2. # This file is organized in the standard fashion for Tcl tests.
  3. #
  4. # Copyright (c) 1992-1994 The Regents of the University of California.
  5. # Copyright (c) 1994-1995 Sun Microsystems, Inc.
  6. #
  7. # See the file "license.terms" for information on usage and redistribution
  8. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  9. #
  10. # @(#) text.test 1.24 95/06/28 17:51:27
  11.  
  12. if {[string compare test [info procs test]] == 1} then \
  13.   {source defs}
  14.  
  15. eval destroy [winfo child .]
  16. if [catch {text .t \
  17.     -font -adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1 \
  18.     -width 20 -height 10}] {
  19.     puts "The font needed by these tests isn't available, so I'm"
  20.     puts "going to skip the tests."
  21.     return
  22. }
  23. pack append . .t {top expand fill}
  24. update
  25. .t debug on
  26. wm geometry . {}
  27.   
  28. # The statements below reset the main window;  it's needed if the window
  29. # manager is mwm to make mwm forget about a previous minimum size setting.
  30.  
  31. wm withdraw .
  32. wm minsize . 1 1
  33. wm positionfrom . user
  34. wm deiconify .
  35.  
  36. entry .t.e
  37. .t.e insert end abcdefg
  38. .t.e select from 0
  39.  
  40. .t insert 1.0 "Line 1
  41. abcdefghijklm
  42. 12345
  43. Line 4
  44. bOy GIrl .#@? x_yz
  45. !@#$%
  46. Line 7"
  47.  
  48. catch {destroy .t2}
  49. text .t2
  50. set i 0
  51. foreach test {
  52.     {-background #ff00ff #ff00ff <gorp>}
  53.     {-bd 4 4 foo}
  54.     {-bg blue blue #xx}
  55.     {-borderwidth 7 7 ++}
  56.     {-cursor watch watch lousy}
  57.     {-exportselection no 0 maybe}
  58.     {-fg red red stupid}
  59.     {-font fixed fixed never_heard_of}
  60.     {-foreground #012 #012 bogus}
  61.     {-height 5 5 bad}
  62.     {-highlightbackground #123 #123 bogus}
  63.     {-highlightcolor #234 #234 bogus}
  64.     {-highlightthickness -2 0 bad}
  65.     {-insertbackground green green <bogus>}
  66.     {-insertborderwidth 45 45 bogus}
  67.     {-insertofftime 100 100 2.4}
  68.     {-insertontime 47 47 e1}
  69.     {-insertwidth 2.3 2 47d}
  70.     {-padx 3.4 3 2.4.}
  71.     {-pady 82 82 bogus}
  72.     {-relief raised raised bumpy}
  73.     {-selectbackground #ffff01234567 #ffff01234567 bogus}
  74.     {-selectborderwidth 21 21 3x}
  75.     {-selectforeground yellow yellow #12345}
  76.     {-spacing1 20 20 1.3x}
  77.     {-spacing1 -5 0 bogus}
  78.     {-spacing2 5 5 bogus}
  79.     {-spacing2 -1 0 bogus}
  80.     {-spacing3 20 20 bogus}
  81.     {-spacing3 -10 0 bogus}
  82.     {-state disabled disabled foo}
  83.     {-tabs {1i 2i 3i 4i} {1i 2i 3i 4i} bad_tabs}
  84.     {-width 73 73 2.4}
  85.     {-wrap word word bad_wrap}
  86. } {
  87.     test text-1.[incr i] {text options} {
  88.     set result {}
  89.     lappend result [catch {.t2 configure [lindex $test 0] [lindex $test 3]}]
  90.     .t2 configure [lindex $test 0] [lindex $test 1]
  91.     lappend result [.t2 cget [lindex $test 0]]
  92.     } [list 1 [lindex $test 2]]
  93. }
  94. test text-1.[incr i] {text options} {
  95.     .t2 configure -takefocus "any old thing"
  96.     .t2 cget -takefocus
  97. } {any old thing}
  98. test text-1.[incr i] {text options} {
  99.     .t2 configure -xscrollcommand "x scroll command"
  100.     .t2 configure -xscrollcommand
  101. } {-xscrollcommand xScrollCommand ScrollCommand {} {x scroll command}}
  102. test text-1.[incr i] {text options} {
  103.     .t2 configure -yscrollcommand "test command"
  104.     .t2 configure -yscrollcommand
  105. } {-yscrollcommand yScrollCommand ScrollCommand {} {test command}}
  106. test text-1.[incr i] {text options} {
  107.     set result {}
  108.     foreach i [.t2 configure] {
  109.     lappend result [lindex $i 4]
  110.     }
  111.     set result
  112. } {blue {} {} 7 watch 0 {} fixed #012 5 #123 #234 0 green 45 100 47 2 3 82 raised #ffff01234567 21 yellow 0 0 0 0 disabled {1i 2i 3i 4i} {any old thing} 73 word {x scroll command} {test command}}
  113.  
  114. test text-2.1 {Tk_TextCmd procedure} {
  115.     list [catch {text} msg] $msg
  116. } {1 {wrong # args: should be "text pathName ?options?"}}
  117. test text-2.2 {Tk_TextCmd procedure} {
  118.     list [catch {text foobar} msg] $msg
  119. } {1 {bad window path name "foobar"}}
  120. test text-2.3 {Tk_TextCmd procedure} {
  121.     catch {destroy .t2}
  122.     list [catch {text .t2 -gorp nofun} msg] $msg [winfo exists .t2]
  123. } {1 {unknown option "-gorp"} 0}
  124. test text-2.4 {Tk_TextCmd procedure} {
  125.     catch {destroy .t2}
  126.     list [catch {text .t2 -bd 2 -fg red} msg] $msg \
  127.     [lindex [.t2 config -bd] 4] [lindex [.t2 config -fg] 4]
  128. } {0 .t2 2 red}
  129. test text-2.5 {Tk_TextCmd procedure} {
  130.     catch {destroy .t2}
  131.     text .t2
  132.     .t2 tag cget sel -relief 
  133. } {raised}
  134. test text-2.6 {Tk_TextCmd procedure} {
  135.     catch {destroy .t2}
  136.     list [text .t2] [winfo class .t2]
  137. } {.t2 Text}
  138.  
  139. test text-3.1 {TextWidgetCmd procedure, basics} {
  140.     list [catch {.t} msg] $msg
  141. } {1 {wrong # args: should be ".t option ?arg arg ...?"}}
  142. test text-3.2 {TextWidgetCmd procedure} {
  143.     list [catch {.t gorp 1.0 z 1.2} msg] $msg
  144. } {1 {bad option "gorp":  must be bbox, cget, compare, configure, debug, delete, dlineinfo, get, index, insert, mark, scan, search, see, tag, window, xview, or yview}}
  145.  
  146. test text-4.1 {TextWidgetCmd procedure, "bbox" option} {
  147.     list [catch {.t bbox} msg] $msg
  148. } {1 {wrong # args: should be ".t bbox index"}}
  149. test text-4.2 {TextWidgetCmd procedure, "bbox" option} {
  150.     list [catch {.t bbox a b} msg] $msg
  151. } {1 {wrong # args: should be ".t bbox index"}}
  152. test text-4.3 {TextWidgetCmd procedure, "bbox" option} {
  153.     list [catch {.t bbox bad_mark} msg] $msg
  154. } {1 {bad text index "bad_mark"}}
  155.  
  156. test text-5.1 {TextWidgetCmd procedure, "cget" option} {
  157.     list [catch {.t cget} msg] $msg
  158. } {1 {wrong # args: should be ".t cget option"}}
  159. test text-5.2 {TextWidgetCmd procedure, "cget" option} {
  160.     list [catch {.t cget a b} msg] $msg
  161. } {1 {wrong # args: should be ".t cget option"}}
  162. test text-5.3 {TextWidgetCmd procedure, "cget" option} {
  163.     list [catch {.t cget -gorp} msg] $msg
  164. } {1 {unknown option "-gorp"}}
  165. test text-5.4 {TextWidgetCmd procedure, "cget" option} {
  166.     .t configure -bd 17
  167.     .t cget -bd
  168. } {17}
  169. .t configure -bd [lindex [.t configure -bd] 3]
  170.  
  171. test text-6.1 {TextWidgetCmd procedure, "compare" option} {
  172.     list [catch {.t compare a b} msg] $msg
  173. } {1 {wrong # args: should be ".t compare index1 op index2"}}
  174. test text-6.2 {TextWidgetCmd procedure, "compare" option} {
  175.     list [catch {.t compare a b c d} msg] $msg
  176. } {1 {wrong # args: should be ".t compare index1 op index2"}}
  177. test text-6.3 {TextWidgetCmd procedure, "compare" option} {
  178.     list [catch {.t compare @x == 1.0} msg] $msg
  179. } {1 {bad text index "@x"}}
  180. test text-6.4 {TextWidgetCmd procedure, "compare" option} {
  181.     list [catch {.t compare 1.0 < @y} msg] $msg
  182. } {1 {bad text index "@y"}}
  183. test text-6.5 {TextWidgetCmd procedure, "compare" option} {
  184.     list [.t compare 1.1 < 1.0] [.t compare 1.1 < 1.1] [.t compare 1.1 < 1.2]
  185. } {0 0 1}
  186. test text-6.6 {TextWidgetCmd procedure, "compare" option} {
  187.     list [.t compare 1.1 <= 1.0] [.t compare 1.1 <= 1.1] [.t compare 1.1 <= 1.2]
  188. } {0 1 1}
  189. test text-6.7 {TextWidgetCmd procedure, "compare" option} {
  190.     list [.t compare 1.1 == 1.0] [.t compare 1.1 == 1.1] [.t compare 1.1 == 1.2]
  191. } {0 1 0}
  192. test text-6.8 {TextWidgetCmd procedure, "compare" option} {
  193.     list [.t compare 1.1 >= 1.0] [.t compare 1.1 >= 1.1] [.t compare 1.1 >= 1.2]
  194. } {1 1 0}
  195. test text-6.9 {TextWidgetCmd procedure, "compare" option} {
  196.     list [.t compare 1.1 > 1.0] [.t compare 1.1 > 1.1] [.t compare 1.1 > 1.2]
  197. } {1 0 0}
  198. test text-6.10 {TextWidgetCmd procedure, "compare" option} {
  199.     list [.t com 1.1 != 1.0] [.t compare 1.1 != 1.1] [.t compare 1.1 != 1.2]
  200. } {1 0 1}
  201. test text-6.11 {TextWidgetCmd procedure, "compare" option} {
  202.     list [catch {.t compare 1.0 <x 1.2} msg] $msg
  203. } {1 {bad comparison operator "<x": must be <, <=, ==, >=, >, or !=}}
  204. test text-6.12 {TextWidgetCmd procedure, "compare" option} {
  205.     list [catch {.t compare 1.0 >> 1.2} msg] $msg
  206. } {1 {bad comparison operator ">>": must be <, <=, ==, >=, >, or !=}}
  207. test text-6.13 {TextWidgetCmd procedure, "compare" option} {
  208.     list [catch {.t compare 1.0 z 1.2} msg] $msg
  209. } {1 {bad comparison operator "z": must be <, <=, ==, >=, >, or !=}}
  210. test text-6.14 {TextWidgetCmd procedure, "compare" option} {
  211.     list [catch {.t co 1.0 z 1.2} msg] $msg
  212. } {1 {bad option "co":  must be bbox, cget, compare, configure, debug, delete, dlineinfo, get, index, insert, mark, scan, search, see, tag, window, xview, or yview}}
  213.  
  214. # "configure" option is already covered above
  215.  
  216. test text-7.1 {TextWidgetCmd procedure, "debug" option} {
  217.     list [catch {.t debug 0 1} msg] $msg
  218. } {1 {wrong # args: should be ".t debug boolean"}}
  219. test text-7.2 {TextWidgetCmd procedure, "debug" option} {
  220.     list [catch {.t de 0 1} msg] $msg
  221. } {1 {bad option "de":  must be bbox, cget, compare, configure, debug, delete, dlineinfo, get, index, insert, mark, scan, search, see, tag, window, xview, or yview}}
  222. test text-7.3 {TextWidgetCmd procedure, "debug" option} {
  223.     .t debug true
  224.     .t deb
  225. } 1
  226. test text-7.4 {TextWidgetCmd procedure, "debug" option} {
  227.     .t debug false
  228.     .t debug
  229. } 0
  230. .t debug
  231.  
  232. test text-8.1 {TextWidgetCmd procedure, "delete" option} {
  233.     list [catch {.t delete} msg] $msg
  234. } {1 {wrong # args: should be ".t delete index1 ?index2?"}}
  235. test text-8.2 {TextWidgetCmd procedure, "delete" option} {
  236.     list [catch {.t delete a b c} msg] $msg
  237. } {1 {wrong # args: should be ".t delete index1 ?index2?"}}
  238. test text-8.3 {TextWidgetCmd procedure, "delete" option} {
  239.     list [catch {.t delete @x 2.2} msg] $msg
  240. } {1 {bad text index "@x"}}
  241. test text-8.4 {TextWidgetCmd procedure, "delete" option} {
  242.     list [catch {.t delete 2.3 @y} msg] $msg
  243. } {1 {bad text index "@y"}}
  244. test text-8.5 {TextWidgetCmd procedure, "delete" option} {
  245.     .t con -state disabled
  246.     .t delete 2.3
  247.     .t g 2.0 2.end
  248. } abcdefghijklm
  249. .t con -state normal
  250. test text-8.6 {TextWidgetCmd procedure, "delete" option} {
  251.     .t delete 2.3
  252.     .t get 2.0 2.end
  253. } abcefghijklm
  254. test text-8.7 {TextWidgetCmd procedure, "delete" option} {
  255.     .t delete 2.1 2.3
  256.     .t get 2.0 2.end
  257. } aefghijklm
  258.  
  259. test text-9.1 {TextWidgetCmd procedure, "get" option} {
  260.     list [catch {.t get} msg] $msg
  261. } {1 {wrong # args: should be ".t get index1 ?index2?"}}
  262. test text-9.2 {TextWidgetCmd procedure, "get" option} {
  263.     list [catch {.t get a b c} msg] $msg
  264. } {1 {wrong # args: should be ".t get index1 ?index2?"}}
  265. test text-9.3 {TextWidgetCmd procedure, "get" option} {
  266.     list [catch {.t get @q 3.1} msg] $msg
  267. } {1 {bad text index "@q"}}
  268. test text-9.4 {TextWidgetCmd procedure, "get" option} {
  269.     list [catch {.t get 3.1 @r} msg] $msg
  270. } {1 {bad text index "@r"}}
  271. test text-9.5 {TextWidgetCmd procedure, "get" option} {
  272.     .t get 5.7 5.3
  273. } {}
  274. test text-9.6 {TextWidgetCmd procedure, "get" option} {
  275.     .t get 5.3 5.5
  276. } { G}
  277. test text-9.7 {TextWidgetCmd procedure, "get" option} {
  278.     .t get 5.3 end
  279. } { GIrl .#@? x_yz
  280. !@#$%
  281. Line 7
  282. }
  283. .t mark set a 5.3
  284. .t mark set b 5.3
  285. .t mark set c 5.5
  286. test text-9.8 {TextWidgetCmd procedure, "get" option} {
  287.     .t get 5.2 5.7
  288. } {y GIr}
  289. test text-9.9 {TextWidgetCmd procedure, "get" option} {
  290.     .t get 5.2
  291. } {y}
  292. test text-9.10 {TextWidgetCmd procedure, "get" option} {
  293.     .t get 5.2 5.4
  294. } {y }
  295.  
  296. test text-10.1 {TextWidgetCmd procedure, "index" option} {
  297.     list [catch {.t index} msg] $msg
  298. } {1 {wrong # args: should be ".t index index"}}
  299. test text-10.2 {TextWidgetCmd procedure, "index" option} {
  300.     list [catch {.t ind a b} msg] $msg
  301. } {1 {wrong # args: should be ".t index index"}}
  302. test text-10.3 {TextWidgetCmd procedure, "index" option} {
  303.     list [catch {.t in a b} msg] $msg
  304. } {1 {bad option "in":  must be bbox, cget, compare, configure, debug, delete, dlineinfo, get, index, insert, mark, scan, search, see, tag, window, xview, or yview}}
  305. test text-10.4 {TextWidgetCmd procedure, "index" option} {
  306.     list [catch {.t index @xyz} msg] $msg
  307. } {1 {bad text index "@xyz"}}
  308. test text-10.5 {TextWidgetCmd procedure, "index" option} {
  309.     .t index 1.2
  310. } 1.2
  311.  
  312. test text-11.1 {TextWidgetCmd procedure, "insert" option} {
  313.     list [catch {.t insert 1.2} msg] $msg
  314. } {1 {wrong # args: should be ".t insert index chars ?tagList chars tagList ...?"}}
  315. test text-11.2 {TextWidgetCmd procedure, "insert" option} {
  316.     .t config -state disabled
  317.     .t insert 1.2 xyzzy
  318.     .t get 1.0 1.end
  319. } {Line 1}
  320. .t config -state normal
  321. test text-11.3 {TextWidgetCmd procedure, "insert" option} {
  322.     .t insert 1.2 xyzzy
  323.     .t get 1.0 1.end
  324. } {Lixyzzyne 1}
  325. test text-11.4 {TextWidgetCmd procedure, "insert" option} {
  326.     .t delete 1.0 end
  327.     .t insert 1.0 "Sample text" x
  328.     .t tag ranges x
  329. } {1.0 1.11}
  330. test text-11.5 {TextWidgetCmd procedure, "insert" option} {
  331.     .t delete 1.0 end
  332.     .t insert 1.0 "Sample text" x
  333.     .t insert 1.2 "XYZ" y
  334.     list [.t tag ranges x] [.t tag ranges y]
  335. } {{1.0 1.2 1.5 1.14} {1.2 1.5}}
  336. test text-11.6 {TextWidgetCmd procedure, "insert" option} {
  337.     .t delete 1.0 end
  338.     .t insert 1.0 "Sample text" {x y z}
  339.     list [.t tag ranges x] [.t tag ranges y] [.t tag ranges z]
  340. } {{1.0 1.11} {1.0 1.11} {1.0 1.11}}
  341. test text-11.7 {TextWidgetCmd procedure, "insert" option} {
  342.     .t delete 1.0 end
  343.     .t insert 1.0 "Sample text" {x y z}
  344.     .t insert 1.3 "A" {a b z}
  345.     list [.t tag ranges a] [.t tag ranges b] [.t tag ranges x] [.t tag ranges y] [.t tag ranges z]
  346. } {{1.3 1.4} {1.3 1.4} {1.0 1.3 1.4 1.12} {1.0 1.3 1.4 1.12} {1.0 1.12}}
  347. test text-11.8 {TextWidgetCmd procedure, "insert" option} {
  348.     .t delete 1.0 end
  349.     list [catch {.t insert 1.0 "Sample text" "a \{b"} msg] $msg
  350. } {1 {unmatched open brace in list}}
  351. test text-11.9 {TextWidgetCmd procedure, "insert" option} {
  352.     .t delete 1.0 end
  353.     .t insert 1.0 "First" bold " " {} second "x y z" " third"
  354.     list [.t get 1.0 1.end] [.t tag ranges bold] [.t tag ranges x] \
  355.         [.t tag ranges y] [.t tag ranges z]
  356. } {{First second third} {1.0 1.5} {1.6 1.12} {1.6 1.12} {1.6 1.12}}
  357. test text-11.10 {TextWidgetCmd procedure, "insert" option} {
  358.     .t delete 1.0 end
  359.     .t insert 1.0 "First" bold " second" silly
  360.     list [.t get 1.0 1.end] [.t tag ranges bold] [.t tag ranges silly]
  361. } {{First second} {1.0 1.5} {1.5 1.12}}
  362.  
  363. # Mark, scan, search, see, tag, window, xview, and yview actions are tested elsewhere.
  364.  
  365. test text-12.1 {ConfigureText procedure} {
  366.     list [catch {.t2 configure -state foobar} msg] $msg
  367. } {1 {bad state value "foobar":  must be normal or disabled}}
  368. test text-12.2 {ConfigureText procedure} {
  369.     .t2 configure -spacing1 -2 -spacing2 1 -spacing3 1
  370.     list [.t2 cget -spacing1] [.t2 cget -spacing2] [.t2 cget -spacing3]
  371. } {0 1 1}
  372. test text-12.3 {ConfigureText procedure} {
  373.     .t2 configure -spacing1 1 -spacing2 -1 -spacing3 1
  374.     list [.t2 cget -spacing1] [.t2 cget -spacing2] [.t2 cget -spacing3]
  375. } {1 0 1}
  376. test text-12.4 {ConfigureText procedure} {
  377.     .t2 configure -spacing1 1 -spacing2 1 -spacing3 -3
  378.     list [.t2 cget -spacing1] [.t2 cget -spacing2] [.t2 cget -spacing3]
  379. } {1 1 0}
  380. test text-12.5 {ConfigureText procedure} {
  381.     set x [list [catch {.t2 configure -tabs {30 foo}} msg] $msg $errorInfo]
  382.     .t2 configure -tabs {10 20 30}
  383.     set x
  384. } {1 {bad tab alignment "foo": must be left, right, center, or numeric} {bad tab alignment "foo": must be left, right, center, or numeric
  385.     (while processing -tabs option)
  386.     invoked from within
  387. ".t2 configure -tabs {30 foo}"}}
  388. test text-12.6 {ConfigureText procedure} {
  389.     .t2 configure -tabs {10 20 30}
  390.     .t2 configure -tabs {}
  391.     .t2 cget -tabs
  392. } {}
  393. test text-12.7 {ConfigureText procedure} {
  394.     list [catch {.t2 configure -wrap bogus} msg] $msg
  395. } {1 {bad wrap mode "bogus":  must be char, none, or word}}
  396. test text-12.8 {ConfigureText procedure} {
  397.     .t2 configure -selectborderwidth 17 -selectforeground #332211 \
  398.         -selectbackground #abc
  399.     list [lindex [.t2 tag config sel -borderwidth] 4] \
  400.     [lindex [.t2 tag config sel -foreground] 4] \
  401.     [lindex [.t2 tag config sel -background] 4]
  402. } {17 #332211 #abc}
  403. test text-12.9 {ConfigureText procedure} {
  404.     .t2 configure -selectborderwidth {}
  405.     .t2 tag cget sel -borderwidth
  406. } {}
  407. test text-12.10 {ConfigureText procedure} {
  408.     list [catch {.t2 configure -selectborderwidth foo} msg] $msg
  409. } {1 {bad screen distance "foo"}}
  410. test text-12.11 {ConfigureText procedure} {
  411.     catch {destroy .t2}
  412.     .t.e select to 2
  413.     text .t2 -exportselection 1
  414.     selection get
  415. } {ab}
  416. test text-12.12 {ConfigureText procedure} {
  417.     catch {destroy .t2}
  418.     .t.e select to 2
  419.     text .t2 -exportselection 0
  420.     .t2 insert insert 1234657890
  421.     .t2 tag add sel 1.0 1.4
  422.     selection get
  423. } {ab}
  424. test text-12.13 {ConfigureText procedure} {
  425.     catch {destroy .t2}
  426.     .t.e select to 1
  427.     text .t2 -exportselection 1
  428.     .t2 insert insert 1234657890
  429.     .t2 tag add sel 1.0 1.4
  430.     selection get
  431. } {1234}
  432. test text-12.14 {ConfigureText procedure} {
  433.     catch {destroy .t2}
  434.     .t.e select to 1
  435.     text .t2 -exportselection 0
  436.     .t2 insert insert 1234657890
  437.     .t2 tag add sel 1.0 1.4
  438.     .t2 configure -exportselection 1
  439.     selection get
  440. } {1234}
  441. test text-12.15 {ConfigureText procedure} {
  442.     catch {destroy .t2}
  443.     text .t2 -exportselection 1
  444.     .t2 insert insert 1234657890
  445.     .t2 tag add sel 1.0 1.4
  446.     set result [selection get]
  447.     .t2 configure -exportselection 0
  448.     lappend result [catch {selection get} msg] $msg
  449. } {1234 1 {PRIMARY selection doesn't exist or form "STRING" not defined}}
  450. if $doNonPortableTests {
  451.     # This test is non-portable because the window size will vary depending
  452.     # on the font size, which can vary.
  453.  
  454.     test text-12.16 {ConfigureText procedure} {
  455.     catch {destroy .t2}
  456.     toplevel .t2
  457.     text .t2.t -width 20 -height 10
  458.     pack append .t2 .t2.t top
  459.     wm geometry .t2 +0+0
  460.     update
  461.     wm geometry .t2
  462.     } {150x150+0+0}
  463. }
  464. test text-12.17 {ConfigureText procedure} {
  465.     catch {destroy .t2}
  466.     toplevel .t2
  467.     text .t2.t -width 20 -height 10 -setgrid 1
  468.     pack append .t2 .t2.t top
  469.     wm geometry .t2 +0+0
  470.     update
  471.     wm geometry .t2
  472. } {20x10+0+0}
  473. test text-12.18 {ConfigureText procedure} {
  474.     catch {destroy .t2}
  475.     toplevel .t2
  476.     text .t2.t -width 20 -height 10 -setgrid 1
  477.     pack append .t2 .t2.t top
  478.     wm geometry .t2 +0+0
  479.     update
  480.     set result [wm geometry .t2]
  481.     wm geometry .t2 15x8
  482.     update
  483.     lappend result [wm geometry .t2]
  484.     .t2.t configure -wrap word
  485.     update
  486.     lappend result [wm geometry .t2]
  487. } {20x10+0+0 15x8+0+0 15x8+0+0}
  488.  
  489. test text-13.1 {TextEventProc procedure} {
  490.     text .tx1 -bg #543210
  491.     rename .tx1 .tx2
  492.     set x {}
  493.     lappend x [winfo exists .tx1]
  494.     lappend x [.tx2 cget -bg]
  495.     destroy .tx1
  496.     lappend x [info command .tx*] [winfo exists .tx1] [winfo exists .tx2]
  497. } {1 #543210 {} 0 0}
  498.  
  499. test text-14.1 {TextCmdDeletedProc procedure} {
  500.     text .tx1
  501.     rename .tx1 {}
  502.     list [info command .tx*] [winfo exists .tx1]
  503. } {{} 0}
  504.  
  505. test text-15.1 {InsertChars procedure} {
  506.     catch {destroy .t2}
  507.     text .t2
  508.     .t2 insert 2.0 abcd\n
  509.     .t2 get 1.0 end
  510. } {abcd
  511.  
  512. }
  513. test text-15.2 {InsertChars procedure} {
  514.     catch {destroy .t2}
  515.     text .t2
  516.     .t2 insert 1.0 abcd\n
  517.     .t2 insert end 123\n
  518.     .t2 get 1.0 end
  519. } {abcd
  520. 123
  521.  
  522. }
  523. test text-15.3 {InsertChars procedure} {
  524.     catch {destroy .t2}
  525.     text .t2
  526.     .t2 insert 1.0 abcd\n
  527.     .t2 insert 10.0 123
  528.     .t2 get 1.0 end
  529. } {abcd
  530. 123
  531. }
  532.  
  533. proc setup {} {
  534.     .t delete 1.0 end
  535.     .t insert 1.0 "Line 1
  536. abcde
  537. 12345
  538. Line 4"
  539. }
  540.  
  541. .t delete 1.0 end
  542. test text-16.1 {DeleteChars procedure} {
  543.     .t get 1.0 end
  544. } {
  545. }
  546. test text-16.2 {DeleteChars procedure} {
  547.     list [catch {.t delete foobar} msg] $msg
  548. } {1 {bad text index "foobar"}}
  549. test text-16.3 {DeleteChars procedure} {
  550.     list [catch {.t delete 1.0 lousy} msg] $msg
  551. } {1 {bad text index "lousy"}}
  552. test text-16.4 {DeleteChars procedure} {
  553.     setup
  554.     .t delete 2.1
  555.     .t get 1.0 end
  556. } {Line 1
  557. acde
  558. 12345
  559. Line 4
  560. }
  561. test text-16.5 {DeleteChars procedure} {
  562.     setup
  563.     .t delete 2.3
  564.     .t get 1.0 end
  565. } {Line 1
  566. abce
  567. 12345
  568. Line 4
  569. }
  570. test text-16.6 {DeleteChars procedure} {
  571.     setup
  572.     .t delete 2.end
  573.     .t get 1.0 end
  574. } {Line 1
  575. abcde12345
  576. Line 4
  577. }
  578. test text-16.7 {DeleteChars procedure} {
  579.     setup
  580.     .t tag add sel 4.2 end
  581.     .t delete 4.2 end
  582.     list [.t tag ranges sel] [.t get 1.0 end]
  583. } {{} {Line 1
  584. abcde
  585. 12345
  586. Li
  587. }}
  588. test text-16.8 {DeleteChars procedure} {
  589.     setup
  590.     .t tag add sel 1.0 end
  591.     .t delete 4.0 end
  592.     list [.t tag ranges sel] [.t get 1.0 end]
  593. } {{1.0 3.5} {Line 1
  594. abcde
  595. 12345
  596. }}
  597. test text-16.9 {DeleteChars procedure} {
  598.     setup
  599.     .t delete 2.2 2.2
  600.     .t get 1.0 end
  601. } {Line 1
  602. abcde
  603. 12345
  604. Line 4
  605. }
  606. test text-16.10 {DeleteChars procedure} {
  607.     setup
  608.     .t delete 2.3 2.1
  609.     .t get 1.0 end
  610. } {Line 1
  611. abcde
  612. 12345
  613. Line 4
  614. }
  615. test text-16.11 {DeleteChars procedure} {
  616.     catch {destroy .t2}
  617.     toplevel .t2
  618.     text .t2.t -width 20 -height 5
  619.     pack append .t2 .t2.t top
  620.     wm geometry .t2 +0+0
  621.     .t2.t insert 1.0 "abc\n123\nx\ny\nz\nq\nr\ns"
  622.     update
  623.     .t2.t delete 1.0 3.0
  624.     list [.t2.t index @0,0] [.t2.t get @0,0]
  625. } {1.0 x}
  626. test text-16.12 {DeleteChars procedure} {
  627.     catch {destroy .t2}
  628.     toplevel .t2
  629.     text .t2.t -width 20 -height 5
  630.     pack append .t2 .t2.t top
  631.     wm geometry .t2 +0+0
  632.     .t2.t insert 1.0 "abc\n123\nx\ny\nz\nq\nr\ns"
  633.     .t2.t yview 3.0
  634.     update
  635.     .t2.t delete 2.0 4.0
  636.     list [.t2.t index @0,0] [.t2.t get @0,0]
  637. } {2.0 y}
  638. catch {destroy .t2}
  639. toplevel .t2
  640. text .t2.t -width 1 -height 10 -wrap char
  641. frame .t2.f -width 200 -height 20 -relief raised -bd 2
  642. pack .t2.f .t2.t -side left
  643. wm geometry .t2 +0+0
  644. update
  645. test text-16.13 {DeleteChars procedure, updates affecting topIndex} {
  646.     .t2.t delete 1.0 end
  647.     .t2.t insert end "abcde\n12345\nqrstuv"
  648.     .t2.t yview 2.1
  649.     .t2.t delete 1.4 2.3
  650.     .t2.t index @0,0
  651. } {1.2}
  652. test text-16.14 {DeleteChars procedure, updates affecting topIndex} {
  653.     .t2.t delete 1.0 end
  654.     .t2.t insert end "abcde\n12345\nqrstuv"
  655.     .t2.t yview 2.1
  656.     .t2.t delete 2.3 2.4
  657.     .t2.t index @0,0
  658. } {2.0}
  659. test text-16.15 {DeleteChars procedure, updates affecting topIndex} {
  660.     .t2.t delete 1.0 end
  661.     .t2.t insert end "abcde\n12345\nqrstuv"
  662.     .t2.t yview 1.3
  663.     .t2.t delete 1.0 1.2
  664.     .t2.t index @0,0
  665. } {1.1}
  666. test text-16.16 {DeleteChars procedure, updates affecting topIndex} {
  667.     catch {destroy .t2}
  668.     toplevel .t2
  669.     text .t2.t -width 6 -height 10 -wrap word
  670.     frame .t2.f -width 200 -height 20 -relief raised -bd 2
  671.     pack .t2.f .t2.t -side left
  672.     wm geometry .t2 +0+0
  673.     update
  674.     .t2.t insert end "abc def\n01 2345 678 9101112\nLine 3\nLine 4\nLine 5\n6\n7\n8\n"
  675.     .t2.t yview 2.4
  676.     .t2.t delete 2.5
  677.     set x [.t2.t index @0,0]
  678.     .t2.t delete 2.5
  679.     list $x [.t2.t index @0,0]
  680. } {2.3 2.0}
  681.  
  682. .t delete 1.0 end
  683. foreach i {a b c d e f g h i j k l m n o p q r s t u v w x y z} {
  684.     .t insert end $i.0$i.1$i.2$i.3$i.4\n
  685. }
  686. test text-17.1 {TextFetchSelection procedure} {
  687.     .t tag add sel 1.3 3.4
  688.     selection get
  689. } {a.1a.2a.3a.4
  690. b.0b.1b.2b.3b.4
  691. c.0c}
  692. test text-17.2 {TextFetchSelection procedure} {
  693.     .t tag add x 1.2
  694.     .t tag add x 1.4
  695.     .t tag add x 2.0
  696.     .t tag add x 2.3
  697.     .t tag remove sel 1.0 end
  698.     .t tag add sel 1.0 3.4
  699.     selection get
  700. } {a.0a.1a.2a.3a.4
  701. b.0b.1b.2b.3b.4
  702. c.0c}
  703. test text-17.3 {TextFetchSelection procedure} {
  704.     .t tag remove sel 1.0 end
  705.     .t tag add sel 13.3
  706.     selection get
  707. } {m}
  708. test text-17.4 {TextFetchSelection procedure} {
  709.     .t tag remove x 1.0 end
  710.     .t tag add sel 1.0 3.4
  711.     .t tag remove sel 1.0 end
  712.     .t tag add sel 1.2 1.5
  713.     .t tag add sel 2.4 3.1
  714.     .t tag add sel 10.0 10.end
  715.     .t tag add sel 13.3
  716.     selection get
  717. } {0a..1b.2b.3b.4
  718. cj.0j.1j.2j.3j.4m}
  719. set x ""
  720. for {set i 1} {$i < 200} {incr i} {
  721.     append x "This is line $i, padded to just about 53 characters.\n"
  722. }
  723. test text-17.5 {TextFetchSelection procedure, long selections} {
  724.     .t delete 1.0 end
  725.     .t insert end $x
  726.     .t tag add sel 1.0 end
  727.     selection get
  728. } $x\n
  729.  
  730. test text-18.1 {TkTextLostSelection procedure} {
  731.     catch {destroy .t2}
  732.     text .t2
  733.     .t2 insert 1.0 "abc\ndef\nghijk\n1234"
  734.     .t2 tag add sel 1.2 3.3
  735.     .t.e select to 1
  736.     .t2 tag ranges sel
  737. } {}
  738. catch {destroy .t2}
  739.  
  740. .t delete 1.0 end
  741. .t insert end "xxyz xyz x. the\nfoo -forward bar xxxxx BaR foo\nxyz xxyzx"
  742. test text-19.1 {TextSearchCmd procedure, argument parsing} {
  743.     list [catch {.t search -} msg] $msg
  744. } {1 {bad switch "-": must be -forward, -backward, -exact, -regexp, -nocase, -count, or --}}
  745. test text-19.2 {TextSearchCmd procedure, -backwards option} {
  746.     .t search -backwards xyz 1.4
  747. } {1.1}
  748. test text-19.3 {TextSearchCmd procedure, -forwards option} {
  749.     .t search -forwards xyz 1.4
  750. } {1.5}
  751. test text-19.4 {TextSearchCmd procedure, -exact option} {
  752.     .t search -f -exact x. 1.0
  753. } {1.9}
  754. test text-19.5 {TextSearchCmd procedure, -regexp option} {
  755.     .t search -b -regexp x.z 1.4
  756. } {1.1}
  757. test text-19.6 {TextSearchCmd procedure, -count option} {
  758.     set length unmodified
  759.     list [.t search -count length x. 1.4] $length
  760. } {1.9 2}
  761. test text-19.7 {TextSearchCmd procedure, -count option} {
  762.     list [catch {.t search -count} msg] $msg
  763. } {1 {no value given for "-count" option}}
  764. test text-19.8 {TextSearchCmd procedure, -nocase option} {
  765.     list [.t search -nocase BaR 1.1] [.t search BaR 1.1]
  766. } {2.13 2.23}
  767. test text-19.9 {TextSearchCmd procedure, -nocase option} {
  768.     .t search -n BaR 1.1
  769. } {2.13}
  770. test text-19.10 {TextSearchCmd procedure, -- option} {
  771.     .t search -- -forward 1.0
  772. } {2.4}
  773. test text-19.11 {TextSearchCmd procedure, argument parsing} {
  774.     list [catch {.t search abc} msg] $msg
  775. } {1 {wrong # args: should be ".t search ?switches? pattern index ?stopIndex?}}
  776. test text-19.12 {TextSearchCmd procedure, argument parsing} {
  777.     list [catch {.t search abc d e f} msg] $msg
  778. } {1 {wrong # args: should be ".t search ?switches? pattern index ?stopIndex?}}
  779. test text-19.13 {TextSearchCmd procedure, check index} {
  780.     list [catch {.t search abc gorp} msg] $msg
  781. } {1 {bad text index "gorp"}}
  782. test text-19.14 {TextSearchCmd procedure, startIndex == "end"} {
  783.     .t search non-existent end
  784. } {}
  785. test text-19.15 {TextSearchCmd procedure, startIndex == "end"} {
  786.     .t search non-existent end
  787. } {}
  788. test text-19.16 {TextSearchCmd procedure, bad stopIndex} {
  789.     list [catch {.t search abc 1.0 lousy} msg] $msg
  790. } {1 {bad text index "lousy"}}
  791. test text-19.17 {TextSearchCmd procedure, pattern case conversion} {
  792.     list [.t search -nocase BAR 1.1] [.t search BAR 1.1]
  793. } {2.13 {}}
  794. test text-19.18 {TextSearchCmd procedure, bad regular expression pattern} {
  795.     list [catch {.t search -regexp a( 1.0} msg] $msg
  796. } {1 {couldn't compile regular expression pattern: unmatched ()}}
  797. test text-19.19 {TextSearchCmd procedure, skip dummy last line} {
  798.     .t search \n end
  799. } {1.15}
  800. test text-19.20 {TextSearchCmd procedure, skip dummy last line} {
  801.     .t search -back \n 1.0
  802. } {3.9}
  803. test text-19.21 {TextSearchCmd procedure, extract line contents} {
  804.     .t tag add foo 1.2
  805.     .t tag add x 1.3
  806.     .t mark set silly 1.2
  807.     .t search xyz 3.6
  808. } {1.1}
  809. test text-19.22 {TextSearchCmd procedure, line case conversion} {
  810.     list [.t search -nocase bar 2.18] [.t search bar 2.18]
  811. } {2.23 2.13}
  812. test text-19.23 {TextSearchCmd procedure, stripping newlines} {
  813.     .t search the\n 1.0
  814. } {1.12}
  815. test text-19.24 {TextSearchCmd procedure, stripping newlines} {
  816.     .t search -regexp the\n 1.0
  817. } {}
  818. test text-19.25 {TextSearchCmd procedure, stripping newlines} {
  819.     .t search -regexp {the$} 1.0
  820. } {1.12}
  821. test text-19.26 {TextSearchCmd procedure, stripping newlines} {
  822.     .t search -regexp \n 1.0
  823. } {}
  824. test text-19.27 {TextSearchCmd procedure, firstChar and lastChar} {
  825.     .t search -backwards xyz 1.6
  826. } {1.5}
  827. test text-19.28 {TextSearchCmd procedure, firstChar and lastChar} {
  828.     .t search -backwards xyz 1.5
  829. } {1.1}
  830. test text-19.29 {TextSearchCmd procedure, firstChar and lastChar} {
  831.     .t search xyz 1.5
  832. } {1.5}
  833. test text-19.30 {TextSearchCmd procedure, firstChar and lastChar} {
  834.     .t search xyz 1.6
  835. } {3.0}
  836. test text-19.31 {TextSearchCmd procedure, firstChar and lastChar} {
  837.     .t search {} 1.end
  838. } {1.15}
  839. test text-19.32 {TextSearchCmd procedure, firstChar and lastChar} {
  840.     .t search f 1.end
  841. } {2.0}
  842. test text-19.33 {TextSearchCmd procedure, firstChar and lastChar} {
  843.     .t search {} end
  844. } {1.0}
  845. test text-19.34 {TextSearchCmd procedure, firstChar and lastChar} {
  846.     .t search -backwards forw 2.5
  847. } {2.5}
  848. test text-19.35 {TextSearchCmd procedure, firstChar and lastChar} {
  849.     .t search forw 2.5
  850. } {2.5}
  851. test text-19.36 {TextSearchCmd procedure, firstChar and lastChar} {
  852.     catch {destroy .t2}
  853.     text .t2
  854.     list [.t2 search a 1.0] [.t2 search -backward a 1.0]
  855. } {{} {}}
  856. test text-19.37 {TextSearchCmd procedure, regexp match length} {
  857.     set length unchanged
  858.     list [.t search -regexp -count length x(.)(.*)z 1.1] $length
  859. } {1.1 7}
  860. test text-19.38 {TextSearchCmd procedure, regexp match length} {
  861.     set length unchanged
  862.     list [.t search -regexp -backward -count length fo* 2.5] $length
  863. } {2.0 3}
  864. test text-19.39 {TextSearchCmd procedure, checking stopIndex} {
  865.     list [.t search bar 2.1 2.13] [.t search bar 2.1 2.14] \
  866.         [.t search bar 2.12 2.14] [.t search bar 2.14 2.14]
  867. } {{} 2.13 2.13 {}}
  868. test text-19.40 {TextSearchCmd procedure, checking stopIndex} {
  869.     list [.t search -backwards bar 2.20 2.13] \
  870.         [.t search -backwards bar 2.20 2.14] \
  871.         [.t search -backwards bar 2.14 2.13] \
  872.         [.t search -backwards bar 2.13 2.13]
  873. } {2.13 {} 2.13 {}}
  874. test text-19.41 {TextSearchCmd procedure, embedded windows and index/count} {
  875.     frame .t.f1 -width 20 -height 20 -relief raised -bd 2
  876.     frame .t.f2 -width 20 -height 20 -relief raised -bd 2
  877.     frame .t.f3 -width 20 -height 20 -relief raised -bd 2
  878.     frame .t.f4 -width 20 -height 20 -relief raised -bd 2
  879.     .t window create 2.10 -window .t.f3
  880.     .t window create 2.8 -window .t.f2
  881.     .t window create 2.8 -window .t.f1
  882.     .t window create 2.1 -window .t.f4
  883.     set result ""
  884.     lappend result [.t search -count x forward 1.0] $x
  885.     lappend result [.t search -count x wa 1.0] $x
  886.     .t delete 2.1
  887.     .t delete 2.8 2.10
  888.     .t delete 2.10
  889.     set result
  890. } {2.6 10 2.11 2}
  891. test text-19.42 {TextSearchCmd procedure, error setting variable} {
  892.     catch {unset a}
  893.     set a 44
  894.     list [catch {.t search -count a(2) xyz 1.0} msg] $msg
  895. } {1 {can't set "a(2)": variable isn't array}}
  896. test text-19.43 {TextSearchCmd procedure, wrap-around} {
  897.     .t search -backwards xyz 1.1
  898. } {3.5}
  899. test text-19.44 {TextSearchCmd procedure, wrap-around} {
  900.     .t search -backwards xyz 1.1 1.0
  901. } {}
  902. test text-19.45 {TextSearchCmd procedure, wrap-around} {
  903.     .t search xyz 3.6
  904. } {1.1}
  905. test text-19.46 {TextSearchCmd procedure, wrap-around} {
  906.     .t search xyz 3.6 end
  907. } {}
  908. test text-19.47 {TextSearchCmd procedure, no match} {
  909.     .t search non_existent 3.5
  910. } {}
  911. test text-19.48 {TextSearchCmd procedure, no match} {
  912.     .t search -regexp non_existent 3.5
  913. } {}
  914. test text-19.49 {TextSearchCmd procedure, special cases} {
  915.     .t search -back x 1.1
  916. } {1.0}
  917. test text-19.50 {TextSearchCmd procedure, special cases} {
  918.     .t search -back x 1.0
  919. } {3.8}
  920. test text-19.51 {TextSearchCmd procedure, special cases} {
  921.     .t search \n {end-2c}
  922. } {3.9}
  923. test text-19.52 {TextSearchCmd procedure, special cases} {
  924.     .t search \n end
  925. } {1.15}
  926. test text-19.53 {TextSearchCmd procedure, special cases} {
  927.     .t search x 1.0
  928. } {1.0}
  929. test text-19.54 {TextSearchCmd, freeing copy of pattern} {
  930.     # This test doesn't return a result, but it will generate
  931.     # a core leak if the pattern copy isn't properly freed.
  932.  
  933.     set p abcdefg1234567890
  934.     set p $p$p$p$p$p$p$p$p
  935.     set p $p$p$p$p$p
  936.     .t search -nocase $p 1.0
  937. } {}
  938.  
  939. eval destroy [winfo child .]
  940. text .t2 -highlightthickness 0 -bd 0 -relief flat -padx 0
  941. pack .t2
  942. .t2 insert end "1\t2\t3\t4\t55.5"
  943. test text-20.1 {TkTextGetTabs procedure} {
  944.     list [catch {.t2 configure -tabs "\{{}"} msg] $msg
  945. } {1 {unmatched open brace in list}}
  946. test text-20.2 {TkTextGetTabs procedure} {
  947.     list [catch {.t2 configure -tabs xyz} msg] $msg
  948. } {1 {bad screen distance "xyz"}}
  949. test text-20.3 {TkTextGetTabs procedure} {
  950.     .t2 configure -tabs {100 200}
  951.     update idletasks
  952.     list [lindex [.t2 bbox 1.2] 0] [lindex [.t2 bbox 1.4] 0]
  953. } {100 200}
  954. test text-20.4 {TkTextGetTabs procedure} {
  955.     .t2 configure -tabs {100 right 200 left 300 center 400 numeric}
  956.     update idletasks
  957.     list [expr [lindex [.t2 bbox 1.2] 0] + [lindex [.t2 bbox 1.2] 2]] \
  958.         [lindex [.t2 bbox 1.4] 0] \
  959.         [expr [lindex [.t2 bbox 1.6] 0] + [lindex [.t2 bbox 1.6] 2]/2] \
  960.         [lindex [.t2 bbox 1.10] 0]
  961. } {100 200 300 400}
  962. test text-20.5 {TkTextGetTabs procedure} {
  963.     .t2 configure -tabs {105 r 205 l 305 c 405 n}
  964.     update idletasks
  965.     list [expr [lindex [.t2 bbox 1.2] 0] + [lindex [.t2 bbox 1.2] 2]] \
  966.         [lindex [.t2 bbox 1.4] 0] \
  967.         [expr [lindex [.t2 bbox 1.6] 0] + [lindex [.t2 bbox 1.6] 2]/2] \
  968.         [lindex [.t2 bbox 1.10] 0]
  969. } {105 205 305 405}
  970. test text-20.6 {TkTextGetTabs procedure} {
  971.     list [catch {.t2 configure -tabs {100 left 200 lork}} msg] $msg
  972. } {1 {bad tab alignment "lork": must be left, right, center, or numeric}}
  973. test text-20.7 {TkTextGetTabs procedure} {
  974.     list [catch {.t2 configure -tabs {100 !44 200 lork}} msg] $msg
  975. } {1 {bad screen distance "!44"}}
  976.  
  977. destroy .t2
  978.