Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tests/split.test @ 68

Last change on this file since 68 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 2.4 KB
Line 
1# Commands covered:  split
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-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
12# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13#
14# RCS: @(#) $Id: split.test,v 1.9 2004/05/19 10:50:30 dkf Exp $
15
16if {[lsearch [namespace children] ::tcltest] == -1} {
17    package require tcltest
18    namespace import -force ::tcltest::*
19}
20
21test split-1.1 {basic split commands} {
22    split "a\n b\t\r c\n "
23} {a {} b {} {} c {} {}}
24test split-1.2 {basic split commands} {
25    split "word 1xyzword 2zword 3" xyz
26} {{word 1} {} {} {word 2} {word 3}}
27test split-1.3 {basic split commands} {
28    split "12345" {}
29} {1 2 3 4 5}
30test split-1.4 {basic split commands} {
31    split "a\}b\[c\{\]\$"
32} "a\\}b\\\[c\\{\\\]\\\$"
33test split-1.5 {basic split commands} {
34    split {} {}
35} {}
36test split-1.6 {basic split commands} {
37    split {}
38} {}
39test split-1.7 {basic split commands} {
40    split {   }
41} {{} {} {} {}}
42test split-1.8 {basic split commands} {
43    proc foo {} {
44        set x {}
45        foreach f [split {]\n} {}] {
46            append x $f
47        }
48        return $x       
49    }
50    foo
51} {]\n}
52test split-1.9 {basic split commands} {
53    proc foo {} {
54        set x ab\000c
55        set y [split $x {}]
56        return $y
57    }
58    foo
59} "a b \000 c"
60test split-1.10 {basic split commands} {
61    split "a0ab1b2bbb3\000c4" ab\000c
62} {{} 0 {} 1 2 {} {} 3 {} 4}
63test split-1.11 {basic split commands} {
64    split "12,3,45" {,}
65} {12 3 45}
66test split-1.12 {basic split commands} {
67    split "\u0001ab\u0001cd\u0001\u0001ef\u0001" \1
68} {{} ab cd {} ef {}}
69test split-1.13 {basic split commands} {
70    split "12,34,56," {,}
71} {12 34 56 {}}
72test split-1.14 {basic split commands} {
73    split ",12,,,34,56," {,}
74} {{} 12 {} {} 34 56 {}}
75
76test split-2.1 {split errors} {
77    list [catch split msg] $msg $errorCode
78} {1 {wrong # args: should be "split string ?splitChars?"} NONE}
79test split-2.2 {split errors} {
80    list [catch {split a b c} msg] $msg $errorCode
81} {1 {wrong # args: should be "split string ?splitChars?"} NONE}
82
83# cleanup
84catch {rename foo {}}
85::tcltest::cleanupTests
86return
Note: See TracBrowser for help on using the repository browser.