summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-02-10 20:22:07 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-02-10 20:22:07 (GMT)
commitbab9170bdca67622ada57df9a0e7f55c5ac92b2f (patch)
tree6522890583184c71f8881e7a9374535e74efbb84 /tests
parentde0a637d7c24faa768c266bacda17bf6ac48171d (diff)
downloadtcl-bab9170bdca67622ada57df9a0e7f55c5ac92b2f.zip
tcl-bab9170bdca67622ada57df9a0e7f55c5ac92b2f.tar.gz
tcl-bab9170bdca67622ada57df9a0e7f55c5ac92b2f.tar.bz2
Proposed fix (and testcases) for [4a7397e0b3]: Tcl 9: fcopy with -strictencoding 1 UTF-8 channels
Diffstat (limited to 'tests')
-rw-r--r--tests/io.test97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/io.test b/tests/io.test
index 2708906..7b8182e 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -7609,6 +7609,103 @@ test io-52.19 {coverage of eofChar handling} {
close $out
file size $path(test2)
} 8
+test io-52.20 {TclCopyChannel & encodings} -setup {
+ set out [open $path(utf8-fcopy.txt) w]
+ fconfigure $out -encoding utf-8 -translation lf
+ puts $out "Á"
+ close $out
+} -constraints {fcopy} -body {
+ # binary to encoding => the input has to be
+ # in utf-8 to make sense to the encoder
+
+ set in [open $path(utf8-fcopy.txt) r]
+ set out [open $path(kyrillic.txt) w]
+
+ # Using "-encoding ascii" means reading the "Á" gives an error
+ fconfigure $in -encoding ascii -strictencoding 1
+ fconfigure $out -encoding koi8-r -translation lf
+
+ fcopy $in $out
+} -cleanup {
+ close $in
+ close $out
+} -returnCodes 1 -match glob -result {error reading "file*": illegal byte sequence}
+test io-52.21 {TclCopyChannel & encodings} -setup {
+ set out [open $path(utf8-fcopy.txt) w]
+ fconfigure $out -encoding utf-8 -translation lf
+ puts $out "Á"
+ close $out
+} -constraints {fcopy} -body {
+ # binary to encoding => the input has to be
+ # in utf-8 to make sense to the encoder
+
+ set in [open $path(utf8-fcopy.txt) r]
+ set out [open $path(kyrillic.txt) w]
+
+ # Using "-encoding ascii" means writing the "Á" gives an error
+ fconfigure $in -encoding utf-8
+ fconfigure $out -encoding ascii -translation lf -strictencoding 1
+
+ fcopy $in $out
+} -cleanup {
+ close $in
+ close $out
+} -returnCodes 1 -match glob -result {error writing "file*": illegal byte sequence}
+test io-52.22 {TclCopyChannel & encodings} -setup {
+ set out [open $path(utf8-fcopy.txt) w]
+ fconfigure $out -encoding utf-8 -translation lf
+ puts $out "Á"
+ close $out
+} -constraints {fcopy} -body {
+ # binary to encoding => the input has to be
+ # in utf-8 to make sense to the encoder
+
+ set in [open $path(utf8-fcopy.txt) r]
+ set out [open $path(kyrillic.txt) w]
+
+ # Using "-encoding ascii" means reading the "Á" gives an error
+ fconfigure $in -encoding ascii -strictencoding 1
+ fconfigure $out -encoding koi8-r -translation lf
+ proc ::xxx args {
+ set ::s0 $args
+ }
+
+ fcopy $in $out -command ::xxx
+ vwait ::s0
+ set ::s0
+} -cleanup {
+ close $in
+ close $out
+ unset ::s0
+} -match glob -result {0 {error reading "file*": illegal byte sequence}}
+test io-52.23 {TclCopyChannel & encodings} -setup {
+ set out [open $path(utf8-fcopy.txt) w]
+ fconfigure $out -encoding utf-8 -translation lf
+ puts $out "Á"
+ close $out
+} -constraints {fcopy} -body {
+ # binary to encoding => the input has to be
+ # in utf-8 to make sense to the encoder
+
+ set in [open $path(utf8-fcopy.txt) r]
+ set out [open $path(kyrillic.txt) w]
+
+ # Using "-encoding ascii" means writing the "Á" gives an error
+ fconfigure $in -encoding utf-8
+ fconfigure $out -encoding ascii -translation lf -strictencoding 1
+ proc ::xxx args {
+ set ::s0 $args
+ }
+
+ fcopy $in $out -command ::xxx
+ vwait ::s0
+ set ::s0
+} -cleanup {
+ close $in
+ close $out
+ unset ::s0
+} -match glob -result {0 {error writing "file*": illegal byte sequence}}
+
test io-53.1 {CopyData} {fcopy} {
file delete $path(test1)