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

  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. #
  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. # @(#) textIndex.test 1.6 95/06/28 16:14:29
  11.  
  12. if {[string compare test [info procs test]] == 1} then \
  13.   {source defs}
  14.  
  15. catch {destroy .t}
  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. .t insert 1.0 "Line 1
  37. abcdefghijklm
  38. 12345
  39. Line 4
  40. bOy GIrl .#@? x_yz
  41. !@#$%
  42. Line 7"
  43.  
  44. test textIndex-1.1 {TkTextMakeIndex} {
  45.     .t index -1.3
  46. } 1.0
  47. test textIndex-1.2 {TkTextMakeIndex} {
  48.     .t index 0.3
  49. } 1.0
  50. test textIndex-1.3 {TkTextMakeIndex} {
  51.     .t index 1.3
  52. } 1.3
  53. test textIndex-1.4 {TkTextMakeIndex} {
  54.     .t index 3.-1
  55. } 3.0
  56. test textIndex-1.5 {TkTextMakeIndex} {
  57.     .t index 3.3
  58. } 3.3
  59. test textIndex-1.6 {TkTextMakeIndex} {
  60.     .t index 3.5
  61. } 3.5
  62. test textIndex-1.7 {TkTextMakeIndex} {
  63.     .t index 3.6
  64. } 3.5
  65. test textIndex-1.8 {TkTextMakeIndex} {
  66.     .t index 3.7
  67. } 3.5
  68. test textIndex-1.9 {TkTextMakeIndex} {
  69.     .t index 7.2
  70. } 7.2
  71. test textIndex-1.10 {TkTextMakeIndex} {
  72.     .t index 8.0
  73. } 8.0
  74. test textIndex-1.11 {TkTextMakeIndex} {
  75.     .t index 8.1
  76. } 8.0
  77. test textIndex-1.12 {TkTextMakeIndex} {
  78.     .t index 9.0
  79. } 8.0
  80.  
  81. .t tag add x 2.3 2.6
  82. test textIndex-2.1 {TkTextIndexToSeg} {
  83.     .t get 2.0
  84. } a
  85. test textIndex-2.2 {TkTextIndexToSeg} {
  86.     .t get 2.2
  87. } c
  88. test textIndex-2.3 {TkTextIndexToSeg} {
  89.     .t get 2.3
  90. } d
  91. test textIndex-2.4 {TkTextIndexToSeg} {
  92.     .t get 2.6
  93. } g
  94. test textIndex-2.5 {TkTextIndexToSeg} {
  95.     .t get 2.7
  96. } h
  97. test textIndex-2.6 {TkTextIndexToSeg} {
  98.     .t get 2.12
  99. } m
  100. test textIndex-2.7 {TkTextIndexToSeg} {
  101.     .t get 2.13
  102. } \n
  103. test textIndex-2.8 {TkTextIndexToSeg} {
  104.     .t get 2.14
  105. } \n
  106. .t tag delete x
  107.  
  108. .t mark set foo 3.2
  109. .t tag add x 2.8 2.11
  110. .t tag add x 6.0 6.2
  111. set weirdTag "funny . +- 22.1\n\t{"
  112. .t tag add $weirdTag 2.1  2.6
  113. set weirdMark "asdf \n{-+ 66.2\t"
  114. .t mark set $weirdMark 4.0
  115. .t tag config y -relief raised
  116. test textIndex-3.1 {TkTextGetIndex, weird mark names} {
  117.     list [catch {.t index $weirdMark} msg] $msg
  118. } {0 4.0}
  119.  
  120. test textIndex-4.1 {TkTextGetIndex, tags} {
  121.     list [catch {.t index x.first} msg] $msg
  122. } {0 2.8}
  123. test textIndex-4.2 {TkTextGetIndex, tags} {
  124.     list [catch {.t index x.last} msg] $msg
  125. } {0 6.2}
  126. test textIndex-4.3 {TkTextGetIndex, weird tags} {
  127.     list [.t index $weirdTag.first+1c] [.t index $weirdTag.last+2c]
  128. } {2.2 2.8}
  129. test textIndex-4.4 {TkTextGetIndex, tags} {
  130.     list [catch {.t index x.gorp} msg] $msg
  131. } {1 {bad text index "x.gorp"}}
  132. test textIndex-4.5 {TkTextGetIndex, tags} {
  133.     list [catch {.t index foo.last} msg] $msg
  134. } {1 {bad text index "foo.last"}}
  135. test textIndex-4.6 {TkTextGetIndex, tags} {
  136.     list [catch {.t index y.first} msg] $msg
  137. } {1 {text doesn't contain any characters tagged with "y"}}
  138. test textIndex-4.7 {TkTextGetIndex, tags} {
  139.     list [catch {.t index x.last,} msg] $msg
  140. } {1 {bad text index "x.last,"}}
  141. test textIndex-4.8 {TkTextGetIndex, tags} {
  142.     .t tag add z 1.0
  143.     set result [list [.t index z.first] [.t index z.last]]
  144.     .t tag delete z
  145.     set result
  146. } {1.0 1.1}
  147.  
  148. if $doNonPortableTests {
  149.     test textIndex-5.1 {TkTextGetIndex, "@"} {
  150.     .t index @12,9
  151.     } 1.1
  152.     test textIndex-5.2 {TkTextGetIndex, "@"} {
  153.     .t index @-2,7
  154.     } 1.0
  155.     test textIndex-5.3 {TkTextGetIndex, "@"} {
  156.     .t index @10,-7
  157.     } 1.0
  158.     test textIndex-5.4 {TkTextGetIndex, "@"} {
  159.     list [catch {.t index @x} msg] $msg
  160.     } {1 {bad text index "@x"}}
  161.     test textIndex-5.5 {TkTextGetIndex, "@"} {
  162.     list [catch {.t index @10q} msg] $msg
  163.     } {1 {bad text index "@10q"}}
  164.     test textIndex-5.6 {TkTextGetIndex, "@"} {
  165.     list [catch {.t index @10,} msg] $msg
  166.     } {1 {bad text index "@10,"}}
  167.     test textIndex-5.7 {TkTextGetIndex, "@"} {
  168.     list [catch {.t index @10,a} msg] $msg
  169.     } {1 {bad text index "@10,a"}}
  170.     test textIndex-5.8 {TkTextGetIndex, "@"} {
  171.     list [catch {.t index @10,9,} msg] $msg
  172.     } {1 {bad text index "@10,9,"}}
  173. }
  174.  
  175. test textIndex-6.1 {TkTextGetIndex, numeric} {
  176.     list [catch {.t index 2.3} msg] $msg
  177. } {0 2.3}
  178. test textIndex-6.2 {TkTextGetIndex, numeric} {
  179.     list [catch {.t index -} msg] $msg
  180. } {1 {bad text index "-"}}
  181. test textIndex-6.3 {TkTextGetIndex, numeric} {
  182.     list [catch {.t index 2.end} msg] $msg
  183. } {0 2.13}
  184. test textIndex-6.4 {TkTextGetIndex, numeric} {
  185.     list [catch {.t index 2.x} msg] $msg
  186. } {1 {bad text index "2.x"}}
  187. test textIndex-6.5 {TkTextGetIndex, numeric} {
  188.     list [catch {.t index 2.3x} msg] $msg
  189. } {1 {bad text index "2.3x"}}
  190.  
  191. test textIndex-7.1 {TkTextGetIndex, miscellaneous other bases} {
  192.     list [catch {.t index end} msg] $msg
  193. } {0 8.0}
  194. test textIndex-7.2 {TkTextGetIndex, miscellaneous other bases} {
  195.     list [catch {.t index foo} msg] $msg
  196. } {0 3.2}
  197. test textIndex-7.3 {TkTextGetIndex, miscellaneous other bases} {
  198.     list [catch {.t index foo+1c} msg] $msg
  199. } {0 3.3}
  200.  
  201. test textIndex-8.1 {TkTextGetIndex, modifiers} {
  202.     list [catch {.t index 2.1+1char} msg] $msg
  203. } {0 2.2}
  204. test textIndex-8.2 {TkTextGetIndex, modifiers} {
  205.     list [catch {.t index "2.1      +1char"} msg] $msg
  206. } {0 2.2}
  207. test textIndex-8.3 {TkTextGetIndex, modifiers} {
  208.     list [catch {.t index 2.1-1char} msg] $msg
  209. } {0 2.0}
  210. test textIndex-8.4 {TkTextGetIndex, modifiers} {
  211.     list [catch {.t index {2.1  }} msg] $msg
  212. } {0 2.1}
  213. test textIndex-8.5 {TkTextGetIndex, modifiers} {
  214.     list [catch {.t index {2.1+foo bar}} msg] $msg
  215. } {1 {bad text index "2.1+foo bar"}}
  216. test textIndex-8.6 {TkTextGetIndex, modifiers} {
  217.     list [catch {.t index {2.1 foo bar}} msg] $msg
  218. } {1 {bad text index "2.1 foo bar"}}
  219.  
  220. test textIndex-9.1 {TkTextIndexCmp} {
  221.     list [.t compare 3.1 < 3.2] [.t compare 3.1 == 3.2]
  222. } {1 0}
  223. test textIndex-9.2 {TkTextIndexCmp} {
  224.     list [.t compare 3.2 < 3.2] [.t compare 3.2 == 3.2]
  225. } {0 1}
  226. test textIndex-9.3 {TkTextIndexCmp} {
  227.     list [.t compare 3.3 < 3.2] [.t compare 3.3 == 3.2]
  228. } {0 0}
  229. test textIndex-9.4 {TkTextIndexCmp} {
  230.     list [.t compare 2.1 < 3.2] [.t compare 2.1 == 3.2]
  231. } {1 0}
  232. test textIndex-9.5 {TkTextIndexCmp} {
  233.     list [.t compare 4.1 < 3.2] [.t compare 4.1 == 3.2]
  234. } {0 0}
  235.  
  236. test textIndex-10.1 {ForwBack} {
  237.     list [catch {.t index {2.3 + x}} msg] $msg
  238. } {1 {bad text index "2.3 + x"}}
  239. test textIndex-10.2 {ForwBack} {
  240.     list [catch {.t index {2.3 + 2 chars}} msg] $msg
  241. } {0 2.5}
  242. test textIndex-10.3 {ForwBack} {
  243.     list [catch {.t index {2.3 + 2c}} msg] $msg
  244. } {0 2.5}
  245. test textIndex-10.4 {ForwBack} {
  246.     list [catch {.t index {2.3 - 3ch}} msg] $msg
  247. } {0 2.0}
  248. test textIndex-10.5 {ForwBack} {
  249.     list [catch {.t index {2.3 + 3 lines}} msg] $msg
  250. } {0 5.3}
  251. test textIndex-10.6 {ForwBack} {
  252.     list [catch {.t index {2.3 -1l}} msg] $msg
  253. } {0 1.3}
  254. test textIndex-10.7 {ForwBack} {
  255.     list [catch {.t index {2.3 -1 gorp}} msg] $msg
  256. } {1 {bad text index "2.3 -1 gorp"}}
  257. test textIndex-10.8 {ForwBack} {
  258.     list [catch {.t index {2.3 - 4 lines}} msg] $msg
  259. } {0 1.3}
  260.  
  261. test textIndex-11.1 {TkTextIndexForwChars} {
  262.     .t index {2.3 + -7 chars}
  263. } 1.3
  264. test textIndex-11.2 {TkTextIndexForwChars} {
  265.     .t index {2.3 + 5 chars}
  266. } 2.8
  267. test textIndex-11.3 {TkTextIndexForwChars} {
  268.     .t index {2.3 + 10 chars}
  269. } 2.13
  270. test textIndex-11.4 {TkTextIndexForwChars} {
  271.     .t index {2.3 + 11 chars}
  272. } 3.0
  273. test textIndex-11.5 {TkTextIndexForwChars} {
  274.     .t index {2.3 + 55 chars}
  275. } 7.6
  276. test textIndex-11.6 {TkTextIndexForwChars} {
  277.     .t index {2.3 + 56 chars}
  278. } 8.0
  279. test textIndex-11.7 {TkTextIndexForwChars} {
  280.     .t index {2.3 + 57 chars}
  281. } 8.0
  282.  
  283. test textIndex-12.1 {TkTextIndexBackChars} {
  284.     .t index {3.2 - -10 chars}
  285. } 4.6
  286. test textIndex-12.2 {TkTextIndexBackChars} {
  287.     .t index {3.2 - 2 chars}
  288. } 3.0
  289. test textIndex-12.3 {TkTextIndexBackChars} {
  290.     .t index {3.2 - 3 chars}
  291. } 2.13
  292. test textIndex-12.4 {TkTextIndexBackChars} {
  293.     .t index {3.2 - 22 chars}
  294. } 1.1
  295. test textIndex-12.5 {TkTextIndexBackChars} {
  296.     .t index {3.2 - 23 chars}
  297. } 1.0
  298. test textIndex-12.6 {TkTextIndexBackChars} {
  299.     .t index {3.2 - 24 chars}
  300. } 1.0
  301.  
  302. proc getword index {
  303.     .t get [.t index "$index wordstart"] [.t index "$index wordend"]
  304. }
  305. test textIndex-13.1 {StartEnd} {
  306.     list [catch {.t index {2.3 lineend}} msg] $msg
  307. } {0 2.13}
  308. test textIndex-13.2 {StartEnd} {
  309.     list [catch {.t index {2.3 linee}} msg] $msg
  310. } {0 2.13}
  311. test textIndex-13.3 {StartEnd} {
  312.     list [catch {.t index {2.3 line}} msg] $msg
  313. } {1 {bad text index "2.3 line"}}
  314. test textIndex-13.4 {StartEnd} {
  315.     list [catch {.t index {2.3 linestart}} msg] $msg
  316. } {0 2.0}
  317. test textIndex-13.5 {StartEnd} {
  318.     list [catch {.t index {2.3 lines}} msg] $msg
  319. } {0 2.0}
  320. test textIndex-13.6 {StartEnd} {
  321.     getword 5.3
  322. } { }
  323. test textIndex-13.7 {StartEnd} {
  324.     getword 5.4
  325. } GIrl
  326. test textIndex-13.8 {StartEnd} {
  327.     getword 5.7
  328. } GIrl
  329. test textIndex-13.9 {StartEnd} {
  330.     getword 5.8
  331. } { }
  332. test textIndex-13.10 {StartEnd} {
  333.     getword 5.14
  334. } x_yz
  335. test textIndex-13.11 {StartEnd} {
  336.     getword 6.2
  337. } #
  338. test textIndex-13.12 {StartEnd} {
  339.     getword 3.4
  340. } 12345
  341. .t tag add x 2.8 2.11
  342. test textIndex-13.13 {StartEnd} {
  343.     list [catch {.t index {2.2 worde}} msg] $msg
  344. } {0 2.13}
  345. test textIndex-13.14 {StartEnd} {
  346.     list [catch {.t index {2.12 words}} msg] $msg
  347. } {0 2.0}
  348. test textIndex-13.15 {StartEnd} {
  349.     list [catch {.t index {2.12 word}} msg] $msg
  350. } {1 {bad text index "2.12 word"}}
  351.  
  352. catch {destroy .t}
  353. concat
  354.