Skip to content
Tcl Source Code Artifact [d14f26affb]
Login

Artifact [d14f26affb]

Artifact d14f26affb2fc48bfbb1b6222c8632d22ba0f9e92c60300d4ac672259d8b1c53:


# This file contains a collection of tests for tclUtf.c
# Sourcing this file into Tcl runs the tests and generates output for
# errors.  No output means no errors were found.
#
# Copyright (c) 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.

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest 2
    namespace import -force ::tcltest::*
}

testConstraint compat85 [expr {[format %c 0x010000] == "\uFFFD"}]
testConstraint testbytestring [llength [info commands testbytestring]]
testConstraint testfindfirst [llength [info commands testfindfirst]]
testConstraint testfindlast [llength [info commands testfindlast]]
testConstraint testnumutfchars [llength [info commands testnumutfchars]]
testConstraint teststringobj [llength [info commands teststringobj]]
testConstraint testutfnext [llength [info commands testutfnext]]
testConstraint testutfprev [llength [info commands testutfprev]]

catch {unset x}

test utf-1.1 {Tcl_UniCharToUtf: 1 byte sequences} testbytestring {
    expr {"\x01" eq [testbytestring "\x01"]}
} 1
test utf-1.2 {Tcl_UniCharToUtf: 2 byte sequences} testbytestring {
    expr {"\x00" eq [testbytestring "\xC0\x80"]}
} 1
test utf-1.3 {Tcl_UniCharToUtf: 2 byte sequences} testbytestring {
    expr {"\xE0" eq [testbytestring "\xC3\xA0"]}
} 1
test utf-1.4 {Tcl_UniCharToUtf: 3 byte sequences} testbytestring {
    expr {"\u4E4E" eq [testbytestring "\xE4\xB9\x8E"]}
} 1
test utf-1.5 {Tcl_UniCharToUtf: overflowed Tcl_UniChar} testbytestring {
    expr {[format %c 0x110000] eq [testbytestring "\xEF\xBF\xBD"]}
} 1
test utf-1.6 {Tcl_UniCharToUtf: negative Tcl_UniChar} testbytestring {
    expr {[format %c -1] eq [testbytestring "\xEF\xBF\xBD"]}
} 1
test utf-2.1 {Tcl_UtfToUniChar: low ascii} {
    string length "abc"
} {3}
test utf-2.2 {Tcl_UtfToUniChar: naked trail bytes} testbytestring {
    string length [testbytestring "\x82\x83\x84"]
} {3}
test utf-2.3 {Tcl_UtfToUniChar: lead (2-byte) followed by non-trail} testbytestring {
    string length [testbytestring "\xC2"]
} {1}
test utf-2.4 {Tcl_UtfToUniChar: lead (2-byte) followed by trail} testbytestring {
    string length [testbytestring "\xC2\xA2"]
} {1}
test utf-2.5 {Tcl_UtfToUniChar: lead (3-byte) followed by non-trail} testbytestring {
    string length [testbytestring "\xE2"]
} {1}
test utf-2.6 {Tcl_UtfToUniChar: lead (3-byte) followed by 1 trail} testbytestring {
    string length [testbytestring "\xE2\xA2"]
} {2}
test utf-2.7 {Tcl_UtfToUniChar: lead (3-byte) followed by 2 trail} testbytestring {
    string length [testbytestring "\xE4\xB9\x8E"]
} {1}
test utf-2.8 {Tcl_UtfToUniChar: lead (4-byte) followed by 3 trail} -constraints {testbytestring compat85} -body {
    string length [testbytestring "\xF0\x90\x80\x80"]
} -result {4}
test utf-2.9 {Tcl_UtfToUniChar: lead (4-byte) followed by 3 trail} -constraints {testbytestring compat85} -body {
    string length [testbytestring "\xF4\x8F\xBF\xBF"]
} -result {4}
test utf-2.10 {Tcl_UtfToUniChar: lead (4-byte) followed by 3 trail, underflow} testbytestring {
    string length [testbytestring "\xF0\x8F\xBF\xBF"]
} {4}
test utf-2.11 {Tcl_UtfToUniChar: lead (4-byte) followed by 3 trail, overflow} testbytestring {
    # Would decode to U+110000 but that is outside the Unicode range.
    string length [testbytestring "\xF4\x90\x80\x80"]
} {4}
test utf-2.12 {Tcl_UtfToUniChar: longer UTF sequences not supported} testbytestring {
    string length [testbytestring "\xF8\xA2\xA2\xA2\xA2"]
} {5}

