zlib: Don't use PASTE for INTMAX error messages
[jimtcl.git] / tests / list.test
blobd4cecda2cc8bccb258a13be28f94aa9ed594c0e9
1 # Commands covered:  list
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.
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.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # RCS: @(#) $Id: list.test,v 1.5 2000/04/10 17:19:01 ericm Exp $
16 source [file dirname [info script]]/testing.tcl
18 # First, a bunch of individual tests
20 test list-1.1 {basic tests} {list a b c} {a b c}
21 test list-1.2 {basic tests} {list {a b} c} {{a b} c}
22 test list-1.3 {basic tests} {list \{a b c} {\{a b c}
23 test list-1.4 {basic tests} "list a{}} b{} c}" "a\\{\\}\\} b{} c\\}"
24 test list-1.5 {basic tests} {list a\[ b\] } "{a\[} b\\]"
25 test list-1.6 {basic tests} {list c\  d\t } "{c } {d\t}"
26 test list-1.7 {basic tests} {list e\n f\$ } "{e\n} {f\$}"
27 test list-1.8 {basic tests} {list g\; h\\} {{g;} h\\}
28 test list-1.9 {basic tests} "list a\\\[} b\\\]} " "a\\\[\\\} b\\\]\\\}"
29 test list-1.10 {basic tests} "list c\\\} d\\t} " "c\\} d\\t\\}"
30 test list-1.11 {basic tests} "list e\\n} f\\$} " "e\\n\\} f\\$\\}"
31 test list-1.12 {basic tests} "list g\\;} h\\\\} " "g\\;\\} {h\\}}"
32 test list-1.13 {basic tests} {list a {{}} b} {a {{}} b}
33 test list-1.14 {basic tests} {list a b xy\\} "a b xy\\\\"
34 test list-1.15 {basic tests} "list a b\} e\\" "a b\\} e\\\\"
35 test list-1.16 {basic tests} "list a b\}\\\$ e\\\$\\" "a b\\}\\\$ e\\\$\\\\"
36 test list-1.17 {basic tests} {list a\f \{\f} "{a\f} \\\{\\f"
37 test list-1.18 {basic tests} {list a\r \{\r} "{a\r} \\\{\\r"
38 test list-1.19 {basic tests} {list a\v \{\v} "{a\v} \\\{\\v"
39 test list-1.20 {basic tests} {list \"\}\{} "\\\"\\}\\{"
40 test list-1.21 {basic tests} {list a b c\\\nd} "a b c\\\\\\nd"
41 test list-1.22 {basic tests} {list "{ab}\\"} \\{ab\\}\\\\
42 test list-1.23 {basic tests} {list \{} "\\{"
43 test list-1.24 {basic tests} {list} {}
44 test list-1.25 {basic tests} {list #} {{#}}
45 test list-1.26 {basic tests} {list #abc} {{#abc}}
46 test list-1.27 {basic tests} {list def #abc} {def #abc}
48 # For the next round of tests create a list and then pick it apart
49 # with "index" to make sure that we get back exactly what went in.
51 test list-2.1 {placeholder} {
52 } {}
53 set num 1
54 proc lcheck {a b c} {
55     global num d
56     set d [list $a $b $c]
57 ;   test list-2.$num {what goes in must come out} {lindex $d 0} $a
58     set num [expr $num+1]
59 ;   test list-2.$num {what goes in must come out} {lindex $d 1} $b
60     set num [expr $num+1]
61 ;   test list-2.$num {what goes in must come out} {lindex $d 2} $c
62     set num [expr $num+1]
64 lcheck a b c
65 lcheck "a b" c\td e\nf
66 lcheck {{a b}} {} {  }
67 lcheck \$ \$ab ab\$
68 lcheck \; \;ab ab\;
69 lcheck \[ \[ab ab\[
70 lcheck \\ \\ab ab\\
71 lcheck {"} {"ab} {ab"}
72 lcheck {a b} { ab} {ab }
73 lcheck a{ a{b \{ab
74 lcheck a} a}b }ab
75 lcheck a\\} {a \}b} {a \{c}
76 lcheck xyz \\ 1\\\n2
77 lcheck "{ab}\\" "{ab}xy" abc
79 concat {}
81 # Check that tclListObj.c's SetListFromAny handles possible overlarge
82 # string rep lengths in the source object.
84 proc slowsort list {
85     set result {}
86     set last [expr [llength $list] - 1]
87     while {$last > 0} {
88         set minIndex [expr [llength $list] - 1]
89         set min [lindex $list $last]
90         set i [expr $minIndex-1]
91         while {$i >= 0} {
92             if {[string compare [lindex $list $i] $min] < 0} {
93                 set minIndex $i
94                 set min [lindex $list $i]
95             }
96             set i [expr $i-1]
97         }
98         set result [concat $result [list $min]]
99         if {$minIndex == 0} {
100             set list [lrange $list 1 end]
101         } else {
102             set list [concat [lrange $list 0 [expr $minIndex-1]] \
103                           [lrange $list [expr $minIndex+1] end]]
104         }
105         set last [expr $last-1]
106     }
107     return [concat $result $list]
109 test list-3.1 {SetListFromAny and lrange/concat results} {
110     slowsort {fred julie alex carol bill annie}
111 } {alex annie bill carol fred julie}
113 testreport