home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tcl7.4 / tests / history.test < prev    next >
Encoding:
Text File  |  1994-12-18  |  12.2 KB  |  387 lines

  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. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # @(#) history.test 1.9 94/12/17 16:20:00
  14.   
  15. if {[info commands history] == ""} {
  16.     puts stdout "This version of Tcl was built without the history command;\n"
  17.     puts stdout "history tests will be skipped.\n"
  18.     return
  19. }
  20.  
  21. if {[string compare test [info procs test]] == 1} then {source defs}
  22.  
  23. set num [history nextid]
  24. history keep 3
  25. history add {set a 12345}
  26. history add {set b [format {A test %s} string]}
  27. history add {Another test}
  28.  
  29. # "history event"
  30.  
  31. test history-1.1 {event option} {history event -1} \
  32.     {set b [format {A test %s} string]}
  33. test history-1.2 {event option} {history event $num} \
  34.     {set a 12345}
  35. test history-1.3 {event option} {history event [expr $num+2]} \
  36.     {Another test}
  37. test history-1.4 {event option} {history event set} \
  38.     {set b [format {A test %s} string]}
  39. test history-1.5 {event option} {history e "* a*"} \
  40.     {set a 12345}
  41. test history-1.6 {event option} {catch {history event *gorp} msg} 1
  42. test history-1.7 {event option} {
  43.     catch {history event *gorp} msg
  44.     set msg
  45. } {no event matches "*gorp"}
  46. test history-1.8 {event option} {history event} \
  47.     {set b [format {A test %s} string]}
  48. test history-1.9 {event option} {catch {history event 123 456} msg} 1
  49. test history-1.10 {event option} {
  50.     catch {history event 123 456} msg
  51.     set msg
  52. } {wrong # args: should be "history event ?event?"}
  53.  
  54. # "history redo"
  55.  
  56. set a 0
  57. history redo -2
  58. test history-2.1 {redo option} {set a} 12345
  59. set b 0
  60. history redo
  61. test history-2.2 {redo option} {set b} {A test string}
  62. test history-2.3 {redo option} {catch {history redo -3 -4}} 1
  63. test history-2.4 {redo option} {
  64.     catch {history redo -3 -4} msg
  65.     set msg
  66. } {wrong # args: should be "history redo ?event?"}
  67.  
  68. # "history add"
  69.  
  70. history add "set a 444" exec
  71. test history-3.1 {add option} {set a} 444
  72. test history-3.2 {add option} {catch {history add "set a 444" execGorp}} 1
  73. test history-3.3 {add option} {
  74.     catch {history add "set a 444" execGorp} msg
  75.     set msg
  76. } {bad argument "execGorp": should be "exec"}
  77. test history-3.4 {add option} {catch {history add "set a 444" a} msg} 1
  78. test history-3.5 {add option} {
  79.     catch {history add "set a 444" a} msg
  80.     set msg
  81. } {bad argument "a": should be "exec"}
  82. history add "set a 555" e
  83. test history-3.6 {add option} {set a} 555
  84. history add "set a 666"
  85. test history-3.7 {add option} {set a} 555
  86. test history-3.8 {add option} {catch {history add "set a 666" e f} msg} 1
  87. test history-3.9 {add option} {
  88.     catch {history add "set a 666" e f} msg
  89.     set msg
  90. } {wrong # args: should be "history add event ?exec?"}
  91.  
  92. # "history change"
  93.  
  94. history change "A test value"
  95. test history-4.1 {change option} {history event [expr {[history n]-1}]} \
  96.     "A test value"
  97. history c "Another test" -1
  98. test history-4.2 {change option} {history e} "Another test"
  99. test history-4.3 {change option} {history event [expr {[history n]-1}]} \
  100.     "A test value"
  101. test history-4.4 {change option} {catch {history change Foo 4 10}} 1
  102. test history-4.5 {change option} {
  103.     catch {history change Foo 4 10} msg
  104.     set msg
  105. } {wrong # args: should be "history change newValue ?event?"}
  106. test history-4.6 {change option} {
  107.     catch {history change Foo [expr {[history n]-4}]}
  108. } 1
  109. test history-4.7 {change option} {
  110.     catch {history change Foo [expr {[history n]-4}]}
  111.     set msg
  112. } {wrong # args: should be "history change newValue ?event?"}
  113.  
  114. # "history info"
  115.  
  116. set num [history n]
  117. history add set\ a\ {b\nc\ d\ e}
  118. history add {set b 1234}
  119. history add set\ c\ {a\nb\nc}
  120. test history-5.1 {info option} {history info} [format {%6d  set a {b
  121.     c d e}
  122. %6d  set b 1234
  123. %6d  set c {a
  124.     b
  125.     c}} $num [expr $num+1] [expr $num+2]]
  126. test history-5.2 {info option} {history i 2} [format {%6d  set b 1234
  127. %6d  set c {a
  128.     b
  129.     c}} [expr $num+1] [expr $num+2]]
  130. test history-5.3 {info option} {catch {history i 2 3}} 1
  131. test history-5.4 {info option} {
  132.     catch {history i 2 3} msg
  133.     set msg
  134. } {wrong # args: should be "history info ?count?"}
  135. test history-5.5 {info option} {history} [format {%6d  set a {b
  136.     c d e}
  137. %6d  set b 1234
  138. %6d  set c {a
  139.     b
  140.     c}} $num [expr $num+1] [expr $num+2]]
  141.  
  142. # "history keep"
  143.  
  144. history add "foo1"
  145. history add "foo2"
  146. history add "foo3"
  147. history keep 2
  148. test history-6.1 {keep option} {history event [expr [history n]-1]} foo3
  149. test history-6.2 {keep option} {history event -1} foo2
  150. test history-6.3 {keep option} {catch {history event -3}} 1
  151. test history-6.4 {keep option} {
  152.     catch {history event -3} msg
  153.     set msg
  154. } {event "-3" is too far in the past}
  155. history k 5
  156. test history-6.5 {keep option} {history event -1} foo2
  157. test history-6.6 {keep option} {history event -2} {}
  158. test history-6.7 {keep option} {history event -3} {}
  159. test history-6.8 {keep option} {history event -4} {}
  160. test history-6.9 {keep option} {catch {history event -5}} 1
  161. test history-6.10 {keep option} {catch {history keep 4 6}} 1
  162. test history-6.11 {keep option} {
  163.     catch {history keep 4 6} msg
  164.     set msg
  165. } {wrong # args: should be "history keep number"}
  166. test history-6.12 {keep option} {catch {history keep}} 1
  167. test history-6.13 {keep option} {
  168.     catch {history keep} msg
  169.     set msg
  170. } {wrong # args: should be "history keep number"}
  171. test history-6.14 {keep option} {catch {history keep -3}} 1
  172. test history-6.15 {keep option} {
  173.     catch {history keep -3} msg
  174.     set msg
  175. } {illegal keep count "-3"}
  176.  
  177. # "history nextid"
  178.  
  179. set num [history n]
  180. history add "Testing"
  181. history add "Testing2"
  182. test history-7.1 {nextid option} {history event} "Testing"
  183. test history-7.2 {nextid option} {history next} [expr $num+2]
  184. test history-7.3 {nextid option} {catch {history nextid garbage}} 1
  185. test history-7.4 {nextid option} {
  186.     catch {history nextid garbage} msg
  187.     set msg
  188. } {wrong # args: should be "history nextid"}
  189.  
  190. # "history substitute"
  191.  
  192. test history-8.1 {substitute option} {
  193.     history add "set a {test foo test b c test}"
  194.     history add "Test command 2"
  195.     set a 0
  196.     history substitute foo bar -1
  197.     set a
  198. } {test bar test b c test}
  199. test history-8.2 {substitute option} {
  200.     history add "set a {test foo test b c test}"
  201.     history add "Test command 2"
  202.     set a 0
  203.     history substitute test gorp
  204.     set a
  205. } {gorp foo gorp b c gorp}
  206. test history-8.3 {substitute option} {
  207.     history add "set a {test foo test b c test}"
  208.     history add "Test command 2"
  209.     set a 0
  210.     history sub " te" to
  211.     set a
  212. } {test footost b ctost}
  213. test history-8.4 {substitute option} {catch {history sub xxx yyy}} 1
  214. test history-8.5 {substitute option} {
  215.     catch {history sub xxx yyy} msg
  216.     set msg
  217. } {"xxx" doesn't appear in event}
  218. test history-8.6 {substitute option} {catch {history s a b -10}} 1
  219. test history-8.7 {substitute option} {
  220.     catch {history s a b -10} msg
  221.     set msg
  222. } {event "-10" is too far in the past}
  223. test history-8.8 {substitute option} {catch {history s a b -1 20}} 1
  224. test history-8.9 {substitute option} {
  225.     catch {history s a b -1 20} msg
  226.     set msg
  227. } {wrong # args: should be "history substitute old new ?event?"}
  228.  
  229. # "history words"
  230.  
  231. test history-9.1 {words option} {
  232.     history add {word0 word1 word2 a b c word6}
  233.     history add foo
  234.     history words 0-$
  235. } {word0 word1 word2 a b c word6}
  236. test history-9.2 {words option} {
  237.     history add {word0 word1 word2 a b c word6}
  238.     history add foo
  239.     history w 2 -1
  240. } word2
  241. test history-9.3 {words option} {
  242.     history add {word0 word1 word2 a b c word6}
  243.     history add foo
  244.     history wo $
  245. } word6
  246. test history-9.4 {words option} {catch {history w 1--1} msg} 1
  247. test history-9.5 {words option} {
  248.     catch {history w 1--1} msg
  249.     set msg
  250. } {bad word selector "1--1":  should be num-num or pattern}
  251. test history-9.6 {words option} {
  252.     history add {word0 word1 word2 a b c word6}
  253.     history add foo
  254.     history w w
  255. } {}
  256. test history-9.7 {words option} {
  257.     history add {word0 word1 word2 a b c word6}
  258.     history add foo
  259.     history w *2
  260. } word2
  261. test history-9.8 {words option} {
  262.     history add {word0 word1 word2 a b c word6}
  263.     history add foo
  264.     history w *or*
  265. } {word0 word1 word2 word6}
  266. test history-9.9 {words option} {catch {history words 10}} 1
  267. test history-9.10 {words option} {
  268.     catch {history words 10} msg
  269.     set msg
  270. } {word selector "10" specified non-existent words}
  271. test history-9.11 {words option} {catch {history words 1 -1 20}} 1
  272. test history-9.12 {words option} {
  273.     catch {history words 1 -1 20} msg
  274.     set msg
  275. } {wrong # args: should be "history words num-num/pat ?event?"}
  276.  
  277. # history revision
  278.  
  279. test history-10.1 {history revision} {
  280.     set a 0
  281.     history a {set a 12345}
  282.     history a {set a [history e]} exec
  283.     set a
  284. } {set a 12345}
  285. test history-10.2 {history revision} {
  286.     set a 0
  287.     history a {set a 12345}
  288.     history a {set a [history e]} exec
  289.     history a foo
  290.     history ev -1
  291. } {set a {set a 12345}}
  292. test history-10.3 {history revision} {
  293.     set a 0
  294.     history a {set a 12345}
  295.     history a {set a [history e]} exec
  296.     history a foo
  297.     history a {history r -2} exec
  298.     history a {set a 12345}
  299.     history ev -1
  300. } {set a {set a 12345}}
  301. test history-10.4 {history revision} {
  302.     history a {set a 12345}
  303.     history a {history s 123 999} exec
  304.     history a foo
  305.     history ev -1
  306. } {set a 99945}
  307. test history-10.5 {history revision} {
  308.     history add {word0 word1 word2 a b c word6}
  309.     history add {set [history w 3] [list [history w 0] [history w {[ab]}]]} exec
  310.     set a
  311. } {word0 {a b}}
  312. test history-10.6 {history revision} {
  313.     history add {word0 word1 word2 a b c word6}
  314.     history add {set [history w 3] [list [history w 0] [history w {[ab]}]]} exec
  315.     history add foo
  316.     history ev
  317. } {set a [list word0 {a b}]}
  318. test history-10.7 {history revision} {
  319.     history add {word0 word1 word2 a b c word6}
  320.     history add {set [history w 3] [list [history w 0] [history w {[ab]}]]} exec
  321.     history add {format b}
  322.     history add {word0 word1 word2 a b c word6}
  323.     set a 0
  324.     history add {set [history subs b a -2] [list abc [history r -2] [history w 1-3]]} exec
  325.     history add foo
  326.     history ev
  327. } {set [format a] [list abc [format b] {word1 word2 a}]}
  328. test history-10.8 {history revision} {
  329.     history add {set a 12345}
  330.     concat a b c
  331.     history add {history redo; set b 44} exec
  332.     history add foo
  333.     history ev
  334. } {set a 12345; set b 44}
  335. test history-10.9 {history revision} {
  336.     history add {set a 12345}
  337.     history add {history redo; history change "A simple test"; history subs 45 xx} exec
  338.     set a
  339. } 123xx
  340. test history-10.10 {history revision} {
  341.     history add {set a 12345}
  342.     history add {history redo; history change "A simple test"; history subs 45 xx} exec
  343.     history add foo
  344.     history e
  345. } {A simple test}
  346. test history-10.11 {history revision} {
  347.     history add {word0 word1 $ a b c word6}
  348.     history add {set a [history w 4-[history word 2]]} exec
  349.     set a
  350. } {b c word6}
  351. test history-10.12 {history revision} {
  352.     history add {word0 word1 $ a b c word6}
  353.     history add {set a [history w 4-[history word 2]]} exec
  354.     history add foo
  355.     history e
  356. } {set a {b c word6}}
  357. test history-10.13 {history revision} {
  358.     history add {history word 0} exec
  359.     history add foo
  360.     history e
  361. } {history word 0}
  362. test history-10.14 {history revision} {
  363.     history add {set a [history word 0; format c]} exec
  364.     history add foo
  365.     history e
  366. } {set a [history word 0; format c]}
  367. test history-10.15 {history revision even when nested} {
  368.     proc x {a b} {history word $a $b}
  369.     history add {word1 word2 word3 word4}
  370.     history add {set a [x 1-3 -1]} exec
  371.     history add foo
  372.     history e
  373. } {set a {word2 word3 word4}}
  374. test history-10.16 {disable history revision in nested history evals} {
  375.     history add {word1 word2 word3 word4}
  376.     history add {set a [history words 0]; history add foo; set a [history words 0]} exec
  377.     history e
  378. } {set a word1; history add foo; set a [history words 0]}
  379.  
  380. # miscellaneous
  381.  
  382. test history-11.1 {miscellaneous} {catch {history gorp} msg} 1
  383. test history-11.2 {miscellaneous} {
  384.     catch {history gorp} msg
  385.     set msg
  386. } {bad option "gorp": must be add, change, event, info, keep, nextid, redo, substitute, or words}
  387.