diff options
-rw-r--r-- | tests/io.test | 81 |
1 files changed, 65 insertions, 16 deletions
diff --git a/tests/io.test b/tests/io.test index a233f7b..6af536a 100644 --- a/tests/io.test +++ b/tests/io.test @@ -8952,12 +8952,13 @@ 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 tests 75.1 to 75.3 exercise tolerant channel encoding. +# The following tests 75.1 to 75.5 exercise strict or tolerant channel +# encoding. # They are left as a place-holder here. If TIP633 is voted, they will # come back. # Exercise strct channel encoding -test io-75.4 {multibyte encoding error read results in raw bytes} -setup { - set fn [makeFile {} io-75.4] +test io-75.6 {multibyte encoding error read results in raw bytes} -setup { + set fn [makeFile {} io-75.6] set f [open $fn w+] fconfigure $f -encoding binary # In UTF-8, a byte 0xCx starts a multibyte sequence and must be followed @@ -8966,15 +8967,19 @@ test io-75.4 {multibyte encoding error read results in raw bytes} -setup { flush $f seek $f 0 fconfigure $f -encoding utf-8 -buffering none -} -constraints knownBug -body { - read $f +} -body { + set d [read $f] + binary scan $d H* hd + set hd } -cleanup { close $f - removeFile io-75.4 -} -returnCodes error + removeFile io-75.6 +} -result "41" +# The current result cuts at the invalid sequence. IMHO, there should be an +# error thrown or the whole sequence should be returned as byte (compat mode). -test io-75.5 {unrepresentable character write passes and is replaced by ?} -setup { - set fn [makeFile {} io-75.5] +test io-75.7 {unrepresentable character write passes and is replaced by ?} -setup { + set fn [makeFile {} io-75.7] set f [open $fn w+] fconfigure $f -encoding iso8859-1 } -body { @@ -8984,27 +8989,71 @@ test io-75.5 {unrepresentable character write passes and is replaced by ?} -setu list [read $f] $msg } -cleanup { close $f - removeFile io-75.5 + removeFile io-75.7 } -match glob -result [list {A} {error writing "*": illegal byte sequence}] # Incomplete sequence test. # This error may IMHO only be detected with the close. # But the read already returns the incomplete sequence. -test io-75.6 {incomplete multibyte encoding read is ignored} -setup { - set fn [makeFile {} io-75.6] +test io-75.8 {incomplete multibyte encoding read is ignored} -setup { + set fn [makeFile {} io-75.8] set f [open $fn w+] fconfigure $f -encoding binary puts -nonewline $f "A\xC0" flush $f seek $f 0 fconfigure $f -encoding utf-8 -buffering none -} -constraints knownBug -body { +} -body { set d [read $f] close $f - set d + binary scan $d H* hd + set hd } -cleanup { - removeFile io-75.6 -} -returnCodes error + removeFile io-75.8 +} -result "41c0" +# The current result returns the orphan byte as byte. +# This may be expected due to special utf-8 handling. + +# As utf-8 has a special treatment in multi-byte decoding, also test another +# one. +test io-75.9 {shiftjis encoding error read results in raw bytes} -setup { + set fn [makeFile {} io-75.9] + 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.9 +} -result "41" +# The current result cuts at the invalid sequence. IMHO, there should be an +# error thrown or the whole sequence should be returned as byte (compat mode). + +test io-75.10 {incomplete shiftjis encoding read is ignored} -setup { + set fn [makeFile {} io-75.10] + 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.10 +} -result "4181" # ### ### ### ######### ######### ######### |