REBOL [ Title: "REBOL Test - File Seek Action Verification (Small File)" Copyright: "2005 REBOL Technologies" Version: 1.0.4 ] if system/build < 30-Aug-2005/16:46:19-7:00 [ ask "Your version of REBOL is too old. This test will not work." quit ] print ["Running Seek Test" system/version system/build] file: %test2.txt tests: [ ;-- Create very simple file for easy debugging: [write file "abcdefg" true] ;-- Open the port as a SEEK-oriented TEXT file: [port? port: open/seek file] ;-- Port object related: [port/size = 7] [port/target = file] [port/scheme = 'file] [#"a" = port/1] ; DO NOT USE - DEPRECIATED! [#"g" = port/7] ; DO NOT USE - DEPRECIATED! ;-- Standard series info/compares: [p: next port p = port] [p: next port same? p port] [head? port] [head? head tail port] [not tail? port] [tail? tail port] [7 = length? port] [1 = index? port] [1 = index? head port] [8 = index? tail port] ;-- COPY actions: [string? copy port] [string? copy/part port 2] ["abcdefg" = copy port] ["ab" = copy/part port 2] ["" = copy/part port 0] ["abcdefg" = copy/part port 99999] ["bc" = copy/part next port 2] ["fg" = copy/part back back tail port 2] ["cd" = copy/part skip port 2 2] [p: next port "bc" = copy/part p 2] ;-- PICK related actions: [char? first port] [#"a" = first port] [#"b" = second port] [#"g" = seventh port] [char? pick port 1] [#"a" = pick port 1] [#"a" = pick port 1.0] [#"b" = pick port 2] [#"g" = pick port 7] [#"a" = pick port true] [#"b" = pick port false] [#"a" = first skip port 0] [#"b" = first skip port 1] [#"b" = first skip port 1.0] [#"g" = first skip port 6] [#"a" = first skip port true] [#"b" = first skip port false] [#"a" = first at port 1] [#"a" = first at port 1.0] [#"b" = first at port 2] [#"g" = first at port 7] [#"a" = first at port true] [#"b" = first at port false] [#"a" = first head tail port] [#"b" = first next port] [#"g" = first back tail port] [#"g" = last port] ;-- CHANGE action: [p1: change port "x" "xb" = copy/part port 2] [port? p1] [2 = index? p1] [change port #"z" "zb" = copy/part port 2] [change port 1 "1b" = copy/part port 2] [p1: change port "xy" "xyc" = copy/part port 3] [3 = index? p1] [change next port "z" "xzc" = copy/part port 3] [change back tail port "1" "f1" = copy/part back back tail port 2] ;-- CHANGE used to append: [p1: change tail port "2" "f12" = copy/part skip tail port -3 3] [port? p1] [tail? p1] [(index? p1) = index? tail port] [8 = length? port] [9 = index? tail port] ;-- INSERT used to append: [p1: insert tail port "89" "89" = copy/part back back tail port 2] [port? p1] [tail? p1] [(index? p1) = index? tail port] [10 = length? port] [11 = index? tail port] [error? try [insert port "ab"]] ; not allowed except at tail [p1: insert tail port "!"] [port? p1] [tail? p1] [11 = length? port] [12 = index? tail port] ;-- CLEAR (truncate) file: [p1: clear skip port 3 3 = length? port] [port? p1] [tail? p1] [4 = index? p1] [p1: clear port] [port? p1] [head? p1] [tail? p1] [1 = index? p1] [empty? port] ;-- These are not allowed: [error? try [find port "ab"]] [error? try [select port "ab"]] [error? try [remove port]] [close port true] [zero? size? file] ;-- Quick check of binary return values: [write file "abcdefg" true] [port? port: open/seek/binary file] [binary? copy port] [binary? copy/part port 2] [integer? pick port 1] [integer? first port] [integer? last port] [change port to-char 0 0 = to-integer pick port 1] [change next port to-char 255 255 = to-integer pick port 2] [change change port 1234 5678 "12345678" = to-string copy/part port 8] [close port true] ;-- Invalid file modes: [error? try [close open/direct/seek file]] [error? try [close open/lines/seek file]] ] err-cnt: 0 foreach test tests [ print [pick [fail ok] stat: not do test mold test] if stat [err-cnt: err-cnt + 1] ] print [err-cnt "errors"] halt