1# 2# loop.test 3# 4# Tests for the loop command. 5#--------------------------------------------------------------------------- 6# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans. 7# 8# Permission to use, copy, modify, and distribute this software and its 9# documentation for any purpose and without fee is hereby granted, provided 10# that the above copyright notice appear in all copies. Karl Lehenbauer and 11# Mark Diekhans make no representations about the suitability of this 12# software for any purpose. It is provided "as is" without express or 13# implied warranty. 14#------------------------------------------------------------------------------ 15# $Id: loop.test,v 1.2 2002/04/02 02:29:43 hobbs Exp $ 16#------------------------------------------------------------------------------ 17# 18 19if {[cequal [info procs Test] {}]} { 20 source [file join [file dirname [info script]] testlib.tcl] 21} 22 23Test loop-1.1 {loop tests} { 24 set a {} 25 set i 1 26 loop i 1 6 { 27 set a [concat $a $i] 28 } 29 set a 30} 0 {1 2 3 4 5} 31 32Test loop-1.2 {loop tests} { 33 set a {} 34 loop i 1 6 { 35 if {$i == 4} { 36 continue} 37 set a [concat $a $i] 38 } 39 set a 40} 0 {1 2 3 5} 41 42Test loop-1.3 {loop tests} { 43 set a {} 44 loop i 1 6 { 45 if $i==4 break 46 set a [concat $a $i] 47 } 48 set a 49} 0 {1 2 3} 50 51Test loop-1.4 {loop tests} { 52 loop 1 2 3 53} 1 {wrong # args: loop var first limit ?incr? command} 54 55Test loop-1.5 {loop tests} { 56 loop 1 2 3 4 5 6 57} 1 {wrong # args: loop var first limit ?incr? command} 58 59Test loop-1.6 {loop tests} { 60 set a {} 61 loop i 1 6 { 62 set a [concat $a $i] 63 set i 100 64 } 65 set a 66} 0 {1 2 3 4 5} 67 68Test loop-1.7 {loop tests} { 69 set a {} 70 loop i 1 6 2 { 71 set a [concat $a $i] 72 } 73 set a 74} 0 {1 3 5} 75 76Test loop-1.8 {loop tests} { 77 set a {} 78 set i 1 79 loop i 6 1 -1 { 80 set a [concat $a $i] 81 } 82 set a 83} 0 {6 5 4 3 2} 84 85Test loop-1.9 {loop tests} { 86 set a {} 87 loop i 6 1 -1 { 88 if $i==4 { 89 continue} 90 set a [concat $a $i] 91 } 92 set a 93} 0 {6 5 3 2} 94 95Test loop-1.10 {loop tests} { 96 set a {} 97 loop i 6 1 -1 { 98 if {$i == 4} { 99 break} 100 set a [concat $a $i] 101 } 102 set a 103} 0 {6 5} 104 105Test loop-1.11 {loop tests} { 106 set j 0 107 loop i 65536 65556 { 108 incr j 109 } 110 set j 111} 0 20 112 113Test loop-1.12 {loop tests} { 114 set j 0 115 loop i 65556 65536 -1 { 116 incr j 1 117 } 118 set j 119} 0 20 120 121Test loop-1.13 {loop tests} { 122 set j 0 123 loop i 0 655360 65536 { 124 incr j 1 125 } 126 set j 127} 0 10 128 129Test loop-1.14 {loop tests} { 130 set j 0 131 loop i 655360 0 -65536 { 132 incr j 1 133 } 134 set j 135} 0 10 136 137Test loop-1.15 {loop tests} { 138 set a {} 139 set i 1 140 loop i 3*2 0+1 10-11 { 141 set a [concat $a $i] 142 } 143 set a 144} 0 {6 5 4 3 2} 145 146Test loop-2.1 {loop test} { 147 loop i 0 5 {error "an error"} 148} 1 {an error} 149 150# cleanup 151::tcltest::cleanupTests 152return 153