Skip to content

Commit

Permalink
Add missing constraint to icu tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apnadkarni committed Oct 23, 2024
1 parent 4d839dc commit ec8931e
Showing 1 changed file with 47 additions and 46 deletions.
93 changes: 47 additions & 46 deletions tests/icu.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace eval icu {
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
Expand Down Expand Up @@ -61,185 +62,185 @@ namespace eval icu {
# icu convertfrom syntax and arg checks
# These tests are NOT for testing encodings, that's elsewhere.

test icu-convertfrom-error-0 {no args} -body {
test icu-convertfrom-error-0 {no args} -constraints icu -body {
icu convertfrom
} -result {wrong # args: should be "icu convertfrom ?-profile PROFILE? ICUENCNAME STRING"} -returnCodes error

test icu-convertfrom-error-1 {one arg} -body {
test icu-convertfrom-error-1 {one arg} -constraints icu -body {
icu convertfrom ASCII
} -result {wrong # args: should be "icu convertfrom ?-profile PROFILE? ICUENCNAME STRING"} -returnCodes error

test icu-convertfrom-error-2 {missing option value} -body {
test icu-convertfrom-error-2 {missing option value} -constraints icu -body {
icu convertfrom -profile strict ASCII
} -result {Missing value for option -profile.} -returnCodes error

test icu-convertfrom-error-3 {-failindex} -body {
test icu-convertfrom-error-3 {-failindex} -constraints icu -body {
icu convertfrom -failindex failindex ASCII abc
} -result {Option -failindex not implemented.} -returnCodes error

test icu-convertfrom-error-4 {extra arg} -body {
test icu-convertfrom-error-4 {extra arg} -constraints icu -body {
icu convertfrom -profile strict extra ASCII abc
} -result {bad option "extra": must be -profile or -failindex} -returnCodes error

test icu-convertfrom-error-5 {invalid profile} -body {
test icu-convertfrom-error-5 {invalid profile} -constraints icu -body {
icu convertfrom -profile tcl8 ASCII abc
} -result {Invalid value "tcl8" supplied for option "-profile". Must be "strict" or "replace".} -returnCodes error

test icu-convertfrom-error-6 {invalid encoding} -body {
test icu-convertfrom-error-6 {invalid encoding} -constraints icu -body {
icu convertfrom nosuchencoding abc
} -result {Could not get encoding converter.*} -match glob -returnCodes error

test icu-convertfrom-0 {default success} -body {
test icu-convertfrom-0 {default success} -constraints icu -body {
icu convertfrom UTF-8 \xf0\x9f\x98\x80
} -result \U1F600

test icu-convertfrom-1 {-profile strict success} -body {
test icu-convertfrom-1 {-profile strict success} -constraints icu -body {
icu convertfrom -profile strict UTF-8 \xf0\x9f\x98\x80
} -result \U1F600

test icu-convertfrom-2 {-profile replace success} -body {
test icu-convertfrom-2 {-profile replace success} -constraints icu -body {
icu convertfrom -profile replace UTF-8 \xf0\x9f\x98\x80
} -result \U1F600

test icu-convertfrom-3 {default invalid encoding} -body {
test icu-convertfrom-3 {default invalid encoding} -constraints icu -body {
icu convertfrom UTF-8 \xC0\x80
} -result {ICU error while decoding. ICU error (12): U_ILLEGAL_CHAR_FOUND} -returnCodes error

test icu-convertfrom-4 {-profile strict invalid encoding} -body {
test icu-convertfrom-4 {-profile strict invalid encoding} -constraints icu -body {
icu convertfrom -profile strict UTF-8 \xC0\x80
} -result {ICU error while decoding. ICU error (12): U_ILLEGAL_CHAR_FOUND} -returnCodes error

test icu-convertfrom-5 {-profile replace invalid encoding} -body {
test icu-convertfrom-5 {-profile replace invalid encoding} -constraints icu -body {
icu convertfrom -profile replace UTF-8 \xC0\x80
} -result \UFFFD\uFFFD

###
# icu convertto syntax and arg checks
# These tests are NOT for testing encodings, that's elsewhere.

test icu-convertto-error-0 {no args} -body {
test icu-convertto-error-0 {no args} -constraints icu -body {
icu convertto
} -result {wrong # args: should be "icu convertto ?-profile PROFILE? ICUENCNAME STRING"} -returnCodes error

test icu-convertto-error-1 {one arg} -body {
test icu-convertto-error-1 {one arg} -constraints icu -body {
icu convertto ASCII
} -result {wrong # args: should be "icu convertto ?-profile PROFILE? ICUENCNAME STRING"} -returnCodes error

test icu-convertto-error-2 {missing option value} -body {
test icu-convertto-error-2 {missing option value} -constraints icu -body {
icu convertto -profile strict ASCII
} -result {Missing value for option -profile.} -returnCodes error

test icu-convertto-error-3 {-failindex} -body {
test icu-convertto-error-3 {-failindex} -constraints icu -body {
icu convertto -failindex failindex ASCII abc
} -result {Option -failindex not implemented.} -returnCodes error

test icu-convertto-error-4 {extra arg} -body {
test icu-convertto-error-4 {extra arg} -constraints icu -body {
icu convertto -profile strict extra ASCII abc
} -result {bad option "extra": must be -profile or -failindex} -returnCodes error

test icu-convertto-error-5 {invalid profile} -body {
test icu-convertto-error-5 {invalid profile} -constraints icu -body {
icu convertto -profile tcl8 ASCII abc
} -result {Invalid value "tcl8" supplied for option "-profile". Must be "strict" or "replace".} -returnCodes error

test icu-convertto-error-6 {invalid encoding} -body {
test icu-convertto-error-6 {invalid encoding} -constraints icu -body {
icu convertto nosuchencoding abc
} -result {Could not get encoding converter.*} -match glob -returnCodes error

test icu-convertto-0 {default success} -body {
test icu-convertto-0 {default success} -constraints icu -body {
icu convertto UTF-8 \U1F600
} -result \xf0\x9f\x98\x80

test icu-convertto-1 {-profile strict success} -body {
test icu-convertto-1 {-profile strict success} -constraints icu -body {
icu convertto -profile strict UTF-8 \U1F600
} -result \xf0\x9f\x98\x80

test icu-convertto-2 {-profile replace success} -body {
test icu-convertto-2 {-profile replace success} -constraints icu -body {
icu convertto -profile replace UTF-8 \U1F600
} -result \xf0\x9f\x98\x80

test icu-convertto-3 {default unencodable character} -body {
test icu-convertto-3 {default unencodable character} -constraints icu -body {
icu convertto ISO-8859-2 \U1F600
} -result {ICU error while encoding. ICU error (10): U_INVALID_CHAR_FOUND} -returnCodes error

test icu-convertto-4 {-profile strict unencodable character} -body {
test icu-convertto-4 {-profile strict unencodable character} -constraints icu -body {
icu convertto -profile strict ISO-8859-2 \U1F600
} -result {ICU error while encoding. ICU error (10): U_INVALID_CHAR_FOUND} -returnCodes error

test icu-convertto-5 {-profile replace unencodable character} -body {
test icu-convertto-5 {-profile replace unencodable character} -constraints icu -body {
icu convertto -profile replace ISO-8859-2 \U1F600
} -result \x1A

###
# Basic tests for normalization

test icu-normalize-error-0 {no args} -body {
test icu-normalize-error-0 {no args} -constraints icu -body {
icu normalize
} -result {wrong # args: should be "icu normalize ?-profile PROFILE? ?-mode MODE? STRING"} -returnCodes error

test icu-normalize-error-1 {missing -profile arg} -body {
test icu-normalize-error-1 {missing -profile arg} -constraints icu -body {
icu normalize -profile STRING
} -result {Missing value for option -profile.} -returnCodes error

test icu-normalize-error-2 {missing -mode arg} -body {
test icu-normalize-error-2 {missing -mode arg} -constraints icu -body {
icu normalize -mode STRING
} -result {Missing value for option -mode.} -returnCodes error

test icu-normalize-error-3 {extra arg} -body {
test icu-normalize-error-3 {extra arg} -constraints icu -body {
icu normalize -profile strict STRING arg
} -result {bad option "STRING": must be -profile or -mode} -returnCodes error

test icu-normalize-error-4 {invalid profile} -body {
test icu-normalize-error-4 {invalid profile} -constraints icu -body {
icu normalize -profile tcl8 ASCII abc
} -result {Invalid value "tcl8" supplied for option "-profile". Must be "strict" or "replace".} -returnCodes error

test icu-normalize-error-6 {invalid mode} -body {
test icu-normalize-error-6 {invalid mode} -constraints icu -body {
icu normalize -mode xxx ASCII abc
} -result {bad normalization mode "xxx": must be nfc, nfd, nfkc, or nfkd} -returnCodes error

# Source is composed
set s \uFB01anc\u00e9
test icu-normalize-0 {Default normalization} -body {
test icu-normalize-0 {Default normalization} -constraints icu -body {
icu normalize $s
} -result \uFB01anc\u00e9
test icu-normalize-nfc-0 {NFC normalization} -body {
test icu-normalize-nfc-0 {NFC normalization} -constraints icu -body {
icu normalize -mode nfc $s
} -result \uFB01anc\u00e9
test icu-normalize-nfd-0 {NFD normalization} -body {
test icu-normalize-nfd-0 {NFD normalization} -constraints icu -body {
icu normalize -mode nfd $s
} -result \uFB01ance\u0301
test icu-normalize-nfkc-0 {NFKC normalization} -body {
test icu-normalize-nfkc-0 {NFKC normalization} -constraints icu -body {
icu normalize -mode nfkc $s
} -result fianc\u00e9
test icu-normalize-nfkd-0 {NFKD normalization} -body {
test icu-normalize-nfkd-0 {NFKD normalization} -constraints icu -body {
icu normalize -mode nfkd $s
} -result fiance\u0301

# Source is decomposed
set s \uFB01ance\u0301
test icu-normalize-1 {Default normalization} -body {
test icu-normalize-1 {Default normalization} -constraints icu -body {
icu normalize $s
} -result \uFB01anc\u00e9
test icu-normalize-nfc-0 {NFC normalization} -body {
test icu-normalize-nfc-0 {NFC normalization} -constraints icu -body {
icu normalize -mode nfc $s
} -result \uFB01anc\u00e9
test icu-normalize-nfd-1 {NFD normalization} -body {
test icu-normalize-nfd-1 {NFD normalization} -constraints icu -body {
icu normalize -mode nfd $s
} -result \uFB01ance\u0301
test icu-normalize-nfkc-1 {NFKC normalization} -body {
test icu-normalize-nfkc-1 {NFKC normalization} -constraints icu -body {
icu normalize -mode nfkc $s
} -result fianc\u00e9
test icu-normalize-nfkd-1 {NFKD normalization} -body {
test icu-normalize-nfkd-1 {NFKD normalization} -constraints icu -body {
icu normalize -mode nfkd $s
} -result fiance\u0301

# Source has multiple diacritics with different canonical ordering
foreach s [list \u1EC7 e\u0302\u0323 e\u0323\u0302] {
test icu-normalize-nfc-2 {fully composed} {
test icu-normalize-nfc-2 {fully composed} -constraints icu -body {
icu normalize -mode nfc $s
} \u1EC7
test icu-normalize-nfc-2 {fully decomposed} {
} -result \u1EC7
test icu-normalize-nfc-2 {fully decomposed} -constraints icu -body {
icu normalize -mode nfd $s
} e\u0323\u0302
} -result e\u0323\u0302
}
}

Expand Down

0 comments on commit ec8931e

Please sign in to comment.