home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tcl7.4 / tests / lsort.test < prev    next >
Encoding:
Text File  |  1995-06-06  |  5.1 KB  |  135 lines

  1. # Commands covered:  lsort
  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. # @(#) lsort.test 1.6 95/06/05 17:00:02
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. test lsort-1.1 {lsort command} {
  18.     lsort {abdeq ab 1 ac a}
  19. } {1 a ab abdeq ac}
  20. test lsort-1.2 {lsort command} {
  21.     lsort -decreasing {abdeq ab 1 ac a}
  22. } {ac abdeq ab a 1}
  23. test lsort-1.3 {lsort command} {
  24.     lsort -increasing {abdeq ab 1 ac a}
  25. } {1 a ab abdeq ac}
  26. test lsort-1.4 {lsort command} {
  27.     lsort {{one long element}}
  28. } {{one long element}}
  29. test lsort-1.5 {lsort command} {
  30.     lsort {}
  31. } {}
  32. test lsort-1.6 {lsort with characters needing backslashes} {
  33.     lsort {$ \\ [] \{}
  34. } {{$} {[]} \\ \{}
  35.  
  36. test lsort-2.1 {lsort -integer} {
  37.     lsort -integer -inc {1 180 62 040 180 -42 33 0x40}
  38. } {-42 1 040 33 62 0x40 180 180}
  39. test lsort-2.2 {lsort -integer} {
  40.     lsort -int -dec {1 180 62 040 180 -42 33 0x40}
  41. } {180 180 0x40 62 33 040 1 -42}
  42. test lsort-2.3 {lsort -integer} {
  43.     list [catch {lsort -integer {xxx 180.2 62 040 180 -42 33 0x40}} msg] $msg $errorInfo
  44. } {1 {expected integer but got "xxx"} {expected integer but got "xxx"
  45.     (converting list element from string to integer)
  46.     invoked from within
  47. "lsort -integer {xxx 180.2 62 040 180 -42 33 0x40}"}}
  48. test lsort-2.4 {lsort -integer} {
  49.     list [catch {lsort -integer {1 180.2 62 040 180 -42 33 0x40}} msg] $msg $errorInfo
  50. } {1 {expected integer but got "180.2"} {expected integer but got "180.2"
  51.     (converting list element from string to integer)
  52.     invoked from within
  53. "lsort -integer {1 180.2 62 040 180 -42 33 0x40}"}}
  54.  
  55. test lsort-3.1 {lsort -real} {
  56.     lsort -real {1 180.1 62 040 180 -42.7 33}
  57. } {-42.7 1 33 040 62 180 180.1}
  58. test lsort-3.2 {lsort -real} {
  59.     lsort -r -d {1 180.1 62 040 180 -42.7 33}
  60. } {180.1 180 62 040 33 1 -42.7}
  61. test lsort-3.3 {lsort -real} {
  62.     list [catch {lsort -real -inc {xxx 20 62 180 -42.7 33}} msg] $msg $errorInfo
  63. } {1 {expected floating-point number but got "xxx"} {expected floating-point number but got "xxx"
  64.     (converting list element from string to real)
  65.     invoked from within
  66. "lsort -real -inc {xxx 20 62 180 -42.7 33}"}}
  67. test lsort-3.4 {lsort -real} {
  68.     list [catch {lsort -real -inc {1 0x40 62 180 -42.7 33}} msg] $msg $errorInfo
  69. } {1 {expected floating-point number but got "0x40"} {expected floating-point number but got "0x40"
  70.     (converting list element from string to real)
  71.     invoked from within
  72. "lsort -real -inc {1 0x40 62 180 -42.7 33}"}}
  73.  
  74. proc lsort1 {a b} {
  75.     expr {2*([string match x* $a] - [string match x* $b])
  76.         + [string match *y $a] - [string match *y $b]}
  77. }
  78. proc lsort2 {a b} {
  79.     error "comparison error"
  80. }
  81. proc lsort3 {a b} {
  82.     concat "foobar"
  83. }
  84.  
  85. test lsort-4.1 {lsort -command} {
  86.     lsort -command lsort1 {xxx yyy abc {xx y}}
  87. } {abc yyy xxx {xx y}}
  88. test lsort-4.2 {lsort -command} {
  89.     lsort -command lsort1 -dec {xxx yyy abc {xx y}}
  90. } {{xx y} xxx yyy abc}
  91. test lsort-4.3 {lsort -command} {
  92.     list [catch {lsort -command lsort2 -dec {1 1 1 1}} msg] $msg $errorInfo
  93. } {1 {comparison error} {comparison error
  94.     while executing
  95. "error "comparison error""
  96.     (procedure "lsort2" line 2)
  97.     invoked from within
  98. "lsort2 1 1"
  99.     (user-defined comparison command)
  100.     invoked from within
  101. "lsort -command lsort2 -dec {1 1 1 1}"}}
  102. test lsort-4.4 {lsort -command} {
  103.     list [catch {lsort -command lsort3 -dec {1 2 3 4}} msg] $msg $errorInfo
  104. } {1 {comparison command returned non-numeric result} {comparison command returned non-numeric result
  105.     while executing
  106. "lsort -command lsort3 -dec {1 2 3 4}"}}
  107. test lsort-4.5 {lsort -command} {
  108.     list [catch {lsort -command {xxx yyy xxy abc}} msg] $msg
  109. } {1 {"-command" must be followed by comparison command}}
  110.  
  111. test lsort-5.1 {lsort errors} {
  112.     list [catch lsort msg] $msg
  113. } {1 {wrong # args: should be "lsort ?-ascii? ?-integer? ?-real? ?-increasing? ?-decreasing? ?-command string? list"}}
  114. test lsort-5.2 {lsort errors} {
  115.     list [catch {lsort a b} msg] $msg
  116. } {1 {bad switch "a": must be -ascii, -integer, -real, -increasing -decreasing, or -command}}
  117. test lsort-5.3 {lsort errors} {
  118.     list [catch {lsort "\{"} msg] $msg
  119. } {1 {unmatched open brace in list}}
  120. test lsort-5.4 {lsort errors} {
  121.     list [catch {lsort -in {1 180.0 040 62 180 -42.7 33}} msg] $msg
  122. } {1 {bad switch "-in": must be -ascii, -integer, -real, -increasing -decreasing, or -command}}
  123. test lsort-5.5 {lsort errors: disallow recursion} {
  124.     proc x args {lsort {a b c}}
  125.     list [catch {lsort -command x {3 7}} msg] $msg $errorInfo
  126. } {1 {can't invoke "lsort" recursively} {can't invoke "lsort" recursively
  127.     while executing
  128. "lsort {a b c}"
  129.     (procedure "x" line 1)
  130.     invoked from within
  131. "x 3 7"
  132.     (user-defined comparison command)
  133.     invoked from within
  134. "lsort -command x {3 7}"}}
  135.