#
# loop.test
#
# Tests for the loop command.
#---------------------------------------------------------------------------
# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies.  Karl Lehenbauer and
# Mark Diekhans make no representations about the suitability of this
# software for any purpose.  It is provided "as is" without express or
# implied warranty.
#------------------------------------------------------------------------------
# $Id: loop.test,v 1.2 2002/04/02 02:29:43 hobbs Exp $
#------------------------------------------------------------------------------
#

if {[cequal [info procs Test] {}]} {
    source [file join [file dirname [info script]] testlib.tcl]
}

Test loop-1.1 {loop tests} {
    set a {}
    set i 1
    loop i 1 6 {
        set a [concat $a $i]
    }
    set a
} 0 {1 2 3 4 5}

Test loop-1.2 {loop tests} {
    set a {}
    loop i 1 6 {
        if {$i == 4} {
            continue}
        set a [concat $a $i]
    }
    set a
} 0 {1 2 3 5}

Test loop-1.3 {loop tests} {
    set a {}
    loop i 1 6 {
        if $i==4 break
        set a [concat $a $i]
    }
    set a
} 0 {1 2 3}

Test loop-1.4 {loop tests} {
    loop 1 2 3
} 1 {wrong # args: loop var first limit ?incr? command}

Test loop-1.5 {loop tests} {
    loop 1 2 3 4 5 6
} 1 {wrong # args: loop var first limit ?incr? command}

Test loop-1.6 {loop tests} {
    set a {}
    loop i 1 6 {
        set a [concat $a $i]
        set i 100
    }
    set a
} 0 {1 2 3 4 5}

Test loop-1.7 {loop tests} {
    set a {}
    loop i 1 6 2 {
        set a [concat $a $i]
    }
    set a
} 0 {1 3 5}

Test loop-1.8 {loop tests} {
    set a {}
    set i 1
    loop i 6 1 -1 {
        set a [concat $a $i]
    }
    set a
} 0 {6 5 4 3 2}

Test loop-1.9 {loop tests} {
    set a {}
    loop i 6 1 -1 {
        if $i==4 {
            continue}
        set a [concat $a $i]
    }
    set a
} 0 {6 5 3 2}

Test loop-1.10 {loop tests} {
    set a {}
    loop i 6 1 -1 {
        if {$i == 4} {
            break}
        set a [concat $a $i]
    }
    set a
} 0 {6 5}

Test loop-1.11 {loop tests} {
    set j 0
    loop i 65536 65556 {
        incr j
    }
    set j
} 0 20

Test loop-1.12 {loop tests} {
    set j 0
    loop i 65556 65536 -1 {
        incr j 1
    }
    set j
} 0 20

Test loop-1.13 {loop tests} {
    set j 0
    loop i 0 655360 65536 {
        incr j 1
    }
    set j
} 0 10

Test loop-1.14 {loop tests} {
    set j 0
    loop i 655360 0 -65536 {
        incr j 1
    }
    set j
} 0 10

Test loop-1.15 {loop tests} {
    set a {}
    set i 1
    loop i 3*2 0+1 10-11 {
        set a [concat $a $i]
    }
    set a
} 0 {6 5 4 3 2}

Test loop-2.1 {loop test} {
    loop i 0 5 {error "an error"}
} 1 {an error}

# cleanup
::tcltest::cleanupTests
return