test utf-3.1 {Tcl_UtfCharComplete} {
} {}

test utf-4.1 {Tcl_NumUtfChars: zero length} testnumutfchars {
    testnumutfchars ""
} {0}
test utf-4.2 {Tcl_NumUtfChars: length 1} {testnumutfchars testbytestring} {
    testnumutfchars [testbytestring "\xC2\xA2"]
} {1}
test utf-4.3 {Tcl_NumUtfChars: long string} {testnumutfchars testbytestring} {
    testnumutfchars [testbytestring "abc\xC2\xA2\xE4\xB9\x8E\uA2\x4E"]
} {7}
test utf-4.4 {Tcl_NumUtfChars: #u0000} {testnumutfchars testbytestring} {
    testnumutfchars [testbytestring "\xC0\x80"]
} {1}
test utf-4.5 {Tcl_NumUtfChars: zero length, calc len} testnumutfchars {
    testnumutfchars "" 0
} {0}
test utf-4.6 {Tcl_NumUtfChars: length 1, calc len} {testnumutfchars testbytestring} {
    testnumutfchars [testbytestring "\xC2\xA2"] 1
} {1}
test utf-4.7 {Tcl_NumUtfChars: long string, calc len} {testnumutfchars testbytestring} {
    testnumutfchars [testbytestring "abc\xC2\xA2\xE4\xB9\x8E\uA2\x4E"] 10
} {7}
test utf-4.8 {Tcl_NumUtfChars: #u0000, calc len} {testnumutfchars testbytestring} {
    testnumutfchars [testbytestring "\xC0\x80"] 1
} {1}
# Bug [2738427]: Tcl_NumUtfChars(...) no overflow check
test utf-4.9 {Tcl_NumUtfChars: #u20AC, calc len, incomplete} {testnumutfchars testbytestring} {
    testnumutfchars [testbytestring "\xE2\x82\xAC"] 2
} {2}
test utf-4.10 {Tcl_NumUtfChars: #u0000, calc len, overcomplete} {testnumutfchars testbytestring} {
    testnumutfchars [testbytestring "\x00"] 2
} {2}
test utf-4.11 {Tcl_NumUtfChars: 3 bytes of 4-byte UTF-8 characater} {testnumutfchars testbytestring} {
    testnumutfchars [testbytestring \xF0\x9F\x92\xA9] 3
} {3}
test utf-4.12 {Tcl_NumUtfChars: #4-byte UTF-8 character} {testnumutfchars testbytestring compat85} {
    testnumutfchars [testbytestring \xF0\x9F\x92\xA9] 4
} {4}

test utf-5.1 {Tcl_UtfFindFirst} {testfindfirst testbytestring} {
    testfindfirst [testbytestring "abcbc"] 98
} {bcbc}
test utf-5.2 {Tcl_UtfFindLast} {testfindlast testbytestring} {
    testfindlast [testbytestring "abcbc"] 98
} {bc}

test utf-6.1 {Tcl_UtfNext} testutfnext {
    # This takes the pointer one past the terminating NUL.
    # This is really an invalid call.
    testutfnext {}
} 1
test utf-6.2 {Tcl_UtfNext} testutfnext {
    testutfnext A
} 1
test utf-6.3 {Tcl_UtfNext} testutfnext {
    testutfnext AA
} 1
test utf-6.4 {Tcl_UtfNext} testutfnext {
    testutfnext A\xA0
} 1
test utf-6.5 {Tcl_UtfNext} testutfnext {
    testutfnext A\xD0
} 1
test utf-6.6 {Tcl_UtfNext} testutfnext {
    testutfnext A\xE8
} 1
test utf-6.7 {Tcl_UtfNext} testutfnext {
    testutfnext A\xF2
} 1
test utf-6.8 {Tcl_UtfNext} testutfnext {
    testutfnext A\xF8
} 1
test utf-6.9 {Tcl_UtfNext} testutfnext {
    testutfnext \xA0
} 1
test utf-6.10 {Tcl_UtfNext} testutfnext {
    testutfnext \xA0G
} 1
test utf-6.11 {Tcl_UtfNext} testutfnext {
    testutfnext \xA0\xA0
} 1
test utf-6.12 {Tcl_UtfNext} testutfnext {
    testutfnext \xA0\xD0
} 1
test utf-6.13 {Tcl_UtfNext} testutfnext {
    testutfnext \xA0\xE8
} 1
test utf-6.14 {Tcl_UtfNext} testutfnext {
    testutfnext \xA0\xF2
} 1
test utf-6.15 {Tcl_UtfNext} testutfnext {
    testutfnext \xA0\xF8
} 1
test utf-6.16 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0
} 1
test utf-6.17 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0G
} 1
test utf-6.18 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0\xA0
} 2
test utf-6.19 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0\xD0
} 1
test utf-6.20 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0\xE8
} 1
test utf-6.21 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0\xF2
} 1
test utf-6.22 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0\xF8
} 1
test utf-6.23 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8
} 1
test utf-6.24 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8G
} 1
test utf-6.25 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0
} 1
test utf-6.26 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xD0
} 1
test utf-6.27 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xE8
} 1
test utf-6.28 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xF2
} 1
test utf-6.29 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xF8
} 1
test utf-6.30 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2
} 1
test utf-6.31 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2G
} 1
test utf-6.32 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xA0
} 1
test utf-6.33 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xD0
} 1
test utf-6.34 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xE8
} 1
test utf-6.35 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xF2
} 1
test utf-6.36 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xF8
} 1
test utf-6.37 {Tcl_UtfNext} testutfnext {
    testutfnext \xF8
} 1
test utf-6.38 {Tcl_UtfNext} testutfnext {
    testutfnext \xF8G
} 1
test utf-6.39 {Tcl_UtfNext} testutfnext {
    testutfnext \xF8\xA0
} 1
test utf-6.40 {Tcl_UtfNext} testutfnext {
    testutfnext \xF8\xD0
} 1
test utf-6.41 {Tcl_UtfNext} testutfnext {
    testutfnext \xF8\xE8
} 1
test utf-6.42 {Tcl_UtfNext} testutfnext {
    testutfnext \xF8\xF2
} 1
test utf-6.43 {Tcl_UtfNext} testutfnext {
    testutfnext \xF8\xF8
} 1
test utf-6.44 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0\xA0G
} 2
test utf-6.45 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0\xA0\xA0
} 2
test utf-6.46 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0\xA0\xD0
} 2
test utf-6.47 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0\xA0\xE8
} 2
test utf-6.48 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0\xA0\xF2
} 2
test utf-6.49 {Tcl_UtfNext} testutfnext {
    testutfnext \xD0\xA0\xF8
} 2
test utf-6.50 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0G
} 1
test utf-6.51 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0\xA0
} 3
test utf-6.52 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0\xD0
} 1
test utf-6.53 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0\xE8
} 1
test utf-6.54 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0\xF2
} 1
test utf-6.55 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0\xF8
} 1
test utf-6.56 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xA0G
} 1
test utf-6.57 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xA0\xA0
} 1
test utf-6.58 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xA0\xD0
} 1
test utf-6.59 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xA0\xE8
} 1
test utf-6.60 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xA0\xF2
} 1
test utf-6.61 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xA0\xF8
} 1
test utf-6.62 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0\xA0G
} 3
test utf-6.63 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0\xA0\xA0
} 3
test utf-6.64 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0\xA0\xD0
} 3
test utf-6.65 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0\xA0\xE8
} 3
test utf-6.66 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0\xA0\xF2
} 3
test utf-6.67 {Tcl_UtfNext} testutfnext {
    testutfnext \xE8\xA0\xA0\xF8
} 3
test utf-6.68 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xA0\xA0G
} 1
test utf-6.69 {Tcl_UtfNext} {testutfnext compat85} {
    testutfnext \xF2\xA0\xA0\xA0
} 1
test utf-6.70 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xA0\xA0\xD0
} 1
test utf-6.71 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xA0\xA0\xE8
} 1
test utf-6.71 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xA0\xA0\xF2
} 1
test utf-6.73 {Tcl_UtfNext} testutfnext {
    testutfnext \xF2\xA0\xA0\xF8
} 1
test utf-6.74 {Tcl_UtfNext} {testutfnext compat85} {
    testutfnext \xF2\xA0\xA0\xA0G
} 1
test utf-6.75 {Tcl_UtfNext} {testutfnext compat85} {
    testutfnext \xF2\xA0\xA0\xA0\xA0
} 1
test utf-6.76 {Tcl_UtfNext} {testutfnext compat85} {
    testutfnext \xF2\xA0\xA0\xA0\xD0
} 1
test utf-6.77 {Tcl_UtfNext} {testutfnext compat85} {
    testutfnext \xF2\xA0\xA0\xA0\xE8
} 1
test utf-6.78 {Tcl_UtfNext} {testutfnext compat85} {
    testutfnext \xF2\xA0\xA0\xA0\xF2
} 1
test utf-6.79 {Tcl_UtfNext} {testutfnext compat85} {
    testutfnext \xF2\xA0\xA0\xA0G\xF8
} 1
test utf-6.80 {Tcl_UtfNext - overlong sequences} testutfnext {
    testutfnext \xC0\x80
} 2
test utf-6.81 {Tcl_UtfNext - overlong sequences} testutfnext {
    testutfnext \xC0\x81
} 1
test utf-6.82 {Tcl_UtfNext - overlong sequences} testutfnext {
    testutfnext \xC1\x80
} 1
test utf-6.83 {Tcl_UtfNext - overlong sequences} testutfnext {
    testutfnext \xC2\x80
} 2
test utf-6.84 {Tcl_UtfNext - overlong sequences} testutfnext {
    testutfnext \xE0\x80\x80
} 1
test utf-6.85 {Tcl_UtfNext - overlong sequences} testutfnext {
    testutfnext \xE0\xA0\x80
} 3
test utf-6.86 {Tcl_UtfNext - overlong sequences} testutfnext {
    testutfnext \xF0\x80\x80\x80
} 1
test utf-6.87 {Tcl_UtfNext - overlong sequences} {testutfnext compat85} {
    testutfnext \xF0\x90\x80\x80
} 1
test utf-6.88 {Tcl_UtfNext, pointing to 2th byte of 3-byte valid sequence} {testutfnext} {
    testutfnext \xA0\xA0
} 1
test utf-6.88.1 {Tcl_UtfNext, pointing to 2th byte of 3-byte valid sequence} {testutfnext} {
    testutfnext \xE8\xA0\xA0 1
} 2
test utf-6.89 {Tcl_UtfNext, pointing to 2th byte of 3-byte invalid sequence} {testutfnext} {
    testutfnext \x80\x80
} 1
test utf-6.89.1 {Tcl_UtfNext, pointing to 2th byte of 3-byte invalid sequence} {testutfnext} {
    testutfnext \xF0\x80\x80 1
} 2
test utf-6.90 {Tcl_UtfNext, validity check [493dccc2de]} {testutfnext compat85} {
    testutfnext \xF4\x8F\xBF\xBF
} 1
test utf-6.91 {Tcl_UtfNext, validity check [493dccc2de]} testutfnext {
    testutfnext \xF4\x90\x80\x80
} 1

test utf-7.1 {Tcl_UtfPrev} testutfprev {
    testutfprev {}
} 0
test utf-7.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A
} 0
test utf-7.3 {Tcl_UtfPrev} testutfprev {
    testutfprev AA
} 1
test utf-7.4 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF8
} 1
test utf-7.4.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF8\xA0\xA0\xA0 2
} 1
test utf-7.4.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF8\xF8\xA0\xA0 2
} 1
test utf-7.5 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF2
} 1
test utf-7.5.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF2\xA0\xA0\xA0 2
} 1
test utf-7.5.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF2\xF8\xA0\xA0 2
} 1
test utf-7.6 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xE8
} 1
test utf-7.6.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xE8\xA0\xA0\xA0 2
} 1
test utf-7.6.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xE8\xF8\xA0\xA0 2
} 1
test utf-7.7 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xD0
} 1
test utf-7.7.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xD0\xA0\xA0\xA0 2
} 1
test utf-7.7.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xD0\xF8\xA0\xA0 2
} 1
test utf-7.8 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xA0
} 1
test utf-7.8.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xA0\xA0\xA0\xA0 2
} 1
test utf-7.8.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xA0\xF8\xA0\xA0 2
} 1
test utf-7.9 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF8\xA0
} 2
test utf-7.9.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF8\xA0\xA0\xA0 3
} 2
test utf-7.9.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF8\xA0\xF8\xA0 3
} 2
test utf-7.10 {Tcl_UtfPrev} {testutfprev compat85} {
    testutfprev A\xF2\xA0
} 2
test utf-7.10.1 {Tcl_UtfPrev} {testutfprev compat85} {
    testutfprev A\xF2\xA0\xA0\xA0 3
} 2
test utf-7.10.2 {Tcl_UtfPrev} {testutfprev compat85} {
    testutfprev A\xF2\xA0\xF8\xA0 3
} 2
test utf-7.11 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xE8\xA0
} 1
test utf-7.11.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xE8\xA0\xA0\xA0 3
} 1
test utf-7.11.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xE8\xA0\xF8\xA0 3
} 1
test utf-7.11.3 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xE8\xA0\xF8 3
} 1
test utf-7.12 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xD0\xA0
} 1
test utf-7.12.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xD0\xA0\xA0\xA0 3
} 1
test utf-7.12.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xD0\xA0\xF8\xA0 3
} 1
test utf-7.13 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xA0\xA0
} 2
test utf-7.13.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xA0\xA0\xA0\xA0 3
} 2
test utf-7.13.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xA0\xA0\xF8\xA0 3
} 2
test utf-7.14 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF8\xA0\xA0
} 3
test utf-7.14.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF8\xA0\xA0\xA0 4
} 3
test utf-7.14.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF8\xA0\xA0\xF8 4
} 3
test utf-7.15 {Tcl_UtfPrev} {testutfprev compat85} {
    testutfprev A\xF2\xA0\xA0
} 3
test utf-7.15.1 {Tcl_UtfPrev} {testutfprev compat85} {
    testutfprev A\xF2\xA0\xA0\xA0 4
} 3
test utf-7.15.2 {Tcl_UtfPrev} {testutfprev compat85} {
    testutfprev A\xF2\xA0\xA0\xF8 4
} 3
test utf-7.16 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xE8\xA0\xA0
} 1
test utf-7.16.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xE8\xA0\xA0\xA0 4
} 1
test utf-7.16.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xE8\xA0\xA0\xF8 4
} 1
test utf-7.17 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xD0\xA0\xA0
} 3
test utf-7.17.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xD0\xA0\xA0\xA0 4
} 3
test utf-7.17.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xD0\xA0\xA0\xF8 4
} 3
test utf-7.18 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xA0\xA0\xA0
} 3
test utf-7.18.1 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xA0\xA0\xA0\xA0 4
} 3
test utf-7.18.2 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xA0\xA0\xA0\xF8 4
} 3
test utf-7.19 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xF8\xA0\xA0\xA0
} 4
test utf-7.20 {Tcl_UtfPrev} {testutfprev compat85} {
    testutfprev A\xF2\xA0\xA0\xA0
} 4
test utf-7.21 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xE8\xA0\xA0\xA0
} 4
test utf-7.22 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xD0\xA0\xA0\xA0
} 4
test utf-7.23 {Tcl_UtfPrev} testutfprev {
    testutfprev A\xA0\xA0\xA0\xA0
} 4
test utf-7.24 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xC0\x81
} 2
test utf-7.25 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xC0\x81 2
} 1
test utf-7.26 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xE0\x80\x80
} 3
test utf-7.27 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xE0\x80
} 2
test utf-7.27.1 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xE0\x80\x80 3
} 2
test utf-7.28 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xE0
} 1
test utf-7.28.1 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xE0\x80\x80 2
} 1
test utf-7.29 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xF0\x80\x80\x80
} 4
test utf-7.30 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xF0\x80\x80\x80 4
} 3
test utf-7.31 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xF0\x80\x80\x80 3
} 2
test utf-7.32 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xF0\x80\x80\x80 2
} 1
test utf-7.33 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xC0\x80
} 1
test utf-7.34 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xC1\x80
} 2
test utf-7.35 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xC2\x80
} 1
test utf-7.36 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xE0\xA0\x80
} 1
test utf-7.37 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xE0\xA0\x80 3
} 1
test utf-7.38 {Tcl_UtfPrev -- overlong sequence}  {testutfprev compat85} {
    testutfprev A\xE0\xA0\x80 2
} 1
test utf-7.39 {Tcl_UtfPrev -- overlong sequence}  {testutfprev compat85} {
    testutfprev A\xF0\x90\x80\x80
} 4
test utf-7.40 {Tcl_UtfPrev -- overlong sequence}  {testutfprev compat85} {
    testutfprev A\xF0\x90\x80\x80 4
} 3
test utf-7.41 {Tcl_UtfPrev -- overlong sequence}  {testutfprev compat85} {
    testutfprev A\xF0\x90\x80\x80 3
} 2
test utf-7.42 {Tcl_UtfPrev -- overlong sequence}  testutfprev {
    testutfprev A\xF0\x90\x80\x80 2
} 1
test utf-7.43 {Tcl_UtfPrev -- no lead byte at start}  testutfprev {
    testutfprev \xA0
} 0
test utf-7.44 {Tcl_UtfPrev -- no lead byte at start}  testutfprev {
    testutfprev \xA0\xA0
} 1
test utf-7.45 {Tcl_UtfPrev -- no lead byte at start}  testutfprev {
    testutfprev \xA0\xA0\xA0
} 2
test utf-7.46 {Tcl_UtfPrev -- no lead byte at start}  testutfprev {
    testutfprev \xA0\xA0\xA0\xA0
} 3
test utf-7.47 {Tcl_UtfPrev, pointing to 3th byte of 3-byte valid sequence} {testutfprev} {
    testutfprev \xE8\xA0
} 0
test utf-7.47.1 {Tcl_UtfPrev, pointing to 3th byte of 3-byte valid sequence} {testutfprev} {
    testutfprev \xE8\xA0\xA0 2
} 0
test utf-7.47.2 {Tcl_UtfPrev, pointing to 3th byte of 3-byte invalid sequence} {testutfprev} {
    testutfprev \xE8\xA0\x00 2
} 0
test utf-7.48 {Tcl_UtfPrev, validity check [493dccc2de]} {testutfprev compat85} {
    testutfprev A\xF4\x8F\xBF\xBF
} 4
test utf-7.48.1 {Tcl_UtfPrev, validity check [493dccc2de]} {testutfprev compat85} {
    testutfprev A\xF4\x8F\xBF\xBF 4
} 3
test utf-7.48.2 {Tcl_UtfPrev, validity check [493dccc2de]} {testutfprev compat85} {
    testutfprev A\xF4\x8F\xBF\xBF 3
} 2
test utf-7.48.3 {Tcl_UtfPrev, validity check [493dccc2de]} testutfprev {
    testutfprev A\xF4\x8F\xBF\xBF 2
} 1
test utf-7.49 {Tcl_UtfPrev, validity check [493dccc2de]} testutfprev {
    testutfprev A\xF4\x90\x80\x80
} 4
test utf-7.49.1 {Tcl_UtfPrev, validity check [493dccc2de]} testutfprev {
    testutfprev A\xF4\x90\x80\x80 4
} 3
test utf-7.49.2 {Tcl_UtfPrev, validity check [493dccc2de]} testutfprev {
    testutfprev A\xF4\x90\x80\x80 3
} 2
test utf-7.49.3 {Tcl_UtfPrev, validity check [493dccc2de]} testutfprev {
    testutfprev A\xF4\x90\x80\x80 2
} 1

