Skip to content
Tcl Source Code Artifact [bc8fa6d7b5]
Login

Artifact [bc8fa6d7b5]

Artifact bc8fa6d7b590777a519910cfe1ff556a5dcb21d473ff79a62775e238e678b24e:


# Tests for tcl::unsupported::icu

if {"::tcltest" ni [namespace children]} {
    package require tcltest
    namespace import -force ::tcltest::*
}

# Force late loading of ICU if present
catch {::tcl::unsupported::icu}
testConstraint icu [llength [info commands ::tcl::unsupported::icu::detect]]

namespace eval icu {
    namespace path {::tcl::unsupported ::tcl::mathop}

    test icu-detect-0 {Return list of ICU encodings} -constraints icu -body {
	set encoders [icu detect]
	list [in UTF-8 $encoders] [in ISO-8859-1 $encoders]
    } -result {1 1}
    test icu-detect-1 {Guess encoding} -constraints icu -body {
	icu detect [readFile [info script]]
    } -result ISO-8859-1
    test icu-detect-2 {Get all possible encodings} -constraints icu -body {
	set encodings [icu detect [readFile [info script]] -all]
	list [in UTF-8 $encodings] [in ISO-8859-1 $encodings]
    } -result {1 1}
    test icu-detect-3 {error case} -constraints icu -returnCodes error -body {
	icu detect gorp gorp gorp
    } -result {wrong # args: should be "icu detect ?bytes ?-all??"}

    test icu-tclToIcu-0 {Map Tcl encoding} -constraints icu -body {
	# tis-620 because it is ambiguous in ICU on some platforms
	# but should return the preferred encoding
	lmap enc {utf-8 tis-620 shiftjis} {
	    icu tclToIcu $enc
	}
    } -result {UTF-8 TIS-620 ibm-943_P15A-2003}
    test icu-tclToIcu-1 {Map Tcl encoding - no map} -constraints icu -body {
	# Should not raise an error
	icu tclToIcu dummy
    } -result {}
    test icu-tclToIcu-2 {error case} -constraints icu -returnCodes error -body {
	icu tclToIcu gorp gorp
    } -result {wrong # args: should be "icu tclToIcu tclName"}

    test icu-icuToTcl-0 {Map ICU encoding} -constraints icu -body {
	lmap enc {UTF-8 TIS-620 ibm-943_P15A-2003} {
	    icu icuToTcl $enc
	}
    } -result {utf-8 tis-620 cp932}
    test icu-icuToTcl-1 {Map ICU encoding - no map} -constraints icu -body {
	# Should not raise an error
	icu icuToTcl dummy
    } -result {}
    test icu-icuToTcl-2 {error case} -constraints icu -returnCodes error -body {
	icu icuToTcl gorp gorp
    } -result {wrong # args: should be "icu icuToTcl icuName"}
}

namespace delete icu
::tcltest::cleanupTests