history.test
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:7k
源码类别:

通讯编程

开发平台:

Visual C++

  1. # Commands covered:  history
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # Copyright (c) 1994 Sun Microsystems, Inc.
  9. # Copyright (c) 1998-1999 by Scriptics Corporation.
  10. #
  11. # See the file "license.terms" for information on usage and redistribution
  12. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13. #
  14. # RCS: @(#) $Id: history.test,v 1.5 2000/04/10 17:18:59 ericm Exp $
  15.   
  16. if {[lsearch [namespace children] ::tcltest] == -1} {
  17.     package require tcltest
  18.     namespace import -force ::tcltest::*
  19. }
  20. if {[catch {history}]} {
  21.     puts stdout "This version of Tcl was built without the history command;n"
  22.     puts stdout "history tests will be skipped.n"
  23.     ::tcltest::cleanupTests
  24.     return
  25. }
  26. set num [history nextid]
  27. history keep 3
  28. history add {set a 12345}
  29. history add {set b [format {A test %s} string]}
  30. history add {Another test}
  31. # "history event"
  32. test history-1.1 {event option} {history event -1} 
  33. {set b [format {A test %s} string]}
  34. test history-1.2 {event option} {history event $num} 
  35. {set a 12345}
  36. test history-1.3 {event option} {history event [expr $num+2]} 
  37. {Another test}
  38. test history-1.4 {event option} {history event set} 
  39. {set b [format {A test %s} string]}
  40. test history-1.5 {event option} {history e "* a*"} 
  41. {set a 12345}
  42. test history-1.6 {event option} {catch {history event *gorp} msg} 1
  43. test history-1.7 {event option} {
  44.     catch {history event *gorp} msg
  45.     set msg
  46. } {no event matches "*gorp"}
  47. test history-1.8 {event option} {history event} 
  48. {set b [format {A test %s} string]}
  49. test history-1.9 {event option} {catch {history event 123 456} msg} 1
  50. test history-1.10 {event option} {
  51.     catch {history event 123 456} msg
  52.     set msg
  53. } {wrong # args: should be "history event ?event?"}
  54. # "history redo"
  55. set a 0
  56. history redo -2
  57. test history-2.1 {redo option} {set a} 12345
  58. set b 0
  59. history redo
  60. test history-2.2 {redo option} {set b} {A test string}
  61. test history-2.3 {redo option} {catch {history redo -3 -4}} 1
  62. test history-2.4 {redo option} {
  63.     catch {history redo -3 -4} msg
  64.     set msg
  65. } {wrong # args: should be "history redo ?event?"}
  66. # "history add"
  67. history add "set a 444" exec
  68. test history-3.1 {add option} {set a} 444
  69. test history-3.2 {add option} {catch {history add "set a 444" execGorp}} 1
  70. test history-3.3 {add option} {
  71.     catch {history add "set a 444" execGorp} msg
  72.     set msg
  73. } {bad argument "execGorp": should be "exec"}
  74. test history-3.4 {add option} {catch {history add "set a 444" a} msg} 1
  75. test history-3.5 {add option} {
  76.     catch {history add "set a 444" a} msg
  77.     set msg
  78. } {bad argument "a": should be "exec"}
  79. history add "set a 555" e
  80. test history-3.6 {add option} {set a} 555
  81. history add "set a 666"
  82. test history-3.7 {add option} {set a} 555
  83. test history-3.8 {add option} {catch {history add "set a 666" e f} msg} 1
  84. test history-3.9 {add option} {
  85.     catch {history add "set a 666" e f} msg
  86.     set msg
  87. } {wrong # args: should be "history add event ?exec?"}
  88. # "history change"
  89. history change "A test value"
  90. test history-4.1 {change option} {history event [expr {[history n]-1}]} 
  91. "A test value"
  92. history ch "Another test" -1
  93. test history-4.2 {change option} {history e} "Another test"
  94. test history-4.3 {change option} {history event [expr {[history n]-1}]} 
  95. "A test value"
  96. test history-4.4 {change option} {catch {history change Foo 4 10}} 1
  97. test history-4.5 {change option} {
  98.     catch {history change Foo 4 10} msg
  99.     set msg
  100. } {wrong # args: should be "history change newValue ?event?"}
  101. test history-4.6 {change option} {
  102.     catch {history change Foo [expr {[history n]-4}]}
  103. } 1
  104. set num [expr {[history n]-4}]
  105. test history-4.7 {change option} {
  106.     catch {history change Foo $num} msg
  107.     set msg
  108. } "event "$num" is too far in the past"
  109. # "history info"
  110. set num [history n]
  111. history add set a {bnc d e}
  112. history add {set b 1234}
  113. history add set c {anbnc}
  114. test history-5.1 {info option} {history info} [format {%6d  set a {b
  115. c d e}
  116. %6d  set b 1234
  117. %6d  set c {a
  118. b
  119. c}} $num [expr $num+1] [expr $num+2]]
  120. test history-5.2 {info option} {history i 2} [format {%6d  set b 1234
  121. %6d  set c {a
  122. b
  123. c}} [expr $num+1] [expr $num+2]]
  124. test history-5.3 {info option} {catch {history i 2 3}} 1
  125. test history-5.4 {info option} {
  126.     catch {history i 2 3} msg
  127.     set msg
  128. } {wrong # args: should be "history info ?count?"}
  129. test history-5.5 {info option} {history} [format {%6d  set a {b
  130. c d e}
  131. %6d  set b 1234
  132. %6d  set c {a
  133. b
  134. c}} $num [expr $num+1] [expr $num+2]]
  135. # "history keep"
  136. history add "foo1"
  137. history add "foo2"
  138. history add "foo3"
  139. history keep 2
  140. test history-6.1 {keep option} {history event [expr [history n]-1]} foo3
  141. test history-6.2 {keep option} {history event -1} foo2
  142. test history-6.3 {keep option} {catch {history event -3}} 1
  143. test history-6.4 {keep option} {
  144.     catch {history event -3} msg
  145.     set msg
  146. } {event "-3" is too far in the past}
  147. history k 5
  148. test history-6.5 {keep option} {history event -1} foo2
  149. test history-6.6 {keep option} {history event -2} {}
  150. test history-6.7 {keep option} {history event -3} {}
  151. test history-6.8 {keep option} {history event -4} {}
  152. test history-6.9 {keep option} {catch {history event -5}} 1
  153. test history-6.10 {keep option} {catch {history keep 4 6}} 1
  154. test history-6.11 {keep option} {
  155.     catch {history keep 4 6} msg
  156.     set msg
  157. } {wrong # args: should be "history keep ?count?"}
  158. test history-6.12 {keep option} {catch {history keep}} 0
  159. test history-6.13 {keep option} {
  160.     history keep
  161. } {5}
  162. test history-6.14 {keep option} {catch {history keep -3}} 1
  163. test history-6.15 {keep option} {
  164.     catch {history keep -3} msg
  165.     set msg
  166. } {illegal keep count "-3"}
  167. test history-6.16 {keep option} {
  168.     catch {history keep butter} msg
  169.     set msg
  170. } {illegal keep count "butter"}
  171. # "history nextid"
  172. set num [history n]
  173. history add "Testing"
  174. history add "Testing2"
  175. test history-7.1 {nextid option} {history event} "Testing"
  176. test history-7.2 {nextid option} {history next} [expr $num+2]
  177. test history-7.3 {nextid option} {catch {history nextid garbage}} 1
  178. test history-7.4 {nextid option} {
  179.     catch {history nextid garbage} msg
  180.     set msg
  181. } {wrong # args: should be "history nextid"}
  182. # "history clear"
  183. set num [history n]
  184. history add "Testing"
  185. history add "Testing2"
  186. test history-8.1 {clear option} {catch {history clear junk}} 1
  187. test history-8.2 {clear option} {history clear} {}
  188. history add "Testing"
  189. test history-8.3 {clear option} {history} {     1  Testing}
  190. # miscellaneous
  191. test history-9.1 {miscellaneous} {catch {history gorp} msg} 1
  192. test history-9.2 {miscellaneous} {
  193.     catch {history gorp} msg
  194.     set msg
  195. } {bad option "gorp": must be add, change, clear, event, info, keep, nextid, or redo}
  196. # cleanup
  197. ::tcltest::cleanupTests
  198. return