test utf-8.1 {Tcl_UniCharAtIndex: index = 0} {
    string index abcd 0
} {a}
test utf-8.2 {Tcl_UniCharAtIndex: index = 0} {
    string index \u4E4E\u25A 0
} "\u4E4E"
test utf-8.3 {Tcl_UniCharAtIndex: index > 0} {
    string index abcd 2
} {c}
test utf-8.4 {Tcl_UniCharAtIndex: index > 0} {
    string index \u4E4E\u25A\xFF\u543 2
} "\uFF"

test utf-9.1 {Tcl_UtfAtIndex: index = 0} {
    string range abcd 0 2
} {abc}
test utf-9.2 {Tcl_UtfAtIndex: index > 0} {
    string range \u4E4E\u25A\xFF\u543klmnop 1 5
} "\u25A\xFF\u543kl"


test utf-10.1 {Tcl_UtfBackslash: dst == NULL} {
    set x \n
} {
}
test utf-10.2 {Tcl_UtfBackslash: \u subst} testbytestring {
    expr {"\uA2" eq [testbytestring "\xC2\xA2"]}
} 1
test utf-10.3 {Tcl_UtfBackslash: longer \u subst} testbytestring {
    expr {"\u4E21" eq [testbytestring "\xE4\xB8\xA1"]}
} 1
test utf-10.4 {Tcl_UtfBackslash: stops at first non-hex} testbytestring {
    expr {"\u4E2k" eq "[testbytestring \xD3\xA2]k"}
} 1
test utf-10.5 {Tcl_UtfBackslash: stops after 4 hex chars} testbytestring {
    expr {"\u4E216" eq [testbytestring "\xE4\xB8\xA1"]6}
} 1
proc bsCheck {char num} {
    global errNum
    test utf-10.$errNum {backslash substitution} {
	scan $char %c value
	set value
    } $num
    incr errNum
}
set errNum 6
bsCheck \b	8
bsCheck \e	101
bsCheck \f	12
bsCheck \n	10
bsCheck \r	13
bsCheck \t	9
bsCheck \v	11
bsCheck \{	123
bsCheck \}	125
bsCheck \[	91
bsCheck \]	93
bsCheck \$	36
bsCheck \ 	32
bsCheck \;	59
bsCheck \\	92
bsCheck \Ca	67
bsCheck \Ma	77
bsCheck \CMa	67
# 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
bsCheck \x	120
bsCheck \xa	10
bsCheck \xA	10
bsCheck \x41	65
bsCheck \x541	65
bsCheck \u	117
bsCheck \uk	117
bsCheck \u41	65
bsCheck \ua	10
bsCheck \uA	10
bsCheck \340	224
bsCheck \ua1	161
bsCheck \u4e21	20001

