Index: modules/virtchannel_base/memchan.tcl ================================================================== --- modules/virtchannel_base/memchan.tcl +++ modules/virtchannel_base/memchan.tcl @@ -5,11 +5,11 @@ # Variable string channel (in-memory r/w file, internal variable). # Seekable beyond the end of the data, implies appending of 0x00 # bytes. # @@ Meta Begin -# Package tcl::chan::memchan 1.0.2 +# Package tcl::chan::memchan 1.0.4 # Meta as::author {Andreas Kupries} # Meta as::copyright 2009 # Meta as::license BSD # Meta description Re-implementation of Memchan's memchan # Meta description channel. Based on Tcl 8.5's channel @@ -129,22 +129,23 @@ # Compute the new location per the arguments. set max [string length $content] switch -exact -- $base { start { set newloc $offset} - current { set newloc [expr {$at + $offset }] } - end { set newloc [expr {$max + $offset - 1}] } + current { set newloc [expr {$at + $offset }] } + end { set newloc [expr {$max + $offset }] } } # Check if the new location is beyond the range given by the # content. if {$newloc < 0} { return -code error "Cannot seek before the start of the channel" - } elseif {$newloc >= $max} { + } elseif {$newloc > $max} { # We can seek beyond the end of the current contents, add # a block of zeros. + #puts XXX.PAD.[expr {$newloc - $max}] append content [binary format @[expr {$newloc - $max}]] } # Commit to new location, switch readable events, and report. set at $newloc @@ -162,7 +163,7 @@ my allow read } } # # ## ### ##### ######## ############# -package provide tcl::chan::memchan 1.0.3 +package provide tcl::chan::memchan 1.0.4 return ADDED modules/virtchannel_base/memchan.test Index: modules/virtchannel_base/memchan.test ================================================================== --- /dev/null +++ modules/virtchannel_base/memchan.test @@ -0,0 +1,92 @@ +# ------------------------------------------------------------------------- +# memchan.test -*- tcl -*- +# (C) 2017 Andreas Kupries. BSD licensed. +# ------------------------------------------------------------------------- + +source [file join \ + [file dirname [file dirname [file join [pwd] [info script]]]] \ + devtools testutilities.tcl] + +testsNeedTcl 8.5 +testsNeedTcltest 2.0 +testsNeed TclOO 1 + +support { + use virtchannel_core/core.tcl tcl::chan::core + use virtchannel_core/events.tcl tcl::chan::events +} +testing { + useLocal memchan.tcl tcl::chan::memchan +} + +# ------------------------------------------------------------------------- + +test tcl-chan-memchan-1.0 {constructor wrong\#args} -body { + tcl::chan::memchan X +} -returnCodes error \ + -result {wrong # args: should be "tcl::chan::memchan"} + +# ------------------------------------------------------------------------- + +test tcl-chan-memchan-2.0 {tell, initial, empty} -setup { + set c [tcl::chan::memchan] +} -body { + tell $c +} -cleanup { + close $c + unset c +} -result 0 + +test tcl-chan-memchan-2.1 {seek from start, expand, tell} -setup { + set c [tcl::chan::memchan] +} -body { + seek $c 10 + tell $c +} -cleanup { + close $c + unset c +} -result 10 + +test tcl-chan-memchan-2.2 {seek from end, eof, empty, tell} -setup { + set c [tcl::chan::memchan] +} -body { + seek $c 0 end + tell $c +} -cleanup { + close $c + unset c +} -result 0 + +test tcl-chan-memchan-2.3 {seek from end, eof, non-empty, tell} -setup { + set c [tcl::chan::memchan] + puts $c Hello +} -body { + seek $c 0 end + tell $c +} -cleanup { + close $c + unset c +} -result 6 + +test tcl-chan-memchan-2.4 {seek from end, non-eof, non-empty, tell} -setup { + set c [tcl::chan::memchan] + puts $c Hello +} -body { + seek $c -6 end + tell $c +} -cleanup { + close $c + unset c +} -result 0 + +# ------------------------------------------------------------------------- +# Explicit cleanup of loaded support classes. +rename tcl::chan::events {} +rename tcl::chan::core {} +testsuiteCleanup +return + +# Local Variables: +# mode: tcl +# indent-tabs-mode: nil +# End: Index: modules/virtchannel_base/pkgIndex.tcl ================================================================== --- modules/virtchannel_base/pkgIndex.tcl +++ modules/virtchannel_base/pkgIndex.tcl @@ -3,15 +3,15 @@ package ifneeded tcl::chan::cat 1.0.2 [list source [file join $dir cat.tcl]] package ifneeded tcl::chan::facade 1.0.1 [list source [file join $dir facade.tcl]] package ifneeded tcl::chan::fifo 1 [list source [file join $dir fifo.tcl]] package ifneeded tcl::chan::fifo2 1 [list source [file join $dir fifo2.tcl]] package ifneeded tcl::chan::halfpipe 1 [list source [file join $dir halfpipe.tcl]] -package ifneeded tcl::chan::memchan 1.0.3 [list source [file join $dir memchan.tcl]] +package ifneeded tcl::chan::memchan 1.0.4 [list source [file join $dir memchan.tcl]] package ifneeded tcl::chan::null 1 [list source [file join $dir null.tcl]] package ifneeded tcl::chan::nullzero 1 [list source [file join $dir nullzero.tcl]] package ifneeded tcl::chan::random 1 [list source [file join $dir random.tcl]] package ifneeded tcl::chan::std 1.0.1 [list source [file join $dir std.tcl]] -package ifneeded tcl::chan::string 1.0.2 [list source [file join $dir string.tcl]] +package ifneeded tcl::chan::string 1.0.3 [list source [file join $dir string.tcl]] package ifneeded tcl::chan::textwindow 1 [list source [file join $dir textwindow.tcl]] -package ifneeded tcl::chan::variable 1.0.3 [list source [file join $dir variable.tcl]] +package ifneeded tcl::chan::variable 1.0.4 [list source [file join $dir variable.tcl]] package ifneeded tcl::chan::zero 1 [list source [file join $dir zero.tcl]] package ifneeded tcl::randomseed 1 [list source [file join $dir randseed.tcl]] Index: modules/virtchannel_base/string.tcl ================================================================== --- modules/virtchannel_base/string.tcl +++ modules/virtchannel_base/string.tcl @@ -1,11 +1,11 @@ # -*- tcl -*- # # ## ### ##### ######## ############# # (C) 2009 Andreas Kupries # @@ Meta Begin -# Package tcl::chan::string 1 +# Package tcl::chan::string 1.0.3 # Meta as::author {Andreas Kupries} # Meta as::copyright 2009 # Meta as::license BSD # Meta description Implementation of a channel representing # Meta description an in-memory read-only random-access @@ -87,20 +87,20 @@ # Compute the new location per the arguments. set max [string length $content] switch -exact -- $base { start { set newloc $offset} - current { set newloc [expr {$at + $offset }] } - end { set newloc [expr {$max + $offset - 1}] } + current { set newloc [expr {$at + $offset }] } + end { set newloc [expr {$max + $offset }] } } # Check if the new location is beyond the range given by the # content. if {$newloc < 0} { return -code error "Cannot seek before the start of the channel" - } elseif {$newloc >= $max} { + } elseif {$newloc > $max} { return -code error "Cannot seek after the end of the channel" } # Commit to new location, switch readable events, and report. set at $newloc @@ -118,7 +118,7 @@ my allow read } } # # ## ### ##### ######## ############# -package provide tcl::chan::string 1.0.2 +package provide tcl::chan::string 1.0.3 return ADDED modules/virtchannel_base/string.test Index: modules/virtchannel_base/string.test ================================================================== --- /dev/null +++ modules/virtchannel_base/string.test @@ -0,0 +1,94 @@ +# ------------------------------------------------------------------------- +# string.test -*- tcl -*- +# (C) 2017 Andreas Kupries. BSD licensed. +# ------------------------------------------------------------------------- + +source [file join \ + [file dirname [file dirname [file join [pwd] [info script]]]] \ + devtools testutilities.tcl] + +testsNeedTcl 8.5 +testsNeedTcltest 2.0 +testsNeed TclOO 1 + +support { + use virtchannel_core/core.tcl tcl::chan::core + use virtchannel_core/events.tcl tcl::chan::events +} +testing { + useLocal string.tcl tcl::chan::string +} + +# ------------------------------------------------------------------------- + +test tcl-chan-string-1.0 {constructor wrong\#args} -body { + tcl::chan::string +} -returnCodes error \ + -result {wrong # args: should be "tcl::chan::string content"} + +test tcl-chan-string-1.1 {constructor wrong\#args} -body { + tcl::chan::string C X +} -returnCodes error \ + -result {wrong # args: should be "tcl::chan::string content"} + +# ------------------------------------------------------------------------- + +test tcl-chan-string-2.0 {tell, initial, empty} -setup { + set c [tcl::chan::string ""] +} -body { + tell $c +} -cleanup { + close $c + unset c +} -result 0 + +test tcl-chan-string-2.1 {seek from start beyond eof is error} -setup { + set c [tcl::chan::string ""] +} -body { + seek $c 10 +} -cleanup { + close $c + unset c +} -returnCodes error -result {Cannot seek after the end of the channel} + +test tcl-chan-string-2.2 {seek from end, eof, empty, tell} -setup { + set c [tcl::chan::string ""] +} -body { + seek $c 0 end + tell $c +} -cleanup { + close $c + unset c +} -result 0 + +test tcl-chan-string-2.3 {seek from end, eof, non-empty, tell} -setup { + set c [tcl::chan::string Hello\n] +} -body { + seek $c 0 end + tell $c +} -cleanup { + close $c + unset c +} -result 6 + +test tcl-chan-string-2.4 {seek from end, non-eof, non-empty, tell} -setup { + set c [tcl::chan::string Hello\n] +} -body { + seek $c -6 end + tell $c +} -cleanup { + close $c + unset c +} -result 0 + +# ------------------------------------------------------------------------- +# Explicit cleanup of loaded support classes. +rename tcl::chan::events {} +rename tcl::chan::core {} +testsuiteCleanup +return + +# Local Variables: +# mode: tcl +# indent-tabs-mode: nil +# End: Index: modules/virtchannel_base/tcllib_memchan.man ================================================================== --- modules/virtchannel_base/tcllib_memchan.man +++ modules/virtchannel_base/tcllib_memchan.man @@ -1,19 +1,20 @@ +[vset VERSION 1.0.4] [comment {-*- tcl -*- doctools manpage}] -[manpage_begin tcl::chan::memchan n 1] +[manpage_begin tcl::chan::memchan n [vset VERSION]] [keywords {in-memory channel}] [keywords {reflected channel}] [keywords {tip 219}] [keywords {virtual channel}] -[copyright {2009 Andreas Kupries }] +[copyright {2009-2017 Andreas Kupries }] [moddesc {Reflected/virtual channel support}] [category Channels] [titledesc {In-memory channel}] [require Tcl 8.5] [require TclOO] [require tcl::chan::events [opt 1]] -[require tcl::chan::memchan [opt 1]] +[require tcl::chan::memchan [opt [vset VERSION]]] [description] [para] The [package tcl::chan::memchan] package provides a command creating channels which live purely in memory. They provide random-access, Index: modules/virtchannel_base/tcllib_string.man ================================================================== --- modules/virtchannel_base/tcllib_string.man +++ modules/virtchannel_base/tcllib_string.man @@ -1,7 +1,8 @@ +[vset VERSION 1.0.3] [comment {-*- tcl -*- doctools manpage}] -[manpage_begin tcl::chan::string n 1] +[manpage_begin tcl::chan::string n [vset VERSION]] [keywords {in-memory channel}] [keywords {reflected channel}] [keywords {tip 219}] [keywords {virtual channel}] [copyright {2009 Andreas Kupries }] @@ -9,11 +10,11 @@ [category Channels] [titledesc {Read-only in-memory channel}] [require Tcl 8.5] [require TclOO] [require tcl::chan::events [opt 1]] -[require tcl::chan::string [opt 1]] +[require tcl::chan::string [opt [vset VERSION]]] [description] [para] The [package tcl::chan::string] package provides a command creating channels which live purely in memory. They provide random-access, Index: modules/virtchannel_base/tcllib_variable.man ================================================================== --- modules/virtchannel_base/tcllib_variable.man +++ modules/virtchannel_base/tcllib_variable.man @@ -1,7 +1,8 @@ +[vset VERSION 1.0.4] [comment {-*- tcl -*- doctools manpage}] -[manpage_begin tcl::chan::variable n 1] +[manpage_begin tcl::chan::variable n [vset VERSION]] [keywords {in-memory channel}] [keywords {reflected channel}] [keywords {tip 219}] [keywords {virtual channel}] [copyright {2009 Andreas Kupries }] @@ -9,11 +10,11 @@ [category Channels] [titledesc {In-memory channel using variable for storage}] [require Tcl 8.5] [require TclOO] [require tcl::chan::events [opt 1]] -[require tcl::chan::variable [opt 1]] +[require tcl::chan::variable [opt [vset VERSION]]] [description] [para] The [package tcl::chan::variable] package provides a command creating channels which live purely in memory. They provide random-access, Index: modules/virtchannel_base/variable.tcl ================================================================== --- modules/virtchannel_base/variable.tcl +++ modules/virtchannel_base/variable.tcl @@ -1,11 +1,11 @@ # -*- tcl -*- # # ## ### ##### ######## ############# # (C) 2009 Andreas Kupries # @@ Meta Begin -# Package tcl::chan::variable 1.0.2 +# Package tcl::chan::variable 1.0.4 # Meta as::author {Andreas Kupries} # Meta as::copyright 2009 # Meta as::license BSD # Meta description Implementation of a channel representing # Meta description an in-memory read-write random-access @@ -142,20 +142,20 @@ # Compute the new location per the arguments. set max [string length $content] switch -exact -- $base { start { set newloc $offset} - current { set newloc [expr {$at + $offset }] } - end { set newloc [expr {$max + $offset - 1}] } + current { set newloc [expr {$at + $offset }] } + end { set newloc [expr {$max + $offset }] } } # Check if the new location is beyond the range given by the # content. if {$newloc < 0} { return -code error "Cannot seek before the start of the channel" - } elseif {$newloc >= $max} { + } elseif {$newloc > $max} { # We can seek beyond the end of the current contents, add # a block of zeros. append content [binary format @[expr {$newloc - $max}]] } @@ -175,7 +175,7 @@ my allow read } } # # ## ### ##### ######## ############# -package provide tcl::chan::variable 1.0.3 +package provide tcl::chan::variable 1.0.4 return ADDED modules/virtchannel_base/variable.test Index: modules/virtchannel_base/variable.test ================================================================== --- /dev/null +++ modules/virtchannel_base/variable.test @@ -0,0 +1,102 @@ +# ------------------------------------------------------------------------- +# variable.test -*- tcl -*- +# (C) 2017 Andreas Kupries. BSD licensed. +# ------------------------------------------------------------------------- + +source [file join \ + [file dirname [file dirname [file join [pwd] [info script]]]] \ + devtools testutilities.tcl] + +testsNeedTcl 8.5 +testsNeedTcltest 2.0 +testsNeed TclOO 1 + +support { + use virtchannel_core/core.tcl tcl::chan::core + use virtchannel_core/events.tcl tcl::chan::events +} +testing { + useLocal variable.tcl tcl::chan::variable +} + +# ------------------------------------------------------------------------- + +test tcl-chan-variable-1.0 {constructor wrong\#args} -body { + tcl::chan::variable +} -returnCodes error \ + -result {wrong # args: should be "tcl::chan::variable varname"} + +test tcl-chan-variable-1.1 {constructor wrong\#args} -body { + tcl::chan::variable V X +} -returnCodes error \ + -result {wrong # args: should be "tcl::chan::variable varname"} + +# ------------------------------------------------------------------------- + +test tcl-chan-variable-2.0 {tell, initial, empty} -setup { + set content "" + set c [tcl::chan::variable content] +} -body { + tell $c +} -cleanup { + close $c + unset c content +} -result 0 + +test tcl-chan-variable-2.1 {seek from start, expand, tell} -setup { + set content "" + set c [tcl::chan::variable content] +} -body { + seek $c 10 + tell $c +} -cleanup { + close $c + unset c content +} -result 10 + +test tcl-chan-variable-2.2 {seek from end, eof, empty, tell} -setup { + set content "" + set c [tcl::chan::variable content] +} -body { + seek $c 0 end + tell $c +} -cleanup { + close $c + unset c content +} -result 0 + +test tcl-chan-variable-2.3 {seek from end, eof, non-empty, tell} -setup { + set content "" + set c [tcl::chan::variable content] + puts $c Hello +} -body { + seek $c 0 end + tell $c +} -cleanup { + close $c + unset c content +} -result 6 + +test tcl-chan-variable-2.4 {seek from end, non-eof, non-empty, tell} -setup { + set content "" + set c [tcl::chan::variable content] + puts $c Hello +} -body { + seek $c -6 end + tell $c +} -cleanup { + close $c + unset c content +} -result 0 + +# ------------------------------------------------------------------------- +# Explicit cleanup of loaded support classes. +rename tcl::chan::events {} +rename tcl::chan::core {} +testsuiteCleanup +return + +# Local Variables: +# mode: tcl +# indent-tabs-mode: nil +# End: