Debian Codegraph @

tests/split.test

raw
1 # Commands covered: split
2 #
3 # This file contains a collection of tests for one or more of the Tcl built-in
4 # commands. Sourcing this file into Tcl runs the tests and generates output
5 # 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-1996 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
10 #
11 # See the file "license.terms" for information on usage and redistribution of
12 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
13
14 if {"::tcltest" ni [namespace children]} {
15 package require tcltest 2.5
16 namespace import -force ::tcltest::*
17 }
18
19 test split-1.1 {basic split commands} {
20 split "a\n b\t\r c\n "
21 } {a {} b {} {} c {} {}}
22 test split-1.2 {basic split commands} {
23 split "word 1xyzword 2zword 3" xyz
24 } {{word 1} {} {} {word 2} {word 3}}
25 test split-1.3 {basic split commands} {
26 split "12345" {}
27 } {1 2 3 4 5}
28 test split-1.4 {basic split commands} {
29 split "a\}b\[c\{\]\$"
30 } "a\\}b\\\[c\\{\\\]\\\$"
31 test split-1.5 {basic split commands} {
32 split {} {}
33 } {}
34 test split-1.6 {basic split commands} {
35 split {}
36 } {}
37 test split-1.7 {basic split commands} {
38 split { }
39 } {{} {} {} {}}
40 test split-1.8 {basic split commands} {
41 proc foo {} {
42 set x {}
43 foreach f [split {]\n} {}] {
44 append x $f
45 }
46 return $x
47 }
48 foo
49 } {]\n}
50 test split-1.9 {basic split commands} {
51 proc foo {} {
52 set x ab\000c
53 set y [split $x {}]
54 return $y
55 }
56 foo
57 } "a b \000 c"
58 test split-1.10 {basic split commands} {
59 split "a0ab1b2bbb3\000c4" ab\000c
60 } {{} 0 {} 1 2 {} {} 3 {} 4}
61 test split-1.11 {basic split commands} {
62 split "12,3,45" {,}
63 } {12 3 45}
64 test split-1.12 {basic split commands} {
65 split "\u0001ab\u0001cd\u0001\u0001ef\u0001" \1
66 } {{} ab cd {} ef {}}
67 test split-1.13 {basic split commands} {
68 split "12,34,56," {,}
69 } {12 34 56 {}}
70 test split-1.14 {basic split commands} {
71 split ",12,,,34,56," {,}
72 } {{} 12 {} {} 34 56 {}}
73 test split-1.15 {basic split commands} -body {
74 split "a\U01f4a9b" {}
75 } -result "a \U01f4a9 b"
76
77 test split-2.1 {split errors} {
78 list [catch split msg] $msg $errorCode
79 } {1 {wrong # args: should be "split string ?splitChars?"} {TCL WRONGARGS}}
80 test split-2.2 {split errors} {
81 list [catch {split a b c} msg] $msg $errorCode
82 } {1 {wrong # args: should be "split string ?splitChars?"} {TCL WRONGARGS}}
83
84 test bug-c9f0520f7e "Bug c9f0520f7e Tcl_SplitList memory overflow crash" -body {
85 # [dict for] compilation calls Tcl_SplitList, thus its use. Not
86 # a bug in dict.
87 proc p {} [list dict for $str {} {}]
88 p
89 } -constraints slowTest -setup {
90 set limit 26
91 set str "0 1 2 3 4 5 6 7 8 9 "
92 for { set i 0 } { $i < $limit } { incr i } {
93 set str "$str $str"
94 }
95 } -cleanup {
96 catch {rename p {}}
97 } -result {max length of a Tcl list * exceeded} -match glob -returnCodes error
98
99 # cleanup
100 catch {rename foo {}}
101 ::tcltest::cleanupTests
102 return
103
104 # Local Variables:
105 # mode: tcl
106 # End: