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

  1. # Commands covered:  lsearch
  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. # @(#) lsearch.test 1.4 94/12/17 16:20:12
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. set x {abcd bbcd 123 234 345}
  18. test lsearch-1.1 {lsearch command} {
  19.     lsearch $x 123
  20. } 2
  21. test lsearch-1.2 {lsearch command} {
  22.     lsearch $x 3456
  23. } -1
  24. test lsearch-1.3 {lsearch command} {
  25.     lsearch $x *5
  26. } 4
  27. test lsearch-1.4 {lsearch command} {
  28.     lsearch $x *bc*
  29. } 0
  30.  
  31. test lsearch-2.1 {search modes} {
  32.     lsearch -exact {xyz bbcc *bc*} *bc*
  33. } 2
  34. test lsearch-2.2 {search modes} {
  35.     lsearch -exact {b.x ^bc xy bcx} ^bc
  36. } 1
  37. test lsearch-2.3 {search modes} {
  38.     list [catch {lsearch -regexp {xyz bbcc *bc*} *bc*} msg] $msg
  39. } {1 {couldn't compile regular expression pattern: ?+* follows nothing}}
  40. test lsearch-2.4 {search modes} {
  41.     lsearch -regexp {b.x ^bc xy bcx} ^bc
  42. } 3
  43. test lsearch-2.5 {search modes} {
  44.     lsearch -glob {xyz bbcc *bc*} *bc*
  45. } 1
  46. test lsearch-2.6 {search modes} {
  47.     lsearch -glob {b.x ^bc xy bcx} ^bc
  48. } 1
  49. test lsearch-2.7 {search modes} {
  50.     list [catch {lsearch -glib {b.x bx xy bcx} b.x} msg] $msg
  51. } {1 {bad search mode "-glib": must be -exact, -glob, or -regexp}}
  52.  
  53. test lsearch-3.1 {lsearch errors} {
  54.     list [catch lsearch msg] $msg
  55. } {1 {wrong # args: should be "lsearch ?mode? list pattern"}}
  56. test lsearch-3.2 {lsearch errors} {
  57.     list [catch {lsearch a} msg] $msg
  58. } {1 {wrong # args: should be "lsearch ?mode? list pattern"}}
  59. test lsearch-3.3 {lsearch errors} {
  60.     list [catch {lsearch a b c} msg] $msg
  61. } {1 {bad search mode "a": must be -exact, -glob, or -regexp}}
  62. test lsearch-3.4 {lsearch errors} {
  63.     list [catch {lsearch a b c d} msg] $msg
  64. } {1 {wrong # args: should be "lsearch ?mode? list pattern"}}
  65. test lsearch-3.5 {lsearch errors} {
  66.     list [catch {lsearch "\{" b} msg] $msg
  67. } {1 {unmatched open brace in list}}
  68.