1# Commands covered: lrepeat 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 © 2003 Simon Geard. 8# 9# See the file "license.terms" for information on usage and redistribution 10# of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 12if {"::tcltest" ni [namespace children]} { 13 package require tcltest 2.5 14 namespace import -force ::tcltest::* 15} 16 17## Arg errors 18test lrepeat-1.1 {error cases} { 19 -body { 20 lrepeat 21 } 22 -returnCodes 1 23 -result {wrong # args: should be "lrepeat count ?value ...?"} 24} 25test lrepeat-1.2 {Accept zero elements(TIP 323)} { 26 -body { 27 lrepeat 1 28 } 29 -result {} 30} 31test lrepeat-1.3 {error cases} { 32 -body { 33 lrepeat a 1 34 } 35 -returnCodes 1 36 -result {expected integer but got "a"} 37} 38test lrepeat-1.4 {error cases} { 39 -body { 40 lrepeat -3 1 41 } 42 -returnCodes 1 43 -result {bad count "-3": must be integer >= 0} 44} 45test lrepeat-1.5 {Accept zero repetitions (TIP 323)} { 46 -body { 47 lrepeat 0 48 } 49 -result {} 50} 51test lrepeat-1.6 {error cases} { 52 -body { 53 lrepeat 3.5 1 54 } 55 -returnCodes 1 56 -result {expected integer but got "3.5"} 57} 58test lrepeat-1.7 {Accept zero repetitions (TIP 323)} { 59 -body { 60 lrepeat 0 a b c 61 } 62 -result {} 63} 64test lrepeat-1.8 {Do not build enormous lists - Bug 2130992} -body { 65 lrepeat 0x10000000 a b c d e f g h 66} -returnCodes error -match glob -result * 67 68## Okay 69test lrepeat-2.1 {normal cases} { 70 lrepeat 10 a 71} {a a a a a a a a a a} 72test lrepeat-2.2 {normal cases} { 73 lrepeat 3 [lrepeat 3 0] 74} {{0 0 0} {0 0 0} {0 0 0}} 75test lrepeat-2.3 {normal cases} { 76 lrepeat 3 a b c 77} {a b c a b c a b c} 78test lrepeat-2.4 {normal cases} { 79 lrepeat 3 [lrepeat 2 a] b c 80} {{a a} b c {a a} b c {a a} b c} 81 82# cleanup 83::tcltest::cleanupTests 84return 85