os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/incr.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:  incr
     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) 1996 Sun Microsystems, Inc.
     8 # Copyright (c) 1998-1999 by Scriptics Corporation.
     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 # RCS: @(#) $Id: incr.test,v 1.8 2003/02/07 01:07:05 mdejong Exp $
    14 
    15 if {[lsearch [namespace children] ::tcltest] == -1} {
    16     package require tcltest
    17     namespace import -force ::tcltest::*
    18 }
    19 
    20 # Basic "incr" operation.
    21 
    22 catch {unset x}
    23 catch {unset i}
    24 
    25 test incr-1.1 {TclCompileIncrCmd: missing variable name} {
    26     list [catch {incr} msg] $msg
    27 } {1 {wrong # args: should be "incr varName ?increment?"}}
    28 test incr-1.2 {TclCompileIncrCmd: simple variable name} {
    29     set i 10
    30     list [incr i] $i
    31 } {11 11}
    32 test incr-1.3 {TclCompileIncrCmd: error compiling variable name} {
    33     set i 10
    34     catch {incr "i"xxx} msg
    35     set msg
    36 } {extra characters after close-quote}
    37 test incr-1.4 {TclCompileIncrCmd: simple variable name in quotes} {
    38     set i 17
    39     list [incr "i"] $i
    40 } {18 18}
    41 test incr-1.5 {TclCompileIncrCmd: simple variable name in braces} {
    42     catch {unset {a simple var}}
    43     set {a simple var} 27
    44     list [incr {a simple var}] ${a simple var}
    45 } {28 28}
    46 test incr-1.6 {TclCompileIncrCmd: simple array variable name} {
    47     catch {unset a}
    48     set a(foo) 37
    49     list [incr a(foo)] $a(foo)
    50 } {38 38}
    51 test incr-1.7 {TclCompileIncrCmd: non-simple (computed) variable name} {
    52     set x "i"
    53     set i 77
    54     list [incr $x 2] $i
    55 } {79 79}
    56 test incr-1.8 {TclCompileIncrCmd: non-simple (computed) variable name} {
    57     set x "i"
    58     set i 77
    59     list [incr [set x] +2] $i
    60 } {79 79}
    61 
    62 test incr-1.9 {TclCompileIncrCmd: increment given} {
    63     set i 10
    64     list [incr i +07] $i
    65 } {17 17}
    66 test incr-1.10 {TclCompileIncrCmd: no increment given} {
    67     set i 10
    68     list [incr i] $i
    69 } {11 11}
    70 
    71 test incr-1.11 {TclCompileIncrCmd: simple global name} {
    72     proc p {} {
    73         global i
    74         set i 54
    75         incr i
    76     }
    77     p
    78 } {55}
    79 test incr-1.12 {TclCompileIncrCmd: simple local name} {
    80     proc p {} {
    81         set foo 100
    82         incr foo
    83     }
    84     p
    85 } {101}
    86 test incr-1.13 {TclCompileIncrCmd: simple but new (unknown) local name} {
    87     proc p {} {
    88         incr bar
    89     }
    90     catch {p} msg
    91     set msg
    92 } {can't read "bar": no such variable}
    93 test incr-1.14 {TclCompileIncrCmd: simple local name, >255 locals} {
    94     proc 260locals {} {
    95         # create 260 locals
    96         set a0 0; set a1 0; set a2 0; set a3 0; set a4 0
    97         set a5 0; set a6 0; set a7 0; set a8 0; set a9 0
    98         set b0 0; set b1 0; set b2 0; set b3 0; set b4 0
    99         set b5 0; set b6 0; set b7 0; set b8 0; set b9 0
   100         set c0 0; set c1 0; set c2 0; set c3 0; set c4 0
   101         set c5 0; set c6 0; set c7 0; set c8 0; set c9 0
   102         set d0 0; set d1 0; set d2 0; set d3 0; set d4 0
   103         set d5 0; set d6 0; set d7 0; set d8 0; set d9 0
   104         set e0 0; set e1 0; set e2 0; set e3 0; set e4 0
   105         set e5 0; set e6 0; set e7 0; set e8 0; set e9 0
   106         set f0 0; set f1 0; set f2 0; set f3 0; set f4 0
   107         set f5 0; set f6 0; set f7 0; set f8 0; set f9 0
   108         set g0 0; set g1 0; set g2 0; set g3 0; set g4 0
   109         set g5 0; set g6 0; set g7 0; set g8 0; set g9 0
   110         set h0 0; set h1 0; set h2 0; set h3 0; set h4 0
   111         set h5 0; set h6 0; set h7 0; set h8 0; set h9 0
   112         set i0 0; set i1 0; set i2 0; set i3 0; set i4 0
   113         set i5 0; set i6 0; set i7 0; set i8 0; set i9 0
   114         set j0 0; set j1 0; set j2 0; set j3 0; set j4 0
   115         set j5 0; set j6 0; set j7 0; set j8 0; set j9 0
   116         set k0 0; set k1 0; set k2 0; set k3 0; set k4 0
   117         set k5 0; set k6 0; set k7 0; set k8 0; set k9 0
   118         set l0 0; set l1 0; set l2 0; set l3 0; set l4 0
   119         set l5 0; set l6 0; set l7 0; set l8 0; set l9 0
   120         set m0 0; set m1 0; set m2 0; set m3 0; set m4 0
   121         set m5 0; set m6 0; set m7 0; set m8 0; set m9 0
   122         set n0 0; set n1 0; set n2 0; set n3 0; set n4 0
   123         set n5 0; set n6 0; set n7 0; set n8 0; set n9 0
   124         set o0 0; set o1 0; set o2 0; set o3 0; set o4 0
   125         set o5 0; set o6 0; set o7 0; set o8 0; set o9 0
   126         set p0 0; set p1 0; set p2 0; set p3 0; set p4 0
   127         set p5 0; set p6 0; set p7 0; set p8 0; set p9 0
   128         set q0 0; set q1 0; set q2 0; set q3 0; set q4 0
   129         set q5 0; set q6 0; set q7 0; set q8 0; set q9 0
   130         set r0 0; set r1 0; set r2 0; set r3 0; set r4 0
   131         set r5 0; set r6 0; set r7 0; set r8 0; set r9 0
   132         set s0 0; set s1 0; set s2 0; set s3 0; set s4 0
   133         set s5 0; set s6 0; set s7 0; set s8 0; set s9 0
   134         set t0 0; set t1 0; set t2 0; set t3 0; set t4 0
   135         set t5 0; set t6 0; set t7 0; set t8 0; set t9 0
   136         set u0 0; set u1 0; set u2 0; set u3 0; set u4 0
   137         set u5 0; set u6 0; set u7 0; set u8 0; set u9 0
   138         set v0 0; set v1 0; set v2 0; set v3 0; set v4 0
   139         set v5 0; set v6 0; set v7 0; set v8 0; set v9 0
   140         set w0 0; set w1 0; set w2 0; set w3 0; set w4 0
   141         set w5 0; set w6 0; set w7 0; set w8 0; set w9 0
   142         set x0 0; set x1 0; set x2 0; set x3 0; set x4 0
   143         set x5 0; set x6 0; set x7 0; set x8 0; set x9 0
   144         set y0 0; set y1 0; set y2 0; set y3 0; set y4 0
   145         set y5 0; set y6 0; set y7 0; set y8 0; set y9 0
   146         set z0 0; set z1 0; set z2 0; set z3 0; set z4 0
   147         set z5 0; set z6 0; set z7 0; set z8 0; set z9 0
   148         # now increment the last one (local var index > 255)
   149         incr z9
   150     }
   151     260locals
   152 } {1}
   153 test incr-1.15 {TclCompileIncrCmd: variable is array} {
   154     catch {unset a}
   155     set a(foo) 27
   156     set x [incr a(foo) 11]
   157     catch {unset a}
   158     set x
   159 } 38
   160 test incr-1.16 {TclCompileIncrCmd: variable is array, elem substitutions} {
   161     catch {unset a}
   162     set i 5
   163     set a(foo5) 27
   164     set x [incr a(foo$i) 11]
   165     catch {unset a}
   166     set x
   167 } 38
   168 
   169 test incr-1.17 {TclCompileIncrCmd: increment given, simple int} {
   170     set i 5
   171     incr i 123
   172 } 128
   173 test incr-1.18 {TclCompileIncrCmd: increment given, simple int} {
   174     set i 5
   175     incr i -100
   176 } -95
   177 test incr-1.19 {TclCompileIncrCmd: increment given, but erroneous} {
   178     set i 5
   179     catch {incr i [set]} msg
   180     set errorInfo
   181 } {wrong # args: should be "set varName ?newValue?"
   182     while compiling
   183 "set"
   184     while compiling
   185 "incr i [set]"}
   186 test incr-1.20 {TclCompileIncrCmd: increment given, in quotes} {
   187     set i 25
   188     incr i "-100"
   189 } -75
   190 test incr-1.21 {TclCompileIncrCmd: increment given, in braces} {
   191     set i 24
   192     incr i {126}
   193 } 150
   194 test incr-1.22 {TclCompileIncrCmd: increment given, large int} {
   195     set i 5
   196     incr i 200000
   197 } 200005
   198 test incr-1.23 {TclCompileIncrCmd: increment given, formatted int != int} {
   199     set i 25
   200     incr i 000012345     ;# an octal literal
   201 } 5374
   202 test incr-1.24 {TclCompileIncrCmd: increment given, formatted int != int} {
   203     set i 25
   204     catch {incr i 1a} msg
   205     set msg
   206 } {expected integer but got "1a"}
   207 
   208 test incr-1.25 {TclCompileIncrCmd: too many arguments} {
   209     set i 10
   210     catch {incr i 10 20} msg
   211     set msg
   212 } {wrong # args: should be "incr varName ?increment?"}
   213 
   214 
   215 test incr-1.26 {TclCompileIncrCmd: runtime error, bad variable name} {
   216     list [catch {incr {"foo}} msg] $msg $errorInfo
   217 } {1 {can't read ""foo": no such variable} {can't read ""foo": no such variable
   218     (reading value of variable to increment)
   219     invoked from within
   220 "incr {"foo}"}}
   221 test incr-1.27 {TclCompileIncrCmd: runtime error, bad variable name} {
   222     list [catch {incr [set]} msg] $msg $errorInfo
   223 } {1 {wrong # args: should be "set varName ?newValue?"} {wrong # args: should be "set varName ?newValue?"
   224     while compiling
   225 "set"
   226     while compiling
   227 "incr [set]"}}
   228 test incr-1.28 {TclCompileIncrCmd: runtime error, readonly variable} {
   229     proc readonly args {error "variable is read-only"}
   230     set x 123
   231     trace var x w readonly
   232     list [catch {incr x 1} msg] $msg $errorInfo
   233 } {1 {can't set "x": variable is read-only} {can't set "x": variable is read-only
   234     while executing
   235 "incr x 1"}}
   236 catch {unset x}
   237 test incr-1.29 {TclCompileIncrCmd: runtime error, bad variable value} {
   238     set x "  -  "
   239     list [catch {incr x 1} msg] $msg
   240 } {1 {expected integer but got "  -  "}}
   241 
   242 test incr-1.30 {TclCompileIncrCmd: array var, braced (no subs)} {
   243     catch {unset array}
   244     set array(\$foo) 4
   245     incr {array($foo)}
   246 } 5
   247     
   248 # Check "incr" and computed command names.
   249 
   250 test incr-2.0 {incr and computed command names} {
   251     set i 5
   252     set z incr
   253     $z i -1
   254     set i
   255 } 4
   256 catch {unset x}
   257 catch {unset i}
   258 
   259 test incr-2.1 {incr command (not compiled): missing variable name} {
   260     set z incr
   261     list [catch {$z} msg] $msg
   262 } {1 {wrong # args: should be "incr varName ?increment?"}}
   263 test incr-2.2 {incr command (not compiled): simple variable name} {
   264     set z incr
   265     set i 10
   266     list [$z i] $i
   267 } {11 11}
   268 test incr-2.3 {incr command (not compiled): error compiling variable name} {
   269     set z incr
   270     set i 10
   271     catch {$z "i"xxx} msg
   272     set msg
   273 } {extra characters after close-quote}
   274 test incr-2.4 {incr command (not compiled): simple variable name in quotes} {
   275     set z incr
   276     set i 17
   277     list [$z "i"] $i
   278 } {18 18}
   279 test incr-2.5 {incr command (not compiled): simple variable name in braces} {
   280     set z incr
   281     catch {unset {a simple var}}
   282     set {a simple var} 27
   283     list [$z {a simple var}] ${a simple var}
   284 } {28 28}
   285 test incr-2.6 {incr command (not compiled): simple array variable name} {
   286     set z incr
   287     catch {unset a}
   288     set a(foo) 37
   289     list [$z a(foo)] $a(foo)
   290 } {38 38}
   291 test incr-2.7 {incr command (not compiled): non-simple (computed) variable name} {
   292     set z incr
   293     set x "i"
   294     set i 77
   295     list [$z $x 2] $i
   296 } {79 79}
   297 test incr-2.8 {incr command (not compiled): non-simple (computed) variable name} {
   298     set z incr
   299     set x "i"
   300     set i 77
   301     list [$z [set x] +2] $i
   302 } {79 79}
   303 
   304 test incr-2.9 {incr command (not compiled): increment given} {
   305     set z incr
   306     set i 10
   307     list [$z i +07] $i
   308 } {17 17}
   309 test incr-2.10 {incr command (not compiled): no increment given} {
   310     set z incr
   311     set i 10
   312     list [$z i] $i
   313 } {11 11}
   314 
   315 test incr-2.11 {incr command (not compiled): simple global name} {
   316     proc p {} {
   317 	set z incr
   318         global i
   319         set i 54
   320         $z i
   321     }
   322     p
   323 } {55}
   324 test incr-2.12 {incr command (not compiled): simple local name} {
   325     proc p {} {
   326 	set z incr
   327         set foo 100
   328         $z foo
   329     }
   330     p
   331 } {101}
   332 test incr-2.13 {incr command (not compiled): simple but new (unknown) local name} {
   333     proc p {} {
   334 	set z incr
   335         $z bar
   336     }
   337     catch {p} msg
   338     set msg
   339 } {can't read "bar": no such variable}
   340 test incr-2.14 {incr command (not compiled): simple local name, >255 locals} {
   341    proc 260locals {} {
   342         set z incr
   343         # create 260 locals
   344         set a0 0; set a1 0; set a2 0; set a3 0; set a4 0
   345         set a5 0; set a6 0; set a7 0; set a8 0; set a9 0
   346         set b0 0; set b1 0; set b2 0; set b3 0; set b4 0
   347         set b5 0; set b6 0; set b7 0; set b8 0; set b9 0
   348         set c0 0; set c1 0; set c2 0; set c3 0; set c4 0
   349         set c5 0; set c6 0; set c7 0; set c8 0; set c9 0
   350         set d0 0; set d1 0; set d2 0; set d3 0; set d4 0
   351         set d5 0; set d6 0; set d7 0; set d8 0; set d9 0
   352         set e0 0; set e1 0; set e2 0; set e3 0; set e4 0
   353         set e5 0; set e6 0; set e7 0; set e8 0; set e9 0
   354         set f0 0; set f1 0; set f2 0; set f3 0; set f4 0
   355         set f5 0; set f6 0; set f7 0; set f8 0; set f9 0
   356         set g0 0; set g1 0; set g2 0; set g3 0; set g4 0
   357         set g5 0; set g6 0; set g7 0; set g8 0; set g9 0
   358         set h0 0; set h1 0; set h2 0; set h3 0; set h4 0
   359         set h5 0; set h6 0; set h7 0; set h8 0; set h9 0
   360         set i0 0; set i1 0; set i2 0; set i3 0; set i4 0
   361         set i5 0; set i6 0; set i7 0; set i8 0; set i9 0
   362         set j0 0; set j1 0; set j2 0; set j3 0; set j4 0
   363         set j5 0; set j6 0; set j7 0; set j8 0; set j9 0
   364         set k0 0; set k1 0; set k2 0; set k3 0; set k4 0
   365         set k5 0; set k6 0; set k7 0; set k8 0; set k9 0
   366         set l0 0; set l1 0; set l2 0; set l3 0; set l4 0
   367         set l5 0; set l6 0; set l7 0; set l8 0; set l9 0
   368         set m0 0; set m1 0; set m2 0; set m3 0; set m4 0
   369         set m5 0; set m6 0; set m7 0; set m8 0; set m9 0
   370         set n0 0; set n1 0; set n2 0; set n3 0; set n4 0
   371         set n5 0; set n6 0; set n7 0; set n8 0; set n9 0
   372         set o0 0; set o1 0; set o2 0; set o3 0; set o4 0
   373         set o5 0; set o6 0; set o7 0; set o8 0; set o9 0
   374         set p0 0; set p1 0; set p2 0; set p3 0; set p4 0
   375         set p5 0; set p6 0; set p7 0; set p8 0; set p9 0
   376         set q0 0; set q1 0; set q2 0; set q3 0; set q4 0
   377         set q5 0; set q6 0; set q7 0; set q8 0; set q9 0
   378         set r0 0; set r1 0; set r2 0; set r3 0; set r4 0
   379         set r5 0; set r6 0; set r7 0; set r8 0; set r9 0
   380         set s0 0; set s1 0; set s2 0; set s3 0; set s4 0
   381         set s5 0; set s6 0; set s7 0; set s8 0; set s9 0
   382         set t0 0; set t1 0; set t2 0; set t3 0; set t4 0
   383         set t5 0; set t6 0; set t7 0; set t8 0; set t9 0
   384         set u0 0; set u1 0; set u2 0; set u3 0; set u4 0
   385         set u5 0; set u6 0; set u7 0; set u8 0; set u9 0
   386         set v0 0; set v1 0; set v2 0; set v3 0; set v4 0
   387         set v5 0; set v6 0; set v7 0; set v8 0; set v9 0
   388         set w0 0; set w1 0; set w2 0; set w3 0; set w4 0
   389         set w5 0; set w6 0; set w7 0; set w8 0; set w9 0
   390         set x0 0; set x1 0; set x2 0; set x3 0; set x4 0
   391         set x5 0; set x6 0; set x7 0; set x8 0; set x9 0
   392         set y0 0; set y1 0; set y2 0; set y3 0; set y4 0
   393         set y5 0; set y6 0; set y7 0; set y8 0; set y9 0
   394         set z0 0; set z1 0; set z2 0; set z3 0; set z4 0
   395         set z5 0; set z6 0; set z7 0; set z8 0; set z9 0
   396         # now increment the last one (local var index > 255)
   397         $z z9
   398     }
   399     260locals
   400 } {1}
   401 test incr-2.15 {incr command (not compiled): variable is array} {
   402     set z incr
   403     catch {unset a}
   404     set a(foo) 27
   405     set x [$z a(foo) 11]
   406     catch {unset a}
   407     set x
   408 } 38
   409 test incr-2.16 {incr command (not compiled): variable is array, elem substitutions} {
   410     set z incr
   411     catch {unset a}
   412     set i 5
   413     set a(foo5) 27
   414     set x [$z a(foo$i) 11]
   415     catch {unset a}
   416     set x
   417 } 38
   418 
   419 test incr-2.17 {incr command (not compiled): increment given, simple int} {
   420     set z incr
   421     set i 5
   422     $z i 123
   423 } 128
   424 test incr-2.18 {incr command (not compiled): increment given, simple int} {
   425     set z incr
   426     set i 5
   427     $z i -100
   428 } -95
   429 test incr-2.19 {incr command (not compiled): increment given, but erroneous} {
   430     set z incr
   431     set i 5
   432     catch {$z i [set]} msg
   433     set errorInfo
   434 } {wrong # args: should be "set varName ?newValue?"
   435     while compiling
   436 "set"
   437     while compiling
   438 "$z i [set]"}
   439 test incr-2.20 {incr command (not compiled): increment given, in quotes} {
   440     set z incr
   441     set i 25
   442     $z i "-100"
   443 } -75
   444 test incr-2.21 {incr command (not compiled): increment given, in braces} {
   445     set z incr
   446     set i 24
   447     $z i {126}
   448 } 150
   449 test incr-2.22 {incr command (not compiled): increment given, large int} {
   450     set z incr
   451     set i 5
   452     $z i 200000
   453 } 200005
   454 test incr-2.23 {incr command (not compiled): increment given, formatted int != int} {
   455     set z incr
   456     set i 25
   457     $z i 000012345     ;# an octal literal
   458 } 5374
   459 test incr-2.24 {incr command (not compiled): increment given, formatted int != int} {
   460     set z incr
   461     set i 25
   462     catch {$z i 1a} msg
   463     set msg
   464 } {expected integer but got "1a"}
   465 
   466 test incr-2.25 {incr command (not compiled): too many arguments} {
   467     set z incr
   468     set i 10
   469     catch {$z i 10 20} msg
   470     set msg
   471 } {wrong # args: should be "incr varName ?increment?"}
   472 
   473 
   474 test incr-2.26 {incr command (not compiled): runtime error, bad variable name} {
   475     set z incr
   476     list [catch {$z {"foo}} msg] $msg $errorInfo
   477 } {1 {can't read ""foo": no such variable} {can't read ""foo": no such variable
   478     (reading value of variable to increment)
   479     invoked from within
   480 "$z {"foo}"}}
   481 test incr-2.27 {incr command (not compiled): runtime error, bad variable name} {
   482     set z incr
   483     list [catch {$z [set]} msg] $msg $errorInfo
   484 } {1 {wrong # args: should be "set varName ?newValue?"} {wrong # args: should be "set varName ?newValue?"
   485     while compiling
   486 "set"
   487     while compiling
   488 "$z [set]"}}
   489 test incr-2.28 {incr command (not compiled): runtime error, readonly variable} {
   490     set z incr
   491     proc readonly args {error "variable is read-only"}
   492     set x 123
   493     trace var x w readonly
   494     list [catch {$z x 1} msg] $msg $errorInfo
   495 } {1 {can't set "x": variable is read-only} {can't set "x": variable is read-only
   496     while executing
   497 "$z x 1"}}
   498 catch {unset x}
   499 test incr-2.29 {incr command (not compiled): runtime error, bad variable value} {
   500     set z incr
   501     set x "  -  "
   502     list [catch {$z x 1} msg] $msg
   503 } {1 {expected integer but got "  -  "}}
   504 test incr-2.30 {incr command (not compiled): bad increment} {
   505     set z incr
   506     set x 0
   507     list [catch {$z x 1a} msg] $msg $errorInfo
   508 } {1 {expected integer but got "1a"} {expected integer but got "1a"
   509     (reading increment)
   510     invoked from within
   511 "$z x 1a"}}
   512 test incr-2.31 {incr command (compiled): bad increment} {
   513     list [catch {incr x 1a} msg] $msg $errorInfo
   514 } {1 {expected integer but got "1a"} {expected integer but got "1a"
   515     (reading increment)
   516     invoked from within
   517 "incr x 1a"}}
   518 
   519 # cleanup
   520 ::tcltest::cleanupTests
   521 return
   522 
   523 
   524 
   525 
   526 
   527 
   528 
   529 
   530 
   531 
   532 
   533