source: trunk/lang/tcl/tests/slice.test @ 3177

Last change on this file since 3177 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 3.4 KB
Line 
1# Commands covered: Rappture::slice
2#
3# This file contains a collection of tests for one of the Rappture Tcl
4# commands.  Sourcing this file into Tcl runs the tests and
5# generates output for errors.  No output means no errors were found.
6#
7# ======================================================================
8# AUTHOR:  Michael McLennan, Purdue University
9# Copyright (c) 2004-2012  HUBzero Foundation, LLC
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
15if {[lsearch [namespace children] ::tcltest] == -1} {
16    package require tcltest
17    package require Rappture
18    namespace import -force ::tcltest::*
19}
20
21#----------------------------------------------------------
22# Check command line switches and proper args
23#----------------------------------------------------------
24test slice-1.1 {requires at least one arg} {
25    list [catch {Rappture::slice} msg] $msg
26} {1 {wrong # args: should be "Rappture::slice ?-open chars? ?-close chars? ?-separators chars? ?--? string}}
27
28test slice-1.2 {has certain options} {
29    list [catch {Rappture::slice -foo string} msg] $msg
30} {1 {bad option "-foo": should be -open, -close, -separators, --}}
31
32test slice-1.3 {options require values} {
33    list [catch {Rappture::slice -separators string} msg] $msg
34} {1 {wrong # args: should be "Rappture::slice ?-open chars? ?-close chars? ?-separators chars? ?--? string}}
35
36test slice-1.4 {open/close quote lists must match} {
37    list [catch {Rappture::slice -open 1 -close 12 string} msg] $msg
38} {1 {must have same number of quote characters for -open and -close}}
39
40test slice-1.5 {can't have multiple strings} {
41    list [catch {Rappture::slice -separators ab string1 string2} msg] $msg
42} {1 {wrong # args: should be "Rappture::slice ?-open chars? ?-close chars? ?-separators chars? ?--? string}}
43
44test slice-1.6 {use -- when string starts with -} {
45    list [catch {Rappture::slice -- "-foo -bar"} msg] $msg
46} {0 {-foo -bar}}
47
48#----------------------------------------------------------
49# Check the rules for splitting
50#----------------------------------------------------------
51test slice-2.1 {multiple separator chars are lumped together} {
52    Rappture::slice -separators ", \t\n" "one,  two ,  three  "
53} {one two three}
54
55test slice-2.2 {leading separators are ignored} {
56    Rappture::slice -separators ", \t\n" ",, one,  two,"
57} {one two}
58
59test slice-2.3 {quote characters keep things together} {
60    Rappture::slice -open \" -close \" {"foo bar" "baz"  " qux "}
61} {{foo bar} baz { qux }}
62
63test slice-2.4 {embedded quotes are ignored} {
64    Rappture::slice -open \" -close \" {foo"bar "baz\""  \"qux}
65} {foo\"bar {baz\"} {\"qux}}
66
67test slice-2.5 {trailing quote doesn't dump core} {
68    Rappture::slice -open \" -close \" {foo"bar "baz"  \"qux "}
69} {foo\"bar baz {\"qux} {}}
70
71test slice-2.6 {close quote corresponds to open quote} {
72    Rappture::slice -open \"< -close \"> { <foo bar> <a b " c> "a<>b" }
73} {{foo bar} {a b " c} a<>b}
74
75test slice-2.7 {close quote can be escaped} {
76    Rappture::slice -open \"< -close \"> { <<foo bar\>> <a  b> }
77} {{<foo bar\>} {a  b}}
78
79test slice-2.8 {can override standard separators} {
80    Rappture::slice -separators : { 1eV : 2 eV : 0.1}
81} {{ 1eV } { 2 eV } { 0.1}}
82
83test slice-2.9 {no quotes by default} {
84    Rappture::slice -separators : { "1eV : 2 eV" : 0.1}
85} {{ "1eV } { 2 eV" } { 0.1}}
86
87::tcltest::cleanupTests
88return
Note: See TracBrowser for help on using the repository browser.