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

  1. # Commands covered:  lindex
  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. # @(#) lindex.test 1.4 94/12/17 16:20:05
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. test lindex-1.1 {basic tests} {
  18.     lindex {a b c} 0} a
  19. test lindex-1.2 {basic tests} {
  20.     lindex {a {b c d} x} 1} {b c d}
  21. test lindex-1.3 {basic tests} {
  22.     lindex {a b\ c\ d x} 1} {b c d}
  23. test lindex-1.4 {basic tests} {
  24.     lindex {a b c} 3} {}
  25. test lindex-1.5 {basic tests} {
  26.     list [catch {lindex {a b c} -1} msg] $msg
  27. } {0 {}}
  28. test lindex-1.6 {basic tests} {
  29.     lindex {a b c d} end
  30. } d
  31. test lindex-1.7 {basic tests} {
  32.     lindex {a b c d} 100
  33. } {}
  34. test lindex-1.8 {basic tests} {
  35.     lindex {a} e
  36. } a
  37. test lindex-1.9 {basic tests} {
  38.     lindex {} end
  39. } {}
  40. test lindex-1.10 {basic tests} {
  41.     lindex {a b c d} 3
  42. } d
  43.  
  44. test lindex-2.1 {error conditions} {
  45.     list [catch {lindex msg} msg] $msg
  46. } {1 {wrong # args: should be "lindex list index"}}
  47. test lindex-2.2 {error conditions} {
  48.     list [catch {lindex 1 2 3 4} msg] $msg
  49. } {1 {wrong # args: should be "lindex list index"}}
  50. test lindex-2.3 {error conditions} {
  51.     list [catch {lindex 1 2a2} msg] $msg
  52. } {1 {expected integer but got "2a2"}}
  53. test lindex-2.4 {error conditions} {
  54.     list [catch {lindex "a \{" 2} msg] $msg
  55. } {1 {unmatched open brace in list}}
  56. test lindex-2.5 {error conditions} {
  57.     list [catch {lindex {a {b c}d e} 2} msg] $msg
  58. } {1 {list element in braces followed by "d" instead of space}}
  59. test lindex-2.6 {error conditions} {
  60.     list [catch {lindex {a "b c"def ghi} 2} msg] $msg
  61. } {1 {list element in quotes followed by "def" instead of space}}
  62.  
  63. test lindex-3.1 {quoted elements} {
  64.     lindex {a "b c" d} 1
  65. } {b c}
  66. test lindex-3.2 {quoted elements} {
  67.     lindex {"{}" b c} 0
  68. } {{}}
  69. test lindex-3.3 {quoted elements} {
  70.     lindex {ab "c d \" x" y} 1
  71. } {c d " x}
  72. test lindex-3.4 {quoted elements} {
  73.     lindex {a b {c d "e} {f g"}} 2
  74. } {c d "e}
  75.