test utf-11.1 {Tcl_UtfToUpper} {
    string toupper {}
} {}
test utf-11.2 {Tcl_UtfToUpper} {
    string toupper abc
} ABC
test utf-11.3 {Tcl_UtfToUpper} {
    string toupper \xE3gh
} \xC3GH
test utf-11.4 {Tcl_UtfToUpper} {
    string toupper \u01E3ab
} \u01E2AB

test utf-12.1 {Tcl_UtfToLower} {
    string tolower {}
} {}
test utf-12.2 {Tcl_UtfToLower} {
    string tolower ABC
} abc
test utf-12.3 {Tcl_UtfToLower} {
    string tolower \xC3GH
} \xE3gh
test utf-12.4 {Tcl_UtfToLower} {
    string tolower \u01E2AB
} \u01E3ab

test utf-13.1 {Tcl_UtfToTitle} {
    string totitle {}
} {}
test utf-13.2 {Tcl_UtfToTitle} {
    string totitle abc
} Abc
test utf-13.3 {Tcl_UtfToTitle} {
    string totitle \xE3GH
} \xC3gh
test utf-13.4 {Tcl_UtfToTitle} {
    string totitle \u01F3AB
} \u01F2ab

test utf-14.1 {Tcl_UtfNcasecmp} {
    string compare -nocase a b
} -1
test utf-14.2 {Tcl_UtfNcasecmp} {
    string compare -nocase b a
} 1
test utf-14.3 {Tcl_UtfNcasecmp} {
    string compare -nocase B a
} 1
test utf-14.4 {Tcl_UtfNcasecmp} {
    string compare -nocase aBcB abca
} 1

