os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/lreplace.test
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 # Commands covered:  lreplace
     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) 1991-1993 The Regents of the University of California.
     8 # Copyright (c) 1994 Sun Microsystems, Inc.
     9 # Copyright (c) 1998-1999 by Scriptics Corporation.
    10 #
    11 # See the file "license.terms" for information on usage and redistribution
    12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    13 #
    14 # RCS: @(#) $Id: lreplace.test,v 1.7 2000/04/10 17:19:01 ericm Exp $
    15 
    16 if {[lsearch [namespace children] ::tcltest] == -1} {
    17     package require tcltest
    18     namespace import -force ::tcltest::*
    19 }
    20 
    21 test lreplace-1.1 {lreplace command} {
    22     lreplace {1 2 3 4 5} 0 0 a
    23 } {a 2 3 4 5}
    24 test lreplace-1.2 {lreplace command} {
    25     lreplace {1 2 3 4 5} 1 1 a
    26 } {1 a 3 4 5}
    27 test lreplace-1.3 {lreplace command} {
    28     lreplace {1 2 3 4 5} 2 2 a
    29 } {1 2 a 4 5}
    30 test lreplace-1.4 {lreplace command} {
    31     lreplace {1 2 3 4 5} 3 3 a
    32 } {1 2 3 a 5}
    33 test lreplace-1.5 {lreplace command} {
    34     lreplace {1 2 3 4 5} 4 4 a
    35 } {1 2 3 4 a}
    36 test lreplace-1.6 {lreplace command} {
    37     lreplace {1 2 3 4 5} 4 5 a
    38 } {1 2 3 4 a}
    39 test lreplace-1.7 {lreplace command} {
    40     lreplace {1 2 3 4 5} -1 -1 a
    41 } {a 1 2 3 4 5}
    42 test lreplace-1.8 {lreplace command} {
    43     lreplace {1 2 3 4 5} 2 end a b c d
    44 } {1 2 a b c d}
    45 test lreplace-1.9 {lreplace command} {
    46     lreplace {1 2 3 4 5} 0 3
    47 } {5}
    48 test lreplace-1.10 {lreplace command} {
    49     lreplace {1 2 3 4 5} 0 4
    50 } {}
    51 test lreplace-1.11 {lreplace command} {
    52     lreplace {1 2 3 4 5} 0 1
    53 } {3 4 5}
    54 test lreplace-1.12 {lreplace command} {
    55     lreplace {1 2 3 4 5} 2 3
    56 } {1 2 5}
    57 test lreplace-1.13 {lreplace command} {
    58     lreplace {1 2 3 4 5} 3 end
    59 } {1 2 3}
    60 test lreplace-1.14 {lreplace command} {
    61     lreplace {1 2 3 4 5} -1 4 a b c
    62 } {a b c}
    63 test lreplace-1.15 {lreplace command} {
    64     lreplace {a b "c c" d e f} 3 3
    65 } {a b {c c} e f}
    66 test lreplace-1.16 {lreplace command} {
    67     lreplace { 1 2 3 4 5} 0 0 a
    68 } {a 2 3 4 5}
    69 test lreplace-1.17 {lreplace command} {
    70     lreplace {1 2 3 4 "5 6"} 4 4 a
    71 } {1 2 3 4 a}
    72 test lreplace-1.18 {lreplace command} {
    73     lreplace {1 2 3 4 {5 6}} 4 4 a
    74 } {1 2 3 4 a}
    75 test lreplace-1.19 {lreplace command} {
    76     lreplace {1 2 3 4} 2 end x y z
    77 } {1 2 x y z}
    78 test lreplace-1.20 {lreplace command} {
    79     lreplace {1 2 3 4} end end a
    80 } {1 2 3 a}
    81 test lreplace-1.21 {lreplace command} {
    82     lreplace {1 2 3 4} end 3 a
    83 } {1 2 3 a}
    84 test lreplace-1.22 {lreplace command} {
    85     lreplace {1 2 3 4} end end
    86 } {1 2 3}
    87 test lreplace-1.23 {lreplace command} {
    88     lreplace {1 2 3 4} 2 -1 xy
    89 } {1 2 xy 3 4}
    90 test lreplace-1.24 {lreplace command} {
    91     lreplace {1 2 3 4} end -1 z
    92 } {1 2 3 z 4}
    93 test lreplace-1.25 {lreplace command} {
    94     concat \"[lreplace {\}\     hello} end end]\"
    95 } {"\}\ "}
    96 test lreplace-1.26 {lreplace command} {
    97     catch {unset foo}
    98     set foo {a b}
    99     list [set foo [lreplace $foo end end]] \
   100         [set foo [lreplace $foo end end]] \
   101         [set foo [lreplace $foo end end]]
   102 } {a {} {}}
   103 
   104 
   105 test lreplace-2.1 {lreplace errors} {
   106     list [catch lreplace msg] $msg
   107 } {1 {wrong # args: should be "lreplace list first last ?element element ...?"}}
   108 test lreplace-2.2 {lreplace errors} {
   109     list [catch {lreplace a b} msg] $msg
   110 } {1 {wrong # args: should be "lreplace list first last ?element element ...?"}}
   111 test lreplace-2.3 {lreplace errors} {
   112     list [catch {lreplace x a 10} msg] $msg
   113 } {1 {bad index "a": must be integer or end?-integer?}}
   114 test lreplace-2.4 {lreplace errors} {
   115     list [catch {lreplace x 10 x} msg] $msg
   116 } {1 {bad index "x": must be integer or end?-integer?}}
   117 test lreplace-2.5 {lreplace errors} {
   118     list [catch {lreplace x 10 1x} msg] $msg
   119 } {1 {bad index "1x": must be integer or end?-integer?}}
   120 test lreplace-2.6 {lreplace errors} {
   121     list [catch {lreplace x 3 2} msg] $msg
   122 } {1 {list doesn't contain element 3}}
   123 test lreplace-2.7 {lreplace errors} {
   124     list [catch {lreplace x 1 1} msg] $msg
   125 } {1 {list doesn't contain element 1}}
   126 
   127 test lreplace-3.1 {lreplace won't modify shared argument objects} {
   128     proc p {} {
   129         lreplace "a b c" 1 1 "x y"
   130         return "a b c"
   131     }
   132     p
   133 } "a b c"
   134 
   135 # cleanup
   136 catch {unset foo}
   137 ::tcltest::cleanupTests
   138 return