summaryrefslogtreecommitdiffstats
path: root/tests/utf.test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utf.test')
-rw-r--r--tests/utf.test223
1 files changed, 190 insertions, 33 deletions
diff --git a/tests/utf.test b/tests/utf.test
index 3250097..ebab967 100644
--- a/tests/utf.test
+++ b/tests/utf.test
@@ -7,14 +7,15 @@
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
-#
-# RCS: @(#) $Id: utf.test,v 1.5 1999/06/26 20:55:17 rjohnson Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
- package require tcltest
- namespace import ::tcltest::*
+ package require tcltest 2
+ namespace import -force ::tcltest::*
}
+::tcltest::loadTestedCommands
+catch [list package require -exact Tcltest [info patchlevel]]
+
catch {unset x}
test utf-1.1 {Tcl_UniCharToUtf: 1 byte sequences} {
@@ -29,6 +30,12 @@ test utf-1.3 {Tcl_UniCharToUtf: 2 byte sequences} {
test utf-1.4 {Tcl_UniCharToUtf: 3 byte sequences} {
set x "\u4e4e"
} [bytestring "\xe4\xb9\x8e"]
+test utf-1.5 {Tcl_UniCharToUtf: overflowed Tcl_UniChar} {
+ format %c 0x110000
+} [bytestring "\xef\xbf\xbd"]
+test utf-1.6 {Tcl_UniCharToUtf: negative Tcl_UniChar} {
+ format %c -1
+} [bytestring "\xef\xbf\xbd"]
test utf-2.1 {Tcl_UtfToUniChar: low ascii} {
string length "abc"
@@ -58,15 +65,31 @@ test utf-2.8 {Tcl_UtfToUniChar: longer UTF sequences not supported} {
test utf-3.1 {Tcl_UtfCharComplete} {
} {}
-test utf-4.1 {Tcl_NumUtfChars: zero length} {
- string length ""
+testConstraint testnumutfchars [llength [info commands testnumutfchars]]
+test utf-4.1 {Tcl_NumUtfChars: zero length} testnumutfchars {
+ testnumutfchars ""
+} {0}
+test utf-4.2 {Tcl_NumUtfChars: length 1} testnumutfchars {
+ testnumutfchars [bytestring "\xC2\xA2"]
+} {1}
+test utf-4.3 {Tcl_NumUtfChars: long string} testnumutfchars {
+ testnumutfchars [bytestring "abc\xC2\xA2\xe4\xb9\x8e\uA2\u4e4e"]
+} {7}
+test utf-4.4 {Tcl_NumUtfChars: #u0000} testnumutfchars {
+ testnumutfchars [bytestring "\xC0\x80"]
+} {1}
+test utf-4.5 {Tcl_NumUtfChars: zero length, calc len} testnumutfchars {
+ testnumutfchars "" 1
} {0}
-test utf-4.2 {Tcl_NumUtfChars: length 1} {
- string length [bytestring "\xC2\xA2"]
+test utf-4.6 {Tcl_NumUtfChars: length 1, calc len} testnumutfchars {
+ testnumutfchars [bytestring "\xC2\xA2"] 1
} {1}
-test utf-4.3 {Tcl_NumUtfChars: long string} {
- string length [bytestring "abc\xC2\xA2\xe4\xb9\x8e\uA2\u4e4e"]
+test utf-4.7 {Tcl_NumUtfChars: long string, calc len} testnumutfchars {
+ testnumutfchars [bytestring "abc\xC2\xA2\xe4\xb9\x8e\uA2\u4e4e"] 1
} {7}
+test utf-4.8 {Tcl_NumUtfChars: #u0000, calc len} testnumutfchars {
+ testnumutfchars [bytestring "\xC0\x80"] 1
+} {1}
test utf-5.1 {Tcl_UtfFindFirsts} {
} {}
@@ -141,7 +164,9 @@ bsCheck \\ 92
bsCheck \Ca 67
bsCheck \Ma 77
bsCheck \CMa 67
-bsCheck \8a 8
+# prior to 8.3, this returned 8, as \8 as accepted as an
+# octal value - but it isn't! [Bug: 3975]
+bsCheck \8a 56
bsCheck \14 12
bsCheck \141 97
bsCheck b\0 98
@@ -149,7 +174,7 @@ bsCheck \x 120
bsCheck \xa 10
bsCheck \xA 10
bsCheck \x41 65
-bsCheck \x541 65
+bsCheck \x541 84
bsCheck \u 117
bsCheck \uk 117
bsCheck \u41 65
@@ -158,6 +183,18 @@ bsCheck \uA 10
bsCheck \340 224
bsCheck \ua1 161
bsCheck \u4e21 20001
+bsCheck \741 60
+bsCheck \U 85
+bsCheck \Uk 85
+bsCheck \U41 65
+bsCheck \Ua 10
+bsCheck \UA 10
+bsCheck \Ua1 161
+bsCheck \U4e21 20001
+bsCheck \U004e21 20001
+bsCheck \U00004e21 20001
+bsCheck \U00110000 65533
+bsCheck \Uffffffff 65533
test utf-11.1 {Tcl_UtfToUpper} {
string toupper {}
@@ -225,8 +262,9 @@ test utf-16.1 {Tcl_UniCharToLower, negative delta} {
string tolower aA
} aa
test utf-16.2 {Tcl_UniCharToLower, positive delta} {
- string tolower \u0178\u00ff
-} \u00ff\u00ff
+ string tolower \u0178\u00ff\uA78D\u01c5
+} \u00ff\u00ff\u0265\u01c6
+
test utf-17.1 {Tcl_UniCharToLower, no delta} {
string tolower !
} !
@@ -255,7 +293,53 @@ test utf-20.1 {TclUniCharNcmp} {
} {}
test utf-21.1 {TclUniCharIsAlnum} {
-} {}
+ # this returns 1 with Unicode 6 compliance
+ string is alnum \u1040\u021f\u0220
+} {1}
+test utf-21.2 {unicode alnum char in regc_locale.c} {
+ # this returns 1 with Unicode 6 compliance
+ list [regexp {^[[:alnum:]]+$} \u1040\u021f\u0220] [regexp {^\w+$} \u1040\u021f\u0220]
+} {1 1}
+test utf-21.3 {unicode print char in regc_locale.c} {
+ # this returns 1 with Unicode 6 compliance
+ regexp {^[[:print:]]+$} \ufbc1
+} 1
+test utf-21.4 {TclUniCharIsGraph} {
+ # [Bug 3464428]
+ string is graph \u0120
+} {1}
+test utf-21.5 {unicode graph char in regc_locale.c} {
+ # [Bug 3464428]
+ regexp {^[[:graph:]]+$} \u0120
+} {1}
+test utf-21.6 {TclUniCharIsGraph} {
+ # [Bug 3464428]
+ string is graph \u00a0
+} {0}
+test utf-21.7 {unicode graph char in regc_locale.c} {
+ # [Bug 3464428]
+ regexp {[[:graph:]]} \u0020\u00a0\u2028\u2029
+} {0}
+test utf-21.8 {TclUniCharIsPrint} {
+ # [Bug 3464428]
+ string is print \u0009
+} {0}
+test utf-21.9 {unicode print char in regc_locale.c} {
+ # [Bug 3464428]
+ regexp {[[:print:]]} \u0009
+} {0}
+test utf-21.10 {unicode print char in regc_locale.c} {
+ # [Bug 3464428]
+ regexp {[[:print:]]} \u0009
+} {0}
+test utf-21.11 {TclUniCharIsControl} {
+ # [Bug 3464428]
+ string is control \u00ad
+} {1}
+test utf-21.12 {unicode control char in regc_locale.c} {
+ # [Bug 3464428], [Bug a876646efe]
+ regexp {^[[:cntrl:]]*$} \u0000\u001f\u00ad
+} {1}
test utf-22.1 {TclUniCharIsWordChar} {
string wordend "xyz123_bar fg" 0
@@ -263,29 +347,102 @@ test utf-22.1 {TclUniCharIsWordChar} {
test utf-22.2 {TclUniCharIsWordChar} {
string wordend "x\u5080z123_bar\u203c fg" 0
} 10
-
+
test utf-23.1 {TclUniCharIsAlpha} {
-} {}
+ # this returns 1 with Unicode 6 compliance
+ string is alpha \u021f\u0220
+} {1}
+test utf-23.2 {unicode alpha char in regc_locale.c} {
+ # this returns 1 with Unicode 6 compliance
+ regexp {^[[:alpha:]]+$} \u021f\u0220
+} {1}
test utf-24.1 {TclUniCharIsDigit} {
-} {}
-
-test utf-24.2 {TclUniCharIsSpace} {
-} {}
+ # this returns 1 with Unicode 6 compliance
+ string is digit \u1040\uabf0
+} {1}
+test utf-24.2 {unicode digit char in regc_locale.c} {
+ # this returns 1 with Unicode 6 compliance
+ list [regexp {^[[:digit:]]+$} \u1040\uabf0] [regexp {^\d+$} \u1040\uabf0]
+} {1 1}
+
+test utf-24.3 {TclUniCharIsSpace} {
+ # this returns 1 with Unicode 6 compliance
+ string is space \u1680\u180e
+} {1}
+test utf-24.4 {unicode space char in regc_locale.c} {
+ # this returns 1 with Unicode 6 compliance
+ list [regexp {^[[:space:]]+$} \u1680\u180e] [regexp {^\s+$} \u1680\u180e]
+} {1 1}
+
+testConstraint teststringobj [llength [info commands teststringobj]]
+
+test utf-25.1 {Tcl_UniCharNcasecmp} -constraints teststringobj \
+ -setup {
+ testobj freeallvars
+ } \
+ -body {
+ teststringobj set 1 a
+ teststringobj set 2 b
+ teststringobj getunicode 1
+ teststringobj getunicode 2
+ string compare -nocase [teststringobj get 1] [teststringobj get 2]
+ } \
+ -cleanup {
+ testobj freeallvars
+ } \
+ -result -1
+test utf-25.2 {Tcl_UniCharNcasecmp} -constraints teststringobj \
+ -setup {
+ testobj freeallvars
+ } \
+ -body {
+ teststringobj set 1 b
+ teststringobj set 2 a
+ teststringobj getunicode 1
+ teststringobj getunicode 2
+ string compare -nocase [teststringobj get 1] [teststringobj get 2]
+ } \
+ -cleanup {
+ testobj freeallvars
+ } \
+ -result 1
+test utf-25.3 {Tcl_UniCharNcasecmp} -constraints teststringobj \
+ -setup {
+ testobj freeallvars
+ } \
+ -body {
+ teststringobj set 1 B
+ teststringobj set 2 a
+ teststringobj getunicode 1
+ teststringobj getunicode 2
+ string compare -nocase [teststringobj get 1] [teststringobj get 2]
+ } \
+ -cleanup {
+ testobj freeallvars
+ } \
+ -result 1
+
+test utf-25.4 {Tcl_UniCharNcasecmp} -constraints teststringobj \
+ -setup {
+ testobj freeallvars
+ } \
+ -body {
+ teststringobj set 1 aBcB
+ teststringobj set 2 abca
+ teststringobj getunicode 1
+ teststringobj getunicode 2
+ string compare -nocase [teststringobj get 1] [teststringobj get 2]
+ } \
+ -cleanup {
+ testobj freeallvars
+ } \
+ -result 1
# cleanup
::tcltest::cleanupTests
return
-
-
-
-
-
-
-
-
-
-
-
-
+# Local Variables:
+# mode: tcl
+# End: