📄 io.test
字号:
lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] close $f set l} {abc def 0 {} 1}test io-8.21 {Tcl_Write, no newline ^Z in middle, Tcl_Gets auto, eofChar} { removeFile test1 set f [open test1 w] fconfigure $f -translation lf set s [format "abc\ndef\n%cqrs\ntuv" 26] puts $f $s close $f set f [open test1 r] fconfigure $f -eofchar \x1a -translation auto set l "" lappend l [gets $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] close $f set l} {abc def 0 {} 1}test io-8.22 {Tcl_Write, ^Z in middle ignored, Tcl_Gets lf} { removeFile test1 set f [open test1 w] fconfigure $f -translation lf -eofchar {} set s [format "abc\ndef\n%cqrs\ntuv" 26] puts $f $s close $f set f [open test1 r] fconfigure $f -translation lf -eofchar {} set l "" lappend l [gets $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] close $f set l} "abc def 0 \x1aqrs 0 tuv 0 {} 1"test io-8.23 {Tcl_Write, ^Z in middle ignored, Tcl_Gets cr} { removeFile test1 set f [open test1 w] fconfigure $f -translation cr -eofchar {} set s [format "abc\ndef\n%cqrs\ntuv" 26] puts $f $s close $f set f [open test1 r] fconfigure $f -translation cr -eofchar {} set l "" lappend l [gets $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] close $f set l} "abc def 0 \x1aqrs 0 tuv 0 {} 1"test io-8.24 {Tcl_Write, ^Z in middle ignored, Tcl_Gets crlf} { removeFile test1 set f [open test1 w] fconfigure $f -translation crlf -eofchar {} set s [format "abc\ndef\n%cqrs\ntuv" 26] puts $f $s close $f set f [open test1 r] fconfigure $f -translation crlf -eofchar {} set l "" lappend l [gets $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] close $f set l} "abc def 0 \x1aqrs 0 tuv 0 {} 1"test io-8.25 {Tcl_Write lf, ^Z in middle, Tcl_Gets auto} { removeFile test1 set f [open test1 w] fconfigure $f -translation lf set s [format "abc\ndef\n%cqrs\ntuv" 26] puts $f $s close $f set f [open test1 r] fconfigure $f -translation auto -eofchar \x1a set l "" lappend l [gets $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] close $f set l} {abc def 0 {} 1}test io-8.26 {Tcl_Write lf, ^Z in middle, Tcl_Gets lf} { removeFile test1 set f [open test1 w] fconfigure $f -translation lf set s [format "abc\ndef\n%cqrs\ntuv" 26] puts $f $s close $f set f [open test1 r] fconfigure $f -translation lf -eofchar \x1a set l "" lappend l [gets $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] close $f set l} {abc def 0 {} 1}test io-8.27 {Tcl_Write cr, ^Z in middle, Tcl_Gets auto} { removeFile test1 set f [open test1 w] fconfigure $f -translation cr -eofchar {} set s [format "abc\ndef\n%cqrs\ntuv" 26] puts $f $s close $f set f [open test1 r] fconfigure $f -translation auto -eofchar \x1a set l "" lappend l [gets $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] close $f set l} {abc def 0 {} 1}test io-8.28 {Tcl_Write cr, ^Z in middle, Tcl_Gets cr} { removeFile test1 set f [open test1 w] fconfigure $f -translation cr -eofchar {} set s [format "abc\ndef\n%cqrs\ntuv" 26] puts $f $s close $f set f [open test1 r] fconfigure $f -translation cr -eofchar \x1a set l "" lappend l [gets $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] close $f set l} {abc def 0 {} 1}test io-8.29 {Tcl_Write crlf, ^Z in middle, Tcl_Gets auto} { removeFile test1 set f [open test1 w] fconfigure $f -translation crlf -eofchar {} set s [format "abc\ndef\n%cqrs\ntuv" 26] puts $f $s close $f set f [open test1 r] fconfigure $f -translation auto -eofchar \x1a set l "" lappend l [gets $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] close $f set l} {abc def 0 {} 1}test io-8.30 {Tcl_Write crlf, ^Z in middle, Tcl_Gets crlf} { removeFile test1 set f [open test1 w] fconfigure $f -translation crlf -eofchar {} set s [format "abc\ndef\n%cqrs\ntuv" 26] puts $f $s close $f set f [open test1 r] fconfigure $f -translation crlf -eofchar \x1a set l "" lappend l [gets $f] lappend l [gets $f] lappend l [eof $f] lappend l [gets $f] lappend l [eof $f] close $f set l} {abc def 0 {} 1}test io-8.31 {Tcl_Write crlf on block boundary, Tcl_Gets auto} { removeFile test1 set f [open test1 w] fconfigure $f -translation crlf set line "123456789ABCDE" ;# 14 char plus crlf puts -nonewline $f x ;# shift crlf across block boundary for {set i 0} {$i < 700} {incr i} { puts $f $line } close $f set f [open test1 r] fconfigure $f -translation auto set c "" while {[gets $f line] >= 0} { append c $line\n } close $f string length $c} [expr 700*15+1]test io-8.32 {Tcl_Write crlf on block boundary, Tcl_Gets auto} { removeFile test1 set f [open test1 w] fconfigure $f -translation crlf set line "123456789ABCDE" ;# 14 char plus crlf puts -nonewline $f x ;# shift crlf across block boundary for {set i 0} {$i < 256} {incr i} { puts $f $line } close $f set f [open test1 r] fconfigure $f -translation auto set c "" while {[gets $f line] >= 0} { append c $line\n } close $f string length $c} [expr 256*15+1]# Test Tcl_Read and buffering.test io-9.1 {Tcl_Read, channel not readable} { list [catch {read stdout} msg] $msg} {1 {channel "stdout" wasn't opened for reading}}test io-9.2 {Tcl_Read, zero byte count} { read stdin 0} ""test io-9.3 {Tcl_Read, negative byte count} { set f [open longfile r] set l [list [catch {read $f -1} msg] $msg] close $f set l} {1 {bad argument "-1": should be "nonewline"}}test io-9.4 {Tcl_Read, positive byte count} { set f [open longfile r] set x [read $f 1024] set s [string length $x] unset x close $f set s} 1024test io-9.5 {Tcl_Read, multiple buffers} { set f [open longfile r] fconfigure $f -buffersize 100 set x [read $f 1024] set s [string length $x] unset x close $f set s} 1024test io-9.6 {Tcl_Read, very large read} { set f1 [open longfile r] set z [read $f1 1000000] close $f1 set l [string length $z] set x ok set z [file size longfile] if {$z != $l} { set x broken } set x} oktest io-9.7 {Tcl_Read, nonblocking, file} {nonBlockFiles} { set f1 [open longfile r] fconfigure $f1 -blocking off set z [read $f1 20] close $f1 set l [string length $z] set x ok if {$l != 20} { set x broken } set x} oktest io-9.8 {Tcl_Read, nonblocking, file} {nonBlockFiles} { set f1 [open longfile r] fconfigure $f1 -blocking off set z [read $f1 1000000] close $f1 set x ok set l [string length $z]] set z [file size longfile]] if {$z != $l} { set x broken } set x} oktest io-9.9 {Tcl_Read, read to end of file} { set f1 [open longfile r] set z [read $f1] close $f1 set l [string length $z] set x ok set z [file size longfile] if {$z != $l} { set x broken } set x} oktest io-9.10 {Tcl_Read from a pipe} {stdio} { removeFile pipe set f1 [open pipe w] puts $f1 {puts [gets stdin]} close $f1 set f1 [open "|[list $tcltest pipe]" r+] puts $f1 hello flush $f1 set x [read $f1] close $f1 set x} "hello\n"test io-9.11 {Tcl_Read from a pipe} {stdio} { removeFile pipe set f1 [open pipe w] puts $f1 {puts [gets stdin]} puts $f1 {puts [gets stdin]} close $f1 set f1 [open "|[list $tcltest pipe]" r+] puts $f1 hello flush $f1 set x "" lappend x [read $f1 6] puts $f1 hello flush $f1 lappend x [read $f1] close $f1 set x} {{hello} {hello}}test io-9.12 {Tcl_Read, -nonewline} { removeFile test1 set f1 [open test1 w] puts $f1 hello puts $f1 bye close $f1 set f1 [open test1 r] set c [read -nonewline $f1] close $f1 set c} {hellobye}test io-9.13 {Tcl_Read, -nonewline} { removeFile test1 set f1 [open test1 w] puts $f1 hello puts $f1 bye close $f1 set f1 [open test1 r] set c [read -nonewline $f1] close $f1 list [string length $c] $c} {9 {hellobye}}test io-9.14 {Tcl_Read, reading in small chunks} { removeFile test1 set f [open test1 w] puts $f "Two lines: this one" puts $f "and this one" close $f set f [open test1] set x [list [read $f 1] [read $f 2] [read $f]] close $f set x} {T wo { lines: this oneand this one}}test io-9.15 {Tcl_Read, asking for more input than available} { removeFile test1 set f [open test1 w] puts $f "Two lines: this one" puts $f "and this one" close $f set f [open test1] set x [read $f 100] close $f set x} {Two lines: this oneand this one}test io-9.16 {Tcl_Read, read to end of file with -nonewline} { removeFile test1 set f [open test1 w] puts $f "Two lines: this one" puts $f "and this one" close $f set f [open test1] set x [read -nonewline $f] close $f set x} {Two lines: this oneand this one}# Test Tcl_Gets.test io-10.1 {Tcl_Gets, reading what was written} { removeFile test1 set f1 [open test1 w] set y "first line" puts $f1 $y close $f1 set f1 [open test1 r] set x [gets $f1] set z ok if {"$x" != "$y"} { set z broken } close $f1 set z} oktest io-10.2 {Tcl_Gets into variable} { set f1 [open longfile r] set c [gets $f1 x] set l [string length x] set z ok if {$l != $l} { set z broken } close $f1 set z} oktest io-10.3 {Tcl_Gets from pipe} {stdio} { removeFile pipe set f1 [open pipe w] puts $f1 {puts [gets stdin]} close $f1 set f1 [open "|[list $tcltest pipe]" r+] puts $f1 hello flush $f1 set x [gets $f1] close $f1 set z ok if {"$x" != "hello"} { set z broken } set z} oktest io-10.4 {Tcl_Gets with long line} { removeFile test3 set f [open test3 w] puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" close $f set f [open test3] set x [gets $f] close $f set x} {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ}test io-10.5 {Tcl_Gets with long line} { set f [open test3] set x [gets $f y] close $f list $x $y} {260 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ}test io-10.6 {Tcl_Gets and end of file} { removeFile test3 set f [open test3 w] puts -nonewline $f "Test1\nTest2" close $f set f [open test3] set x {} set y {} lappend x [gets $f y] $y set y {} lappend x [gets $f y] $y set y {} lappend x [gets $f y] $y close $f set x} {5 Test1 5 Test2 -1 {}}test io-10.7 {Tcl_Gets and bad variable} { set f [open test3 w] puts $f "Line 1" puts $f "Line 2" close $f catch {unset x} set x 24 set f [open test3 r] set result [list [catch {gets $f x(0)} msg] $msg] close $f set result} {1 {can't set "x(0)": variable isn't array}}test io-10.8 {Tcl_Gets, exercising double buffering} { set f [open test3 w] fconfigure $f -translation lf -eofchar {} set x "" for {set y 0} {$y < 99} {incr y} {set x "a$x"} for {set y 0} {$y < 100} {incr y} {puts $f $x}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -