home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tk8.0 / tests / textMark.test < prev    next >
Encoding:
Text File  |  1997-08-15  |  6.6 KB  |  220 lines  |  [TEXT/ALFA]

  1. # This file is a Tcl script to test the code in the file tkTextMark.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. # SCCS: @(#) textMark.test 1.7 96/06/24 16:47:04
  11.  
  12. if {[string compare test [info procs test]] == 1} then \
  13.   {source defs}
  14.  
  15. catch {destroy .t}
  16. if [catch {text .t -font {Courier 12} -width 20 -height 10}] {
  17.     puts "The font needed by these tests isn't available, so I'm"
  18.     puts "going to skip the tests."
  19.     return
  20. }
  21. pack append . .t {top expand fill}
  22. update
  23. .t debug on
  24. wm geometry . {}
  25.   
  26. # The statements below reset the main window;  it's needed if the window
  27. # manager is mwm to make mwm forget about a previous minimum size setting.
  28.  
  29. wm withdraw .
  30. wm minsize . 1 1
  31. wm positionfrom . user
  32. wm deiconify .
  33.  
  34. entry .t.e
  35. .t insert 1.0 "Line 1
  36. abcdefghijklm
  37. 12345
  38. Line 4
  39. bOy GIrl .#@? x_yz
  40. !@#$%
  41. Line 7"
  42.  
  43. test textMark-1.1 {TkTextMarkCmd - missing option} {
  44.     list [catch {.t mark} msg] $msg
  45. } {1 {wrong # args: should be ".t mark option ?arg arg ...?"}}
  46. test textMark-1.2 {TkTextMarkCmd - bogus option} {
  47.     list [catch {.t mark gorp} msg] $msg
  48. } {1 {bad mark option "gorp": must be gravity, names, next, previous, set, or unset}}
  49. test textMark-1.3 {TkTextMarkCmd - "gravity" option} {
  50.     list [catch {.t mark gravity foo} msg] $msg
  51. } {1 {there is no mark named "foo"}}
  52. test textMark-1.4 {TkTextMarkCmd - "gravity" option} {
  53.     .t mark unset x
  54.     .t mark set x 1.3
  55.     .t insert 1.3 x
  56.     list [.t mark gravity x] [.t index x]
  57. } {right 1.4}
  58. test textMark-1.5 {TkTextMarkCmd - "gravity" option} {
  59.     .t mark unset x
  60.     .t mark set x 1.3
  61.     .t mark g x left
  62.     .t insert 1.3 x
  63.     list [.t mark gravity x] [.t index x]
  64. } {left 1.3}
  65. test textMark-1.6 {TkTextMarkCmd - "gravity" option} {
  66.     .t mark unset x
  67.     .t mark set x 1.3
  68.     .t mark gravity x right
  69.     .t insert 1.3 x
  70.     list [.t mark gravity x] [.t index x]
  71. } {right 1.4}
  72. test textMark-1.7 {TkTextMarkCmd - "gravity" option} {
  73.     list [catch {.t mark gravity x gorp} msg] $msg
  74. } {1 {bad mark gravity "gorp": must be left or right}}
  75.  
  76. test textMark-2.1 {TkTextMarkCmd - "names" option} {
  77.     list [catch {.t mark names 2} msg] $msg
  78. } {1 {wrong # args: should be ".t mark names"}}
  79. .t mark unset x
  80. test textMark-2.2 {TkTextMarkCmd - "names" option} {
  81.     lsort [.t mark n]
  82. } {current insert}
  83. test textMark-2.3 {TkTextMarkCmd - "names" option} {
  84.     .t mark set a 1.1
  85.     .t mark set "b c" 2.3
  86.     lsort [.t mark names]
  87. } {a {b c} current insert}
  88.  
  89. test textMark-3.1 {TkTextMarkCmd - "set" option} {
  90.     list [catch {.t mark set a} msg] $msg
  91. } {1 {wrong # args: should be ".t mark set markName index"}}
  92. test textMark-3.2 {TkTextMarkCmd - "set" option} {
  93.     list [catch {.t mark s a b c} msg] $msg
  94. } {1 {wrong # args: should be ".t mark set markName index"}}
  95. test textMark-3.3 {TkTextMarkCmd - "set" option} {
  96.     list [catch {.t mark set a @x} msg] $msg
  97. } {1 {bad text index "@x"}}
  98. test textMark-3.4 {TkTextMarkCmd - "set" option} {
  99.     .t mark set a 1.2
  100.     .t index a
  101. } 1.2
  102. test textMark-3.5 {TkTextMarkCmd - "set" option} {
  103.     .t mark set a end
  104.     .t index a
  105. } {8.0}
  106.  
  107. test textMark-4.1 {TkTextMarkCmd - "unset" option} {
  108.     list [catch {.t mark unset} msg] $msg
  109. } {0 {}}
  110. test textMark-4.2 {TkTextMarkCmd - "unset" option} {
  111.     .t mark set a 1.2
  112.     .t mark set b 2.3
  113.     .t mark unset a b
  114.         list [catch {.t index a} msg] $msg [catch {.t index b} msg2] $msg2
  115. } {1 {bad text index "a"} 1 {bad text index "b"}}
  116. test textMark-4.3 {TkTextMarkCmd - "unset" option} {
  117.     .t mark set a 1.2
  118.     .t mark set b 2.3
  119.     .t mark set 49ers 3.1
  120.     eval .t mark unset [.t mark names]
  121.     lsort [.t mark names]
  122. } {current insert}
  123.  
  124. test textMark-5.1 {TkTextMarkCmd - miscellaneous} {
  125.     list [catch {.t mark} msg] $msg
  126. } {1 {wrong # args: should be ".t mark option ?arg arg ...?"}}
  127. test textMark-5.2 {TkTextMarkCmd - miscellaneous} {
  128.     list [catch {.t mark foo} msg] $msg
  129. } {1 {bad mark option "foo": must be gravity, names, next, previous, set, or unset}}
  130.  
  131. test textMark-6.1 {TkTextMarkSegToIndex} {
  132.     .t mark set a 1.2
  133.     .t mark set b 1.2
  134.     .t mark set c 1.2
  135.     .t mark set d 1.4
  136.     list [.t index a] [.t index b] [.t index c ] [.t index d]
  137. } {1.2 1.2 1.2 1.4}
  138.  
  139. catch {eval {.t mark unset} [.t mark names]}
  140. test textMark-7.1 {MarkFindNext - invalid mark name} {
  141.     catch {.t mark next bogus} x
  142.     set x
  143. } {bad text index "bogus"}
  144. test textMark-7.2 {MarkFindNext - marks at same location} {
  145.     .t mark set insert 2.0
  146.     .t mark set current 2.0
  147.     .t mark next current
  148. } {insert}
  149. test textMark-7.3 {MarkFindNext - numerical starting mark} {
  150.     .t mark set current 1.0
  151.     .t mark set insert 1.0
  152.     .t mark next 1.0
  153. } {insert}
  154. test textMark-7.4 {MarkFindNext - mark on the same line} {
  155.     .t mark set current 1.0
  156.     .t mark set insert 1.1
  157.     .t mark next current
  158. } {insert}
  159. test textMark-7.5 {MarkFindNext - mark on the next line} {
  160.     .t mark set current 1.end
  161.     .t mark set insert 2.0
  162.     .t mark next current
  163. } {insert}
  164. test textMark-7.6 {MarkFindNext - mark far away} {
  165.     .t mark set current 1.2
  166.     .t mark set insert 7.0
  167.     .t mark next current
  168. } {insert}
  169. test textMark-7.7 {MarkFindNext - mark on top of end} {
  170.     .t mark set current end
  171.     .t mark next end
  172. } {current}
  173. test textMark-7.8 {MarkFindNext - no next mark} {
  174.     .t mark set current 1.0
  175.     .t mark set insert 3.0
  176.     .t mark next insert
  177. } {}
  178. test textMark-8.1 {MarkFindPrev - invalid mark name} {
  179.     catch {.t mark prev bogus} x
  180.     set x
  181. } {bad text index "bogus"}
  182. test textMark-8.2 {MarkFindPrev - marks at same location} {
  183.     .t mark set insert 2.0
  184.     .t mark set current 2.0
  185.     .t mark prev insert
  186. } {current}
  187. test textMark-8.3 {MarkFindPrev - numerical starting mark} {
  188.     .t mark set current 1.0
  189.     .t mark set insert 1.0
  190.     .t mark prev 1.1
  191. } {current}
  192. test textMark-8.4 {MarkFindPrev - mark on the same line} {
  193.     .t mark set current 1.0
  194.     .t mark set insert 1.1
  195.     .t mark prev insert
  196. } {current}
  197. test textMark-8.5 {MarkFindPrev - mark on the previous line} {
  198.     .t mark set current 1.end
  199.     .t mark set insert 2.0
  200.     .t mark prev insert
  201. } {current}
  202. test textMark-8.6 {MarkFindPrev - mark far away} {
  203.     .t mark set current 1.2
  204.     .t mark set insert 7.0
  205.     .t mark prev insert
  206. } {current}
  207. test textMark-8.7 {MarkFindPrev - mark on top of end} {
  208.     .t mark set insert 3.0
  209.     .t mark set current end
  210.     .t mark prev end
  211. } {insert}
  212. test textMark-8.8 {MarkFindPrev - no previous mark} {
  213.     .t mark set current 1.0
  214.     .t mark set insert 3.0
  215.     .t mark prev current
  216. } {}
  217.  
  218. catch {destroy .t}
  219. concat {}
  220.