home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / tcl7.0b1 / tests / incr.test < prev    next >
Encoding:
Text File  |  1993-06-16  |  2.8 KB  |  79 lines

  1. # Commands covered:  lreplace
  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. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/incr.test,v 1.4 93/06/16 10:57:48 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. catch {unset x}
  32.  
  33. test incr-1.1 {basic incr operation} {
  34.     set x 23
  35.     list [incr x] $x
  36. } {24 24}
  37. test incr-1.2 {basic incr operation} {
  38.     set x 106
  39.     list [incr x -5] $x
  40. } {101 101}
  41.  
  42. test incr-2.1 {incr errors} {
  43.     list [catch incr msg] $msg
  44. } {1 {wrong # args: should be "incr varName ?increment?"}}
  45. test incr-2.2 {incr errors} {
  46.     list [catch {incr a b c} msg] $msg
  47. } {1 {wrong # args: should be "incr varName ?increment?"}}
  48. test incr-2.3 {incr errors} {
  49.     catch {unset x}
  50.     list [catch {incr x} msg] $msg $errorInfo
  51. } {1 {can't read "x": no such variable} {can't read "x": no such variable
  52.     while executing
  53. "incr x"}}
  54. test incr-2.4 {incr errors} {
  55.     set x abc
  56.     list [catch {incr x} msg] $msg $errorInfo
  57. } {1 {expected integer but got "abc"} {expected integer but got "abc"
  58.     (reading value of variable to increment)
  59.     invoked from within
  60. "incr x"}}
  61. test incr-2.5 {incr errors} {
  62.     set x 123
  63.     list [catch {incr x 1a} msg] $msg $errorInfo
  64. } {1 {expected integer but got "1a"} {expected integer but got "1a"
  65.     (reading increment)
  66.     invoked from within
  67. "incr x 1a"}}
  68. test incr-2.6 {incr errors} {
  69.     proc readonly args {error "variable is read-only"}
  70.     set x 123
  71.     trace var x w readonly
  72.     list [catch {incr x 1} msg] $msg $errorInfo
  73. } {1 {can't set "x": variable is read-only} {can't set "x": variable is read-only
  74.     while executing
  75. "incr x 1"}}
  76.  
  77. catch {unset x}
  78. concat {}
  79.