summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorhershey <hershey>1999-06-08 02:59:23 (GMT)
committerhershey <hershey>1999-06-08 02:59:23 (GMT)
commit0e53e351cd3c0bdf51b84e459262c47f913c9a97 (patch)
tree87cee8e23f1c9f621f583c5d97e3e62979935fa9 /tests
parentb2759d9c544b22071eca46475d110812304e8faa (diff)
downloadtcl-0e53e351cd3c0bdf51b84e459262c47f913c9a97.zip
tcl-0e53e351cd3c0bdf51b84e459262c47f913c9a97.tar.gz
tcl-0e53e351cd3c0bdf51b84e459262c47f913c9a97.tar.bz2
* tests/string.test:
* generic/tclVar.c (Tcl_SetVar2Ex): * generic/tclStringObj.c (Tcl_AppendObjToObj): * generic/tclCmdMZ.c (Tcl_StringObjCmd): optimized the string index, string length, string range, and append command in cases where the object's internal rep is a bytearray. Objects with other internal reps are converted to have the new unicode internal rep. * unix/Makefile.in: * win/Makefile.in: * win/Makefile.vc: * tests/unicode.test: * generic/tclInt.h: * generic/tclObj.c: * generic/tclUnicodeObj.c: added a new object type to store the unicode representation of a string. * generic/tclTestObj.c: added the objtype option to the testobj command. This option returns the name of the type of internal rep an object has.
Diffstat (limited to 'tests')
-rw-r--r--tests/string.test31
-rw-r--r--tests/unicode.test204
2 files changed, 234 insertions, 1 deletions
diff --git a/tests/string.test b/tests/string.test
index 01ad4bf..235dba8 100644
--- a/tests/string.test
+++ b/tests/string.test
@@ -11,12 +11,17 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: string.test,v 1.11 1999/06/03 18:43:30 stanton Exp $
+# RCS: @(#) $Id: string.test,v 1.12 1999/06/08 02:59:28 hershey Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
source [file join [pwd] [file dirname [info script]] defs.tcl]
}
+# Some tests require the testobj command
+
+set ::tcltest::testConfig(testobj) \
+ [expr {[info commands testobj] != {}}]
+
test string-1.1 {error conditions} {
list [catch {string gorp a b} msg] $msg
} {1 {bad option "gorp": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, tolower, toupper, totitle, trim, trimleft, trimright, wordend, or wordstart}}
@@ -226,6 +231,18 @@ test string-5.11 {string index, unicode} {
test string-5.12 {string index, unicode over char length, under byte length} {
string index \334\374\334\374 6
} {}
+test string-5.13 {string index, bytearray object} {
+ string index [binary format a5 fuz] 0
+} f
+test string-5.14 {string index, bytearray object} {
+ string index [binary format I* {0x50515253 0x52}] 3
+} S
+test string-5.15 {string index, bytearray object} {
+ set b [binary format I* {0x50515253 0x52}]
+ set i1 [string index $b end-6]
+ set i2 [string index $b 1]
+ string compare $i1 $i2
+} 0
test string-6.1 {string is, too few args} {
list [catch {string is} msg] $msg
@@ -585,6 +602,12 @@ test string-9.4 {string length} {
test string-9.5 {string length, unicode} {
string le "abcd\u7266"
} 5
+test string-9.6 {string length, bytearray object} {
+ string length [binary format a5 foo]
+} 5
+test string-9.7 {string length, bytearray object} {
+ string length [binary format I* {0x50515253 0x52}]
+} 8
test string-10.1 {string map, too few args} {
list [catch {string map} msg] $msg
@@ -798,6 +821,12 @@ test string-12.17 {string range, unicode} {
test string-12.18 {string range, unicode} {
string range ab\u7266cdefghijklmnop 2 3
} \u7266c
+test string-12.19 {string range, bytearray object} {
+ set b [binary format I* {0x50515253 0x52}]
+ set r1 [string range $b 1 end-1]
+ set r2 [string range $b 1 6]
+ string compare $r1 $r2
+} 0
test string-13.1 {string repeat} {
list [catch {string repeat} msg] $msg
diff --git a/tests/unicode.test b/tests/unicode.test
new file mode 100644
index 0000000..6ee91c8
--- /dev/null
+++ b/tests/unicode.test
@@ -0,0 +1,204 @@
+# This file tests the tclUnicode.c file.
+#
+# This file contains a collection of tests for one or more of the Tcl
+# built-in commands. Sourcing this file into Tcl runs the tests and
+# generates output for errors. No output means no errors were found.
+#
+# Copyright (c) 1999 by Scriptics Corporation.
+#
+# See the file "license.terms" for information on usage and redistribution
+# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+#
+# RCS: @(#) $Id: unicode.test,v 1.2 1999/06/08 02:59:30 hershey Exp $
+
+if {[lsearch [namespace children] ::tcltest] == -1} {
+ source [file join [pwd] [file dirname [info script]] defs.tcl]
+}
+
+# Some tests require the testobj command
+
+set ::tcltest::testConfig(testobj) \
+ [expr {[info commands testobj] != {}}]
+
+test unicode-1.1 {TclGetUniCharFromObj with byte-size chars} {
+ string index "abcdefghi" 0
+} "a"
+test unicode-1.2 {TclGetUniCharFromObj with byte-size chars} {
+ string index "abcdefghi" 3
+} "d"
+test unicode-1.3 {TclGetUniCharFromObj with byte-size chars} {
+ string index "abcdefghi" end
+} "i"
+test unicode-1.4 {TclGetUniCharFromObj with mixed width chars} {
+ string index "ïa¿b®c®¿dï" 0
+} "ï"
+test unicode-1.5 {TclGetUniCharFromObj} {
+ string index "ïa¿b®c®¿dï" 4
+} "®"
+test unicode-1.6 {TclGetUniCharFromObj} {
+ string index "ïa¿b®cï¿d®" end
+} "®"
+
+test unicode-2.1 {TclGetUnicodeLengthFromObj with byte-size chars} {
+ string length ""
+} 0
+test unicode-2.2 {TclGetUnicodeLengthFromObj with byte-size chars} {
+ string length "a"
+} 1
+test unicode-2.3 {TclGetUnicodeLengthFromObj with byte-size chars} {
+ string length "abcdef"
+} 6
+test unicode-2.4 {TclGetUnicodeLengthFromObj with mixed width chars} {
+ string length "®"
+} 1
+test unicode-2.5 {TclGetUnicodeLengthFromObj with mixed width chars} {
+ string length "○○"
+} 6
+test unicode-2.6 {TclGetUnicodeLengthFromObj with mixed width chars} {
+ string length "ïa¿b®cï¿d®"
+} 10
+
+test unicode-3.1 {TclGetRangeFromObj with all byte-size chars} {testobj} {
+ set x "abcdef"
+ list [testobj objtype $x] [set y [string range $x 1 end-1]] \
+ [testobj objtype $x] [testobj objtype $y]
+} {none bcde unicode none}
+
+test unicode-3.2 {TclGetRangeFromObj with some mixed width chars} {testobj} {
+ set x "abcïïdef"
+ list [testobj objtype $x] [set y [string range $x 1 end-1]] \
+ [testobj objtype $x] [testobj objtype $y]
+} {none bcïïde unicode unicode}
+
+test unicode-4.1 {UpdateStringOfUnicode} {testobj} {
+ set x 2345
+ list [string index $x end] [testobj objtype $x] [incr x] \
+ [testobj objtype $x]
+} {5 unicode 2346 int}
+
+test unicode-5.1 {SetUnicodeFromAny called with non-unicode obj} {testobj} {
+ set x 2345
+ list [incr x] [testobj objtype $x] [string index $x end] \
+ [testobj objtype $x]
+} {2346 int 6 unicode}
+
+test unicode-5.2 {SetUnicodeFromAny called with unicode obj} {testobj} {
+ set x "abcdef"
+ list [string length $x] [testobj objtype $x] \
+ [string length $x] [testobj objtype $x]
+} {6 unicode 6 unicode}
+
+test unicode-6.1 {DupUnicodeInternalRep, mixed width chars} {testobj} {
+ set x abcï¿®ghi
+ string length $x
+ set y $x
+ list [testobj objtype $x] [testobj objtype $y] [append x "®¿ï"] \
+ [set y] [testobj objtype $x] [testobj objtype $y]
+} {unicode unicode abcï¿®ghi®¿ï abcï¿®ghi unicode unicode}
+
+test unicode-6.2 {DupUnicodeInternalRep, mixed width chars} {testobj} {
+ set x abcï¿®ghi
+ set y $x
+ string length $x
+ list [testobj objtype $x] [testobj objtype $y] [append x "®¿ï"] \
+ [set y] [testobj objtype $x] [testobj objtype $y]
+} {unicode unicode abcï¿®ghi®¿ï abcï¿®ghi unicode unicode}
+
+test unicode-6.3 {DupUnicodeInternalRep, all byte-size chars} {testobj} {
+ set x abcdefghi
+ string length $x
+ set y $x
+ list [testobj objtype $x] [testobj objtype $y] [append x jkl] \
+ [set y] [testobj objtype $x] [testobj objtype $y]
+} {unicode unicode abcdefghijkl abcdefghi unicode unicode}
+
+test unicode-6.4 {DupUnicodeInternalRep, all byte-size chars} {testobj} {
+ set x abcdefghi
+ set y $x
+ string length $x
+ list [testobj objtype $x] [testobj objtype $y] [append x jkl] \
+ [set y] [testobj objtype $x] [testobj objtype $y]
+} {unicode unicode abcdefghijkl abcdefghi unicode unicode}
+
+test unicode-7.1 {TclAppendObjToUnicodeObj, mixed src & dest} {testobj} {
+ set x abcï¿®ghi
+ set y ®¿ï
+ string length $x
+ list [testobj objtype $x] [testobj objtype $y] [append x $y] \
+ [set y] [testobj objtype $x] [testobj objtype $y]
+} {unicode none abcï¿®ghi®¿ï ®¿ï unicode unicode}
+
+test unicode-7.2 {TclAppendObjToUnicodeObj, mixed src & dest} {testobj} {
+ set x abcï¿®ghi
+ string length $x
+ list [testobj objtype $x] [append x $x] [testobj objtype $x] \
+ [append x $x] [testobj objtype $x]
+} {unicode abcï¿®ghiabcï¿®ghi unicode\
+abcï¿®ghiabcï¿®ghiabcï¿®ghiabcï¿®ghi\
+unicode}
+
+test unicode-7.3 {TclAppendObjToUnicodeObj, mixed src & 1-byte dest} {testobj} {
+ set x abcdefghi
+ set y ®¿ï
+ string length $x
+ list [testobj objtype $x] [testobj objtype $y] [append x $y] \
+ [set y] [testobj objtype $x] [testobj objtype $y]
+} {unicode none abcdefghi®¿ï ®¿ï string unicode}
+
+test unicode-7.4 {TclAppendObjToUnicodeObj, 1-byte src & dest} {testobj} {
+ set x abcdefghi
+ set y jkl
+ string length $x
+ list [testobj objtype $x] [testobj objtype $y] [append x $y] \
+ [set y] [testobj objtype $x] [testobj objtype $y]
+} {unicode none abcdefghijkl jkl unicode unicode}
+
+test unicode-7.5 {TclAppendObjToUnicodeObj, 1-byte src & dest} {testobj} {
+ set x abcdefghi
+ string length $x
+ list [testobj objtype $x] [append x $x] [testobj objtype $x] \
+ [append x $x] [testobj objtype $x]
+} {unicode abcdefghiabcdefghi unicode abcdefghiabcdefghiabcdefghiabcdefghi\
+unicode}
+
+test unicode-7.6 {TclAppendObjToUnicodeObj, 1-byte src & mixed dest} {testobj} {
+ set x abcï¿®ghi
+ set y jkl
+ string length $x
+ list [testobj objtype $x] [testobj objtype $y] [append x $y] \
+ [set y] [testobj objtype $x] [testobj objtype $y]
+} {unicode none abcï¿®ghijkl jkl unicode unicode}
+
+test unicode-7.7 {TclAppendObjToUnicodeObj, integer src & dest} {testobj} {
+ set x [expr {4 * 5}]
+ set y [expr {4 + 5}]
+ list [testobj objtype $x] [testobj objtype $y] [append x $y] \
+ [testobj objtype $x] [append x $y] [testobj objtype $x] \
+ [testobj objtype $y]
+} {int int 209 string 2099 string int}
+
+test unicode-7.8 {TclAppendObjToUnicodeObj, integer src & dest} {testobj} {
+ set x [expr {4 * 5}]
+ list [testobj objtype $x] [append x $x] [testobj objtype $x] \
+ [append x $x] [testobj objtype $x]
+} {int 2020 string 20202020 unicode}
+
+test unicode-7.9 {TclAppendObjToUnicodeObj, integer src & 1-byte dest} {testobj} {
+ set x abcdefghi
+ set y [expr {4 + 5}]
+ string length $x
+ list [testobj objtype $x] [testobj objtype $y] [append x $y] \
+ [set y] [testobj objtype $x] [testobj objtype $y]
+} {unicode int abcdefghi9 9 string int}
+
+test unicode-7.10 {TclAppendObjToUnicodeObj, integer src & mixed dest} {testobj} {
+ set x abcï¿®ghi
+ set y [expr {4 + 5}]
+ string length $x
+ list [testobj objtype $x] [testobj objtype $y] [append x $y] \
+ [set y] [testobj objtype $x] [testobj objtype $y]
+} {unicode int abcï¿®ghi9 9 unicode int}
+
+# cleanup
+::tcltest::cleanupTests
+return