diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/io.test | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/tests/io.test b/tests/io.test index 4b7a61e..edadfed 100644 --- a/tests/io.test +++ b/tests/io.test @@ -8820,7 +8820,7 @@ test io-74.1 {[104f2885bb] improper cache validity check} -setup { removeFile io-74.1 } -returnCodes error -match glob -result {can not find channel named "*"} -# The following tests 75.1 to 75.3 exercice strict or tolerant channel +# The following tests 75.1 to 75.5 exercise strict or tolerant channel # encoding. # TCL 8.6 only offers tolerant channel encoding, what is tested here. test io-75.1 {multibyte encoding error read results in raw bytes} -setup { @@ -8834,12 +8834,13 @@ test io-75.1 {multibyte encoding error read results in raw bytes} -setup { seek $f 0 fconfigure $f -encoding utf-8 -buffering none } -body { - read $f + set d [read $f] + binary scan $d H* hd + set hd } -cleanup { close $f removeFile io-75.1 -} -result "A\xC0\x40" -# for TCL 9.0, the result is error +} -result "41c040" test io-75.2 {unrepresentable character write passes and is replaced by ?} -setup { set fn [makeFile {} io-75.2] @@ -8869,10 +8870,51 @@ test io-75.3 {incomplete multibyte encoding read is ignored} -setup { } -body { set d [read $f] close $f - set d + binary scan $d H* hd + set hd } -cleanup { removeFile io-75.3 -} -result "A\xC0" +} -result "41c0" + +# As utf-8 has a special treatment in multi-byte decoding, also test another +# one. +test io-75.4 {shiftjis encoding error read results in raw bytes} -setup { + set fn [makeFile {} io-75.4] + set f [open $fn w+] + fconfigure $f -encoding binary + # In shiftjis, \x81 starts a two-byte sequence. + # But 2nd byte \xFF is not allowed + puts -nonewline $f "A\x81\xFFA" + flush $f + seek $f 0 + fconfigure $f -encoding shiftjis -buffering none -eofchar "" -translation lf +} -body { + set d [read $f] + binary scan $d H* hd + set hd +} -cleanup { + close $f + removeFile io-75.4 +} -result "4181ff41" + +test io-75.5 {incomplete shiftjis encoding read is ignored} -setup { + set fn [makeFile {} io-75.5] + set f [open $fn w+] + fconfigure $f -encoding binary + # \x81 announces a two byte sequence. + puts -nonewline $f "A\x81" + flush $f + seek $f 0 + fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf +} -body { + set d [read $f] + close $f + binary scan $d H* hd + set hd +} -cleanup { + removeFile io-75.5 +} -result "4181" + # ### ### ### ######### ######### ######### |