test utf-15.1 {Tcl_UniCharToUpper, negative delta} {
    string toupper aA
} AA
test utf-15.2 {Tcl_UniCharToUpper, positive delta} {
    string toupper \u0178\xFF
} \u0178\u0178
test utf-15.3 {Tcl_UniCharToUpper, no delta} {
    string toupper !
} !

test utf-16.1 {Tcl_UniCharToLower, negative delta} {
    string tolower aA
} aa
test utf-16.2 {Tcl_UniCharToLower, positive delta} {
    string tolower \u0178\xFF\uA78D\u01C5
} \xFF\xFF\u0265\u01C6

test utf-17.1 {Tcl_UniCharToLower, no delta} {
    string tolower !
} !

test utf-18.1 {Tcl_UniCharToTitle, add one for title} {
    string totitle \u01C4
} \u01C5
test utf-18.2 {Tcl_UniCharToTitle, subtract one for title} {
    string totitle \u01C6
} \u01C5
test utf-18.3 {Tcl_UniCharToTitle, subtract delta for title (positive)} {
    string totitle \u017F
} \x53
test utf-18.4 {Tcl_UniCharToTitle, subtract delta for title (negative)} {
    string totitle \xFF
} \u0178
test utf-18.5 {Tcl_UniCharToTitle, no delta} {
    string totitle !
} !

