summaryrefslogtreecommitdiffstats
path: root/tests/stringObj.test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/stringObj.test')
-rw-r--r--tests/stringObj.test106
1 files changed, 55 insertions, 51 deletions
diff --git a/tests/stringObj.test b/tests/stringObj.test
index 3b25592..8209142 100644
--- a/tests/stringObj.test
+++ b/tests/stringObj.test
@@ -1,25 +1,29 @@
# Commands covered: none
#
-# This file contains tests for the procedures in tclStringObj.c
-# that implement the Tcl type manager for the string type.
+# This file contains tests for the procedures in tclStringObj.c that implement
+# the Tcl type manager for the string type.
#
-# Sourcing this file into Tcl runs the tests and generates output for
-# errors. No output means no errors were found.
+# Sourcing this file into Tcl runs the tests and generates output for errors.
+# No output means no errors were found.
#
# Copyright (c) 1995-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-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.
+# See the file "license.terms" for information on usage and redistribution of
+# this file, and for a DISCLAIMER OF ALL WARRANTIES.
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
namespace import -force ::tcltest::*
}
+::tcltest::loadTestedCommands
+catch [list package require -exact Tcltest [info patchlevel]]
+
testConstraint testobj [llength [info commands testobj]]
+testConstraint testbytestring [llength [info commands testbytestring]]
testConstraint testdstring [llength [info commands testdstring]]
-
+
test stringObj-1.1 {string type registration} testobj {
set t [testobj types]
set first [string first "string" $t]
@@ -38,7 +42,7 @@ test stringObj-3.1 {Tcl_SetStringObj, existing "empty string" object} testobj {
set result ""
lappend result [testobj freeallvars]
lappend result [testobj newobj 1]
- lappend result [teststringobj set 1 xyz] ;# makes existing obj a string
+ lappend result [teststringobj set 1 xyz] ;# makes existing obj a string
lappend result [testobj type 1]
lappend result [testobj refcount 1]
} {{} {} xyz string 2}
@@ -46,7 +50,7 @@ test stringObj-3.2 {Tcl_SetStringObj, existing non-"empty string" object} testob
set result ""
lappend result [testobj freeallvars]
lappend result [testintobj set 1 512]
- lappend result [teststringobj set 1 foo] ;# makes existing obj a string
+ lappend result [teststringobj set 1 foo] ;# makes existing obj a string
lappend result [testobj type 1]
lappend result [testobj refcount 1]
} {{} 512 foo string 2}
@@ -134,7 +138,7 @@ test stringObj-6.5 {Tcl_AppendStringsToObj procedure, don't double space if init
testobj newobj 1
teststringobj appendstrings 1 123 abcdefg
list [teststringobj length 1] [teststringobj length2 1] [teststringobj get 1]
-} {10 10 123abcdefg}
+} {10 20 123abcdefg}
test stringObj-6.6 {Tcl_AppendStringsToObj procedure, space reallocation} testobj {
testobj freeallvars
teststringobj set 1 abc
@@ -197,24 +201,24 @@ test stringObj-8.1 {DupStringInternalRep procedure} testobj {
teststringobj append 1 abcde -1
testobj duplicate 1 2
list [teststringobj length 1] [teststringobj length2 1] \
- [teststringobj ualloc 1] [teststringobj get 1] \
+ [teststringobj maxchars 1] [teststringobj get 1] \
[teststringobj length 2] [teststringobj length2 2] \
- [teststringobj ualloc 2] [teststringobj get 2]
+ [teststringobj maxchars 2] [teststringobj get 2]
} {5 10 0 abcde 5 5 0 abcde}
test stringObj-8.2 {DupUnicodeInternalRep, mixed width chars} testobj {
- set x abcï¿®ghi
+ set x abc\u00ef\u00bf\u00aeghi
string length $x
set y $x
- list [testobj objtype $x] [testobj objtype $y] [append x "®¿ï"] \
+ list [testobj objtype $x] [testobj objtype $y] [append x "\u00ae\u00bf\u00ef"] \
[set y] [testobj objtype $x] [testobj objtype $y]
-} {string string abcï¿®ghi®¿ï abcï¿®ghi string string}
+} "string string abc\u00ef\u00bf\u00aeghi\u00ae\u00bf\u00ef abc\u00ef\u00bf\u00aeghi string string"
test stringObj-8.3 {DupUnicodeInternalRep, mixed width chars} testobj {
- set x abcï¿®ghi
+ set x abc\u00ef\u00bf\u00aeghi
set y $x
string length $x
- list [testobj objtype $x] [testobj objtype $y] [append x "®¿ï"] \
+ list [testobj objtype $x] [testobj objtype $y] [append x "\u00ae\u00bf\u00ef"] \
[set y] [testobj objtype $x] [testobj objtype $y]
-} {string string abcï¿®ghi®¿ï abcï¿®ghi string string}
+} "string string abc\u00ef\u00bf\u00aeghi\u00ae\u00bf\u00ef abc\u00ef\u00bf\u00aeghi string string"
test stringObj-8.4 {DupUnicodeInternalRep, all byte-size chars} testobj {
set x abcdefghi
string length $x
@@ -237,16 +241,16 @@ test stringObj-9.1 {TclAppendObjToObj, mixed src & dest} {testobj testdstring} {
set y [testdstring get]
string length $x
list [testobj objtype $x] [testobj objtype $y] [append x $y] \
- [set y] [testobj objtype $x] [testobj objtype $y]
+ [set y] [testobj objtype $x] [testobj objtype $y]
} "string none abc\u00ef\u00bf\u00aeghi\u00ae\u00bf\u00ef \u00ae\u00bf\u00ef string none"
test stringObj-9.2 {TclAppendObjToObj, mixed src & dest} testobj {
- set x abcï¿®ghi
+ set x abc\u00ef\u00bf\u00aeghi
string length $x
list [testobj objtype $x] [append x $x] [testobj objtype $x] \
[append x $x] [testobj objtype $x]
-} {string abcï¿®ghiabcï¿®ghi string\
-abcï¿®ghiabcï¿®ghiabcï¿®ghiabcï¿®ghi\
-string}
+} "string abc\u00ef\u00bf\u00aeghiabc\u00ef\u00bf\u00aeghi string\
+abc\u00ef\u00bf\u00aeghiabc\u00ef\u00bf\u00aeghiabc\u00ef\u00bf\u00aeghiabc\u00ef\u00bf\u00aeghi\
+string"
test stringObj-9.3 {TclAppendObjToObj, mixed src & 1-byte dest} {testobj testdstring} {
set x abcdefghi
testdstring free
@@ -254,7 +258,7 @@ test stringObj-9.3 {TclAppendObjToObj, mixed src & 1-byte dest} {testobj testdst
set y [testdstring get]
string length $x
list [testobj objtype $x] [testobj objtype $y] [append x $y] \
- [set y] [testobj objtype $x] [testobj objtype $y]
+ [set y] [testobj objtype $x] [testobj objtype $y]
} "string none abcdefghi\u00ae\u00bf\u00ef \u00ae\u00bf\u00ef string none"
test stringObj-9.4 {TclAppendObjToObj, 1-byte src & dest} {testobj testdstring} {
set x abcdefghi
@@ -263,7 +267,7 @@ test stringObj-9.4 {TclAppendObjToObj, 1-byte src & dest} {testobj testdstring}
set y [testdstring get]
string length $x
list [testobj objtype $x] [testobj objtype $y] [append x $y] \
- [set y] [testobj objtype $x] [testobj objtype $y]
+ [set y] [testobj objtype $x] [testobj objtype $y]
} {string none abcdefghijkl jkl string none}
test stringObj-9.5 {TclAppendObjToObj, 1-byte src & dest} testobj {
set x abcdefghi
@@ -279,7 +283,7 @@ test stringObj-9.6 {TclAppendObjToObj, 1-byte src & mixed dest} {testobj testdst
set y [testdstring get]
string length $x
list [testobj objtype $x] [testobj objtype $y] [append x $y] \
- [set y] [testobj objtype $x] [testobj objtype $y]
+ [set y] [testobj objtype $x] [testobj objtype $y]
} "string none abc\u00ef\u00bf\u00aeghijkl jkl string none"
test stringObj-9.7 {TclAppendObjToObj, integer src & dest} testobj {
set x [expr {4 * 5}]
@@ -301,20 +305,19 @@ test stringObj-9.9 {TclAppendObjToObj, integer src & 1-byte dest} testobj {
[set y] [testobj objtype $x] [testobj objtype $y]
} {string int abcdefghi9 9 string int}
test stringObj-9.10 {TclAppendObjToObj, integer src & mixed dest} testobj {
- set x abcï¿®ghi
+ set x abc\u00ef\u00bf\u00aeghi
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]
-} {string int abcï¿®ghi9 9 string int}
+} "string int abc\u00ef\u00bf\u00aeghi9 9 string int"
test stringObj-9.11 {TclAppendObjToObj, mixed src & 1-byte dest index check} testobj {
# bug 2678, in <=8.2.0, the second obj (the one to append) in
- # Tcl_AppendObjToObj was not correctly checked to see if it was
- # all one byte chars, so a unicode string would be added as one
- # byte chars.
+ # Tcl_AppendObjToObj was not correctly checked to see if it was all one
+ # byte chars, so a unicode string would be added as one byte chars.
set x abcdef
set len [string length $x]
- set y aübåcï
+ set y a\u00fcb\u00e5c\u00ef
set len [string length $y]
append x $y
string length $x
@@ -323,29 +326,29 @@ test stringObj-9.11 {TclAppendObjToObj, mixed src & 1-byte dest index check} tes
lappend q [string index $x $i]
}
set q
-} {a b c d e f a ü b å c ï}
+} "a b c d e f a \u00fc b \u00e5 c \u00ef"
test stringObj-10.1 {Tcl_GetRange with all byte-size chars} {testobj testdstring} {
testdstring free
testdstring append abcdef -1
set x [testdstring get]
list [testobj objtype $x] [set y [string range $x 1 end-1]] \
- [testobj objtype $x] [testobj objtype $y]
+ [testobj objtype $x] [testobj objtype $y]
} [list none bcde string string]
test stringObj-10.2 {Tcl_GetRange with some mixed width chars} {testobj testdstring} {
# Because this test does not use \uXXXX notation below instead of
# hardcoding the values, it may fail in multibyte locales. However, we
# need to test that the parser produces untyped objects even when there
- # are high-ASCII characters in the input (like "ï"). I don't know what
+ # are high-ASCII characters in the input (like "ï"). I don't know what
# else to do but inline those characters here.
testdstring free
testdstring append "abc\u00ef\u00efdef" -1
set x [testdstring get]
list [testobj objtype $x] [set y [string range $x 1 end-1]] \
- [testobj objtype $x] [testobj objtype $y]
+ [testobj objtype $x] [testobj objtype $y]
} [list none "bc\u00EF\u00EFde" string string]
test stringObj-10.3 {Tcl_GetRange with some mixed width chars} testobj {
- # set x "abcïïdef"
+ # set x "abcïïdef"
# Use \uXXXX notation below instead of hardcoding the values, otherwise
# the test will fail in multibyte locales.
set x "abc\u00EF\u00EFdef"
@@ -354,7 +357,7 @@ test stringObj-10.3 {Tcl_GetRange with some mixed width chars} testobj {
[testobj objtype $x] [testobj objtype $y]
} [list string "bc\u00EF\u00EFde" string string]
test stringObj-10.4 {Tcl_GetRange with some mixed width chars} testobj {
- # set a "ïa¿b®cï¿d®"
+ # set a "ïa¿b®cï¿d®"
# Use \uXXXX notation below instead of hardcoding the values, otherwise
# the test will fail in multibyte locales.
set a "\u00EFa\u00BFb\u00AEc\u00EF\u00BFd\u00AE"
@@ -389,15 +392,15 @@ test stringObj-12.3 {Tcl_GetUniChar with byte-size chars} testobj {
list [string index $x end] [string index $x end-1]
} {i h}
test stringObj-12.4 {Tcl_GetUniChar with mixed width chars} testobj {
- string index "ïa¿b®c®¿dï" 0
-} "ï"
+ string index "\u00efa\u00bfb\u00aec\u00ae\u00bfd\u00ef" 0
+} "\u00ef"
test stringObj-12.5 {Tcl_GetUniChar} testobj {
- set x "ïa¿b®c®¿dï"
+ set x "\u00efa\u00bfb\u00aec\u00ae\u00bfd\u00ef"
list [string index $x 4] [string index $x 0]
-} {® ï}
+} "\u00ae \u00ef"
test stringObj-12.6 {Tcl_GetUniChar} testobj {
- string index "ïa¿b®cï¿d®" end
-} "®"
+ string index "\u00efa\u00bfb\u00aec\u00ef\u00bfd\u00ae" end
+} "\u00ae"
test stringObj-13.1 {Tcl_GetCharLength with byte-size chars} testobj {
set a ""
@@ -411,27 +414,27 @@ test stringObj-13.3 {Tcl_GetCharLength with byte-size chars} testobj {
list [string length $a] [string length $a]
} {6 6}
test stringObj-13.4 {Tcl_GetCharLength with mixed width chars} testobj {
- string length "®"
+ string length "\u00ae"
} 1
test stringObj-13.5 {Tcl_GetCharLength with mixed width chars} testobj {
- # string length "○○"
+ # string length "○○"
# Use \uXXXX notation below instead of hardcoding the values, otherwise
# the test will fail in multibyte locales.
string length "\u00EF\u00BF\u00AE\u00EF\u00BF\u00AE"
} 6
test stringObj-13.6 {Tcl_GetCharLength with mixed width chars} testobj {
- # set a "ïa¿b®cï¿d®"
+ # set a "ïa¿b®cï¿d®"
# Use \uXXXX notation below instead of hardcoding the values, otherwise
# the test will fail in multibyte locales.
set a "\u00EFa\u00BFb\u00AEc\u00EF\u00BFd\u00AE"
list [string length $a] [string length $a]
} {10 10}
-test stringObj-13.7 {Tcl_GetCharLength with identity nulls} testobj {
+test stringObj-13.7 {Tcl_GetCharLength with identity nulls} {testobj testbytestring} {
# SF bug #684699
- string length [encoding convertfrom identity \x00]
+ string length [testbytestring \x00]
} 1
-test stringObj-13.8 {Tcl_GetCharLength with identity nulls} testobj {
- string length [encoding convertfrom identity \x01\x00\x02]
+test stringObj-13.8 {Tcl_GetCharLength with identity nulls} {testobj testbytestring} {
+ string length [testbytestring \x01\x00\x02]
} 3
test stringObj-14.1 {Tcl_SetObjLength on pure unicode object} testobj {
@@ -478,6 +481,7 @@ test stringObj-15.8 {Tcl_Append*ToObj: self appends} testobj {
teststringobj appendself2 1 3
} foo
+
if {[testConstraint testobj]} {
testobj freeallvars
}