os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/while-old.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 # Commands covered:  while
     2 #
     3 # This file contains the original set of tests for Tcl's while command.
     4 # Since the while command is now compiled, a new set of tests covering
     5 # the new implementation is in the file "while.test". Sourcing this file
     6 # into Tcl runs the tests and generates output for errors.
     7 # No output means no errors were found.
     8 #
     9 # Copyright (c) 1991-1993 The Regents of the University of California.
    10 # Copyright (c) 1994-1996 Sun Microsystems, Inc.
    11 # Copyright (c) 1998-1999 by Scriptics Corporation.
    12 #
    13 # See the file "license.terms" for information on usage and redistribution
    14 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    15 #
    16 # RCS: @(#) $Id: while-old.test,v 1.6 2000/04/10 17:19:06 ericm Exp $
    17 
    18 if {[lsearch [namespace children] ::tcltest] == -1} {
    19     package require tcltest
    20     namespace import -force ::tcltest::*
    21 }
    22 
    23 test while-old-1.1 {basic while loops} {
    24     set count 0
    25     while {$count < 10} {set count [expr $count+1]}
    26     set count
    27 } 10
    28 test while-old-1.2 {basic while loops} {
    29     set value xxx
    30     while {2 > 3} {set value yyy}
    31     set value
    32 } xxx
    33 test while-old-1.3 {basic while loops} {
    34     set value 1
    35     while {"true"} {
    36 	incr value;
    37 	if {$value > 5} {
    38 	    break;
    39 	}
    40     }
    41     set value
    42 } 6
    43 test while-old-1.4 {basic while loops, multiline test expr} {
    44     set value 1
    45     while {($tcl_platform(platform) != "foobar1") && \
    46 	    ($tcl_platform(platform) != "foobar2")} {
    47         incr value
    48         break
    49     }
    50     set value
    51 } {2}
    52 test while-old-1.5 {basic while loops, test expr in quotes} {
    53     set value 1
    54     while "0 < 3" {set value 2; break}
    55     set value
    56 } {2}
    57 
    58 test while-old-2.1 {continue in while loop} {
    59     set list {1 2 3 4 5}
    60     set index 0
    61     set result {}
    62     while {$index < 5} {
    63 	if {$index == 2} {set index [expr $index+1]; continue}
    64 	set result [concat $result [lindex $list $index]]
    65 	set index [expr $index+1]
    66     }
    67     set result
    68 } {1 2 4 5}
    69 
    70 test while-old-3.1 {break in while loop} {
    71     set list {1 2 3 4 5}
    72     set index 0
    73     set result {}
    74     while {$index < 5} {
    75 	if {$index == 3} break
    76 	set result [concat $result [lindex $list $index]]
    77 	set index [expr $index+1]
    78     }
    79     set result
    80 } {1 2 3}
    81 
    82 test while-old-4.1 {errors in while loops} {
    83     set err [catch {while} msg]
    84     list $err $msg
    85 } {1 {wrong # args: should be "while test command"}}
    86 test while-old-4.2 {errors in while loops} {
    87     set err [catch {while 1} msg]
    88     list $err $msg
    89 } {1 {wrong # args: should be "while test command"}}
    90 test while-old-4.3 {errors in while loops} {
    91     set err [catch {while 1 2 3} msg]
    92     list $err $msg
    93 } {1 {wrong # args: should be "while test command"}}
    94 test while-old-4.4 {errors in while loops} {
    95     set err [catch {while {"a"+"b"} {error "loop aborted"}} msg]
    96     list $err $msg
    97 } {1 {can't use non-numeric string as operand of "+"}}
    98 test while-old-4.5 {errors in while loops} {
    99     catch {unset x}
   100     set x 1
   101     set err [catch {while {$x} {set x foo}} msg]
   102     list $err $msg
   103 } {1 {expected boolean value but got "foo"}}
   104 test while-old-4.6 {errors in while loops} {
   105     set err [catch {while {1} {error "loop aborted"}} msg]
   106     list $err $msg $errorInfo
   107 } {1 {loop aborted} {loop aborted
   108     while executing
   109 "error "loop aborted""}}
   110 
   111 test while-old-5.1 {while return result} {
   112     while {0} {set a 400}
   113 } {}
   114 test while-old-5.2 {while return result} {
   115     set x 1
   116     while {$x} {set x 0}
   117 } {}
   118 
   119 # cleanup
   120 ::tcltest::cleanupTests
   121 return
   122 
   123 
   124 
   125 
   126 
   127 
   128 
   129 
   130 
   131 
   132 
   133