test utf-19.1 {TclUniCharLen} {
    list [regexp \\d abc456def foo] $foo
} {1 4}

test utf-20.1 {TclUniCharNcmp} {
} {}

test utf-21.1 {TclUniCharIsAlnum} {
    # this returns 1 with Unicode 7 compliance
    string is alnum \u1040\u021F\u0220
} {1}
test utf-21.2 {unicode alnum char in regc_locale.c} {
    # this returns 1 with Unicode 7 compliance
    list [regexp {^[[:alnum:]]+$} \u1040\u021F\u0220] [regexp {^\w+$} \u1040\u021F\u0220_\u203F\u2040\u2054\uFE33\uFE34\uFE4D\uFE4E\uFE4F\uFF3F]
} {1 1}
test utf-21.3 {unicode print char in regc_locale.c} {
    # this returns 1 with Unicode 7 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 \xA0
} {0}
test utf-21.7 {unicode graph char in regc_locale.c} {
    # [Bug 3464428]
    regexp {[[:graph:]]} \x20\xA0\u2028\u2029
} {0}
test utf-21.8 {TclUniCharIsPrint} {
    # [Bug 3464428]
    string is print \x09
} {0}
test utf-21.9 {unicode print char in regc_locale.c} {
    # [Bug 3464428]
    regexp {[[:print:]]} \x09
} {0}
test utf-21.10 {unicode print char in regc_locale.c} {
    # [Bug 3464428]
    regexp {[[:print:]]} \x09
} {0}
test utf-21.11 {TclUniCharIsControl} {
    # [Bug 3464428]
    string is control \x00\x1F\xAD\u0605\u061C\u180E\u2066\uFEFF
} {1}
test utf-21.12 {unicode control char in regc_locale.c} {
    # [Bug 3464428], [Bug a876646efe]
    regexp {^[[:cntrl:]]*$} \x00\x1F\xAD\u0605\u061C\u180E\u2066\uFEFF
} {1}

test utf-22.1 {TclUniCharIsWordChar} {
    string wordend "xyz123_bar fg" 0
} 10
test utf-22.2 {TclUniCharIsWordChar} {
    string wordend "x\u5080z123_bar\u203C fg" 0
} 10

test utf-23.1 {TclUniCharIsAlpha} {
    # this returns 1 with Unicode 7 compliance
    string is alpha \u021F\u0220\u037F\u052F
} {1}
test utf-23.2 {unicode alpha char in regc_locale.c} {
    # this returns 1 with Unicode 7 compliance
    regexp {^[[:alpha:]]+$} \u021F\u0220\u037F\u052F
} {1}

test utf-24.1 {TclUniCharIsDigit} {
    # this returns 1 with Unicode 7 compliance
    string is digit \u1040\uABF0
} {1}
test utf-24.2 {unicode digit char in regc_locale.c} {
    # this returns 1 with Unicode 7 compliance
    list [regexp {^[[:digit:]]+$} \u1040\uABF0] [regexp {^\d+$} \u1040\uABF0]
} {1 1}

test utf-24.3 {TclUniCharIsSpace} {
    # this returns 1 with Unicode 7 compliance
    string is space \u1680\u180E\u202F
} {1}
test utf-24.4 {unicode space char in regc_locale.c} {
    # this returns 1 with Unicode 7 compliance
    list [regexp {^[[:space:]]+$} \u1680\u180E\u202F] [regexp {^\s+$} \u1680\u180E\u202F]
} {1 1}

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: