rio 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +1273 -1482
- data/README +2 -2
- data/Rakefile +5 -5
- data/VERSION +1 -1
- data/{RUNME.1st.rb → build_doc.rb} +4 -10
- data/doc/ANNOUNCE +33 -80
- data/doc/RELEASE_NOTES +31 -1
- data/doc/generators/template/html/rio.rb +3 -3
- data/lib/rio/abstract_method.rb +2 -2
- data/lib/rio/argv.rb +2 -2
- data/lib/rio/arycopy.rb +2 -2
- data/lib/rio/assert.rb +2 -2
- data/lib/rio/base.rb +2 -2
- data/lib/rio/callstr.rb +47 -0
- data/lib/rio/const.rb +52 -0
- data/lib/rio/construct.rb +6 -24
- data/lib/rio/constructor.rb +12 -2
- data/lib/rio/context/autoclose.rb +73 -0
- data/lib/rio/context/copying.rb +2 -2
- data/lib/rio/context/cxx.rb +2 -2
- data/lib/rio/context/dir.rb +2 -2
- data/lib/rio/context/gzip.rb +2 -2
- data/lib/rio/context/methods.rb +6 -34
- data/lib/rio/context/skip.rb +2 -2
- data/lib/rio/context/stream.rb +2 -2
- data/lib/rio/context.rb +17 -2
- data/lib/rio/cp.rb +35 -9
- data/lib/rio/def.rb +54 -0
- data/lib/rio/dir.rb +19 -20
- data/lib/rio/doc/HOWTO.rb +23 -7
- data/lib/rio/doc/INTRO.rb +57 -23
- data/lib/rio/doc/MISC.rb +2 -2
- data/lib/rio/doc/OPTIONAL.rb +134 -0
- data/lib/rio/doc/SYNOPSIS.rb +11 -4
- data/lib/rio/doc.rb +2 -2
- data/lib/rio/entrysel.rb +25 -6
- data/lib/rio/exception/copy.rb +2 -2
- data/lib/rio/exception/notsupported.rb +47 -0
- data/lib/rio/exception/open.rb +2 -2
- data/lib/rio/exception/state.rb +2 -2
- data/lib/rio/exception.rb +2 -2
- data/lib/rio/ext/csv.rb +56 -11
- data/lib/rio/ext/yaml.rb +2 -2
- data/lib/rio/ext/zipfile.rb +91 -0
- data/lib/rio/ext.rb +38 -3
- data/lib/rio/factory.rb +17 -34
- data/lib/rio/file.rb +48 -8
- data/lib/rio/filter/closeoneof.rb +36 -16
- data/lib/rio/filter/gzip.rb +2 -2
- data/lib/rio/filter.rb +2 -2
- data/lib/rio/fs/base.rb +42 -0
- data/lib/rio/fs/impl.rb +123 -0
- data/lib/rio/fs/native.rb +76 -0
- data/lib/rio/{record.rb → fs/stream.rb} +21 -18
- data/lib/rio/fs/url.rb +64 -0
- data/lib/rio/ftp/{ioh.rb → conncache.rb} +38 -39
- data/lib/rio/ftp/dir.rb +95 -0
- data/lib/rio/ftp/fs.rb +173 -0
- data/lib/rio/ftp/ftpfile.rb +20 -0
- data/lib/rio/grande.rb +2 -2
- data/lib/rio/handle.rb +2 -2
- data/lib/rio/if/basic.rb +2 -2
- data/lib/rio/if/csv.rb +2 -2
- data/lib/rio/if/dir.rb +2 -2
- data/lib/rio/if/file.rb +26 -2
- data/lib/rio/if/fileordir.rb +44 -49
- data/lib/rio/if/grande.rb +32 -10
- data/lib/rio/if/grande_entry.rb +12 -2
- data/lib/rio/if/grande_stream.rb +17 -28
- data/lib/rio/if/internal.rb +2 -2
- data/lib/rio/if/path.rb +7 -6
- data/lib/rio/if/stream.rb +85 -29
- data/lib/rio/if/string.rb +2 -2
- data/lib/rio/if/temp.rb +2 -2
- data/lib/rio/if/test.rb +37 -4
- data/lib/rio/if/yaml.rb +2 -2
- data/lib/rio/if.rb +2 -2
- data/lib/rio/impl/path.rb +2 -2
- data/lib/rio/ioh.rb +17 -6
- data/lib/rio/iomode.rb +4 -3
- data/lib/rio/ios/fail.rb +107 -0
- data/lib/rio/ios/generic.rb +120 -0
- data/lib/rio/ios/mode.rb +61 -0
- data/lib/rio/ios/null.rb +120 -0
- data/lib/rio/iowrap.rb +129 -0
- data/lib/rio/kernel.rb +12 -3
- data/lib/rio/local.rb +2 -2
- data/lib/rio/match.rb +3 -3
- data/lib/rio/matchrecord.rb +2 -2
- data/lib/rio/no_warn.rb +50 -0
- data/lib/rio/{arrayio.rb → nullio.rb} +47 -86
- data/lib/rio/open3.rb +2 -2
- data/lib/rio/ops/construct.rb +20 -13
- data/lib/rio/ops/create.rb +10 -19
- data/lib/rio/ops/dir.rb +60 -54
- data/lib/rio/ops/either.rb +11 -9
- data/lib/rio/ops/file.rb +28 -24
- data/lib/rio/ops/path.rb +45 -43
- data/lib/rio/ops/stream/input.rb +12 -8
- data/lib/rio/ops/stream/output.rb +2 -2
- data/lib/rio/ops/stream/read.rb +35 -32
- data/lib/rio/ops/stream/write.rb +5 -5
- data/lib/rio/ops/stream.rb +7 -3
- data/lib/rio/ops/symlink.rb +12 -10
- data/lib/rio/path/reset.rb +5 -5
- data/lib/rio/path.rb +32 -24
- data/lib/rio/piper/cp.rb +2 -2
- data/lib/rio/piper.rb +2 -2
- data/lib/rio/prompt.rb +2 -2
- data/lib/rio/rectype.rb +9 -7
- data/lib/rio/rl/base.rb +5 -4
- data/lib/rio/rl/builder.rb +17 -5
- data/lib/rio/rl/ioi.rb +14 -4
- data/lib/rio/rl/path.rb +23 -15
- data/lib/rio/rl/pathmethods.rb +12 -2
- data/lib/rio/rl/uri.rb +13 -6
- data/lib/rio/scheme/aryio.rb +3 -3
- data/lib/rio/scheme/cmdio.rb +4 -3
- data/lib/rio/scheme/cmdpipe.rb +3 -35
- data/lib/rio/scheme/fd.rb +4 -3
- data/lib/rio/scheme/ftp.rb +36 -7
- data/lib/rio/scheme/http.rb +2 -2
- data/lib/rio/{context/closeoneof.rb → scheme/null.rb} +17 -11
- data/lib/rio/scheme/path.rb +28 -30
- data/lib/rio/scheme/stderr.rb +4 -4
- data/lib/rio/scheme/stdio.rb +6 -5
- data/lib/rio/scheme/strio.rb +10 -20
- data/lib/rio/scheme/sysio.rb +5 -2
- data/lib/rio/scheme/tcp.rb +4 -3
- data/lib/rio/scheme/temp.rb +14 -1
- data/lib/rio/state/error.rb +2 -2
- data/lib/rio/state.rb +80 -34
- data/lib/rio/stream/base.rb +7 -2
- data/lib/rio/stream/duplex.rb +13 -10
- data/lib/rio/stream/open.rb +74 -79
- data/lib/rio/stream.rb +15 -23
- data/lib/rio/symantics.rb +2 -2
- data/lib/rio/tempdir.rb +132 -132
- data/lib/rio/to_rio/all.rb +40 -0
- data/lib/rio/to_rio/array.rb +40 -0
- data/lib/rio/to_rio/io.rb +41 -0
- data/lib/rio/to_rio/object.rb +43 -0
- data/lib/rio/to_rio/string.rb +41 -0
- data/lib/rio/to_rio.rb +13 -2
- data/lib/rio/uri/file.rb +2 -2
- data/lib/rio/util.rb +2 -2
- data/lib/rio/version.rb +3 -3
- data/lib/rio.rb +16 -25
- data/test/bin/count_lines.rb +11 -0
- data/test/bin/find_lines.rb +13 -0
- data/test/bin/list_dir.rb +14 -0
- data/test/ftp/all.rb +9 -0
- data/test/ftp/anon_misc.rb +112 -0
- data/test/ftp/anon_read.rb +105 -0
- data/test/ftp/anon_special.rb +68 -0
- data/test/ftp/anon_write.rb +63 -0
- data/test/ftp/ftp2ftp.rb +51 -0
- data/test/ftp/initftpfiles.rb +14 -0
- data/test/ftp/testdef.rb +51 -0
- data/test/gem_runtests.rb +15 -15
- data/test/runalltests.rb +15 -0
- data/test/runftptests.rb +14 -0
- data/test/{1.rb → runhttptests.rb} +14 -14
- data/test/runtests.rb +14 -14
- data/test/tc/all.rb +36 -21
- data/test/tc/cmdpipe.rb +18 -15
- data/test/tc/copy-from-http.rb +89 -0
- data/test/tc/copy-from.rb +1 -52
- data/test/tc/copy.rb +19 -17
- data/test/tc/csv2.rb +6 -3
- data/test/tc/empty.rb +47 -0
- data/test/tc/emptyriodir.rb +129 -0
- data/test/tc/entsel.rb +110 -0
- data/test/tc/files_select.rb +92 -0
- data/test/tc/get.rb +7 -6
- data/test/tc/getrec.rb +2 -5
- data/test/tc/gzip.rb +82 -0
- data/test/tc/io_each_byte.rb +60 -0
- data/test/tc/io_read.rb +80 -0
- data/test/tc/iometh.rb +149 -0
- data/test/tc/likeio.rb +112 -0
- data/test/tc/methods.rb +10 -9
- data/test/tc/misc.rb +1 -37
- data/test/tc/null.rb +45 -0
- data/test/tc/pid.rb +31 -0
- data/test/tc/piper.rb +34 -37
- data/test/tc/programs_util.rb +24 -0
- data/test/tc/readline.rb +30 -0
- data/test/tc/rename.rb +12 -0
- data/test/tc/tempfile.rb +14 -0
- data/test/tc/testcase.rb +6 -0
- data/test/tc/tonl.rb +37 -0
- metadata +181 -144
- data/ex/colx.rb +0 -8
- data/ex/findinruby +0 -16
- data/ex/findruby +0 -15
- data/ex/passwd_report.rb +0 -8
- data/ex/prompt.rb +0 -25
- data/ex/rgb.txt.gz +0 -0
- data/ex/riocat +0 -35
- data/ex/riogunzip +0 -31
- data/ex/riogzip +0 -24
- data/ex/rioprompt.rb +0 -6
- data/ex/targz2zip +0 -17
- data/ex/tolf +0 -11
- data/lib/rio/ftp/conn.rb +0 -167
- data/lib/rio/ftp.rb +0 -275
- data/test/once.rb +0 -7
data/test/tc/entsel.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
if $0 == __FILE__
|
3
|
+
Dir.chdir File.dirname(__FILE__)+'/../'
|
4
|
+
$:.unshift File.expand_path('../lib/')
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rio'
|
8
|
+
require 'tc/testcase'
|
9
|
+
|
10
|
+
class TC_entsel < Test::RIO::TestCase
|
11
|
+
@@once = false
|
12
|
+
@@dirs = nil
|
13
|
+
DN = 'd'
|
14
|
+
OD = 'o'
|
15
|
+
def self.once
|
16
|
+
@@once = true
|
17
|
+
rio(DN).rmtree.mkpath.chdir {
|
18
|
+
mknd(3,3)
|
19
|
+
}
|
20
|
+
end
|
21
|
+
def setup
|
22
|
+
super
|
23
|
+
self.class.once unless @@once
|
24
|
+
@exp = rio(DN).all[]
|
25
|
+
@lev = []
|
26
|
+
@lev[1] = @exp.select{ |el| el.length == 3 }
|
27
|
+
@lev[2] = @exp.select{ |el| el.length == 5 }
|
28
|
+
@lev[3] = @exp.select{ |el| el.length == 7 }
|
29
|
+
@olev = []
|
30
|
+
@olev[1] = @lev[1].map{ |el| el.sub(/^d/,'o') }
|
31
|
+
@olev[2] = @lev[2].map{ |el| el.sub(/^d/,'o') }
|
32
|
+
@olev[3] = @lev[3].map{ |el| el.sub(/^d/,'o') }
|
33
|
+
end
|
34
|
+
include RIO_TestCase
|
35
|
+
|
36
|
+
def self.mknd(n,level)
|
37
|
+
return unless level > 0
|
38
|
+
dirs = (0...n).map{|i| rio(i.to_s).mkdir}
|
39
|
+
dirs.each{ |d|
|
40
|
+
d.chdir {
|
41
|
+
mknd(n,level-1)
|
42
|
+
}
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_skipdirs_copy1
|
47
|
+
odir = rio(OD).delete!
|
48
|
+
rio(DN).skipdirs(1) > odir
|
49
|
+
assert_array_equal([],odir.all[])
|
50
|
+
end
|
51
|
+
def test_skipdirs_copy2
|
52
|
+
odir = rio(OD).delete!
|
53
|
+
rio(DN).skipdirs(2) > odir
|
54
|
+
assert_array_equal(@olev[1],odir.all[])
|
55
|
+
end
|
56
|
+
def test_skipdirs_copy3
|
57
|
+
odir = rio(OD).delete!
|
58
|
+
rio(DN).skipdirs(3) > odir
|
59
|
+
assert_array_equal(@olev[1]+@olev[2],odir.all[])
|
60
|
+
end
|
61
|
+
def test_dirs_copy1
|
62
|
+
odir = rio(OD).delete!
|
63
|
+
rio(DN).dirs(1) > odir
|
64
|
+
assert_array_equal(@olev[1],odir.all[])
|
65
|
+
end
|
66
|
+
def test_dirs_copy2
|
67
|
+
odir = rio(OD).delete!
|
68
|
+
rio(DN).dirs(0..2) > odir
|
69
|
+
assert_array_equal(@olev[1]+@olev[2],odir.all[])
|
70
|
+
end
|
71
|
+
def test_dirs_copy3
|
72
|
+
odir = rio(OD).delete!
|
73
|
+
rio(DN).dirs(2) > odir
|
74
|
+
assert_array_equal([],odir.all[])
|
75
|
+
end
|
76
|
+
def test_dirs_array
|
77
|
+
rios1 = rios2str(rio(DN).dirs(1).to_a)
|
78
|
+
assert_equal(@lev[1],rios1)
|
79
|
+
rios2 = rios2str(rio(DN).dirs(2).to_a)
|
80
|
+
assert_equal([],rios2)
|
81
|
+
rios3 = rios2str(rio(DN).dirs(3).to_a)
|
82
|
+
assert_equal([],rios3)
|
83
|
+
end
|
84
|
+
def test_skipdirs_array
|
85
|
+
rios1 = rios2str(rio(DN).skipdirs(1).to_a)
|
86
|
+
assert_array_equal([],rios1)
|
87
|
+
rios2 = rios2str(rio(DN).skipdirs(2).to_a)
|
88
|
+
assert_array_equal(@lev[1],rios2)
|
89
|
+
rios3 = rios2str(rio(DN).skipdirs(3).to_a)
|
90
|
+
assert_array_equal(@lev[1],rios3)
|
91
|
+
end
|
92
|
+
def test_all_skipdirs_array
|
93
|
+
rios1 = rios2str(rio(DN).all.skipdirs(1).to_a)
|
94
|
+
assert_array_equal(@lev[2]+@lev[3],rios1)
|
95
|
+
rios2 = rios2str(rio(DN).all.skipdirs(2).to_a)
|
96
|
+
assert_array_equal(@lev[1]+@lev[3],rios2)
|
97
|
+
rios3 = rios2str(rio(DN).all.skipdirs(3).to_a)
|
98
|
+
assert_array_equal(@lev[1]+@lev[2],rios3)
|
99
|
+
end
|
100
|
+
def test_all_dirs_array
|
101
|
+
rios1 = rios2str(rio(DN).all.dirs(1).to_a)
|
102
|
+
assert_equal(@lev[1],rios1)
|
103
|
+
rios2 = rios2str(rio(DN).all.dirs(2).to_a)
|
104
|
+
assert_equal(@lev[2],rios2)
|
105
|
+
rios3 = rios2str(rio(DN).all.dirs(3).to_a)
|
106
|
+
assert_equal(@lev[3],rios3)
|
107
|
+
end
|
108
|
+
def test_sel
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
if $0 == __FILE__
|
3
|
+
Dir.chdir File.dirname(__FILE__)+'/../'
|
4
|
+
$:.unshift File.expand_path('../lib/')
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rio'
|
8
|
+
require 'tc/testcase'
|
9
|
+
|
10
|
+
class TC_files_select < Test::RIO::TestCase
|
11
|
+
@@once = false
|
12
|
+
def self.once
|
13
|
+
@@once = true
|
14
|
+
rio('d0').delete!.mkdir
|
15
|
+
rio('f0').delete!.puts!("f0:L0")
|
16
|
+
rio('f1').delete!.puts!("f1:L0")
|
17
|
+
rio('d0/f2').puts!("d0/f2:L0")
|
18
|
+
rio('d0/f3').puts!("d0/f3:L0")
|
19
|
+
end
|
20
|
+
def setup
|
21
|
+
super
|
22
|
+
self.class.once unless @@once
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_files_method_with_dir_rio_each
|
26
|
+
#$trace_states = true
|
27
|
+
ans = []
|
28
|
+
rio('d0').files.each { |f|
|
29
|
+
ans << f
|
30
|
+
}
|
31
|
+
assert_equal(['d0/f2','d0/f3'],smap(ans))
|
32
|
+
end
|
33
|
+
def test_files_method_with_dir_rio_each_skip
|
34
|
+
#$trace_states = true
|
35
|
+
ans = []
|
36
|
+
rio('d0').skip('f*').files.each { |f|
|
37
|
+
ans << f
|
38
|
+
}
|
39
|
+
assert(ans.empty?)
|
40
|
+
end
|
41
|
+
def test_files_method_with_file_rio_each_skip
|
42
|
+
#$trace_states = true
|
43
|
+
ans = []
|
44
|
+
rio('f0').skip('f*').files.each { |f|
|
45
|
+
ans << f
|
46
|
+
}
|
47
|
+
assert(ans.empty?)
|
48
|
+
end
|
49
|
+
def test_files_method_with_file_rio_each
|
50
|
+
#$trace_states = true
|
51
|
+
ans = []
|
52
|
+
rio('f0').files.each { |f|
|
53
|
+
ans << f
|
54
|
+
}
|
55
|
+
assert_equal(['f0'],smap(ans))
|
56
|
+
end
|
57
|
+
def test_files_and_lines_with_file_rio_each
|
58
|
+
#$trace_states = true
|
59
|
+
ans = []
|
60
|
+
rio('f0').files.lines.each { |f|
|
61
|
+
ans << f
|
62
|
+
}
|
63
|
+
assert_equal(["f0:L0\n"],smap(ans))
|
64
|
+
end
|
65
|
+
def test_files_method_with_file_rio_to_a
|
66
|
+
#$trace_states = true
|
67
|
+
ans = rio('f0').files.to_a
|
68
|
+
assert_equal(['f0'],smap(ans))
|
69
|
+
end
|
70
|
+
def test_files_method_with_file_rio_ss
|
71
|
+
#$trace_states = true
|
72
|
+
ans = rio('f0').files[]
|
73
|
+
assert_equal(['f0'],smap(ans))
|
74
|
+
end
|
75
|
+
def test_files_method_with_file_rio_ss_skip
|
76
|
+
#$trace_states = true
|
77
|
+
ans = rio('f0').skip('f*').files[]
|
78
|
+
assert_equal([],smap(ans))
|
79
|
+
end
|
80
|
+
def test_files_method_with_file_rio_ss_args_select
|
81
|
+
#$trace_states = true
|
82
|
+
ans = rio('f0').files['f*']
|
83
|
+
assert_equal(['f0'],smap(ans))
|
84
|
+
end
|
85
|
+
def test_files_method_with_file_rio_ss_args_dontselect
|
86
|
+
#$trace_states = true
|
87
|
+
ans = rio('f0').files['g*']
|
88
|
+
assert_equal([],smap(ans))
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
data/test/tc/get.rb
CHANGED
@@ -86,7 +86,7 @@ class TC_get < Test::RIO::TestCase
|
|
86
86
|
assert_equal(expa+expa,ans)
|
87
87
|
end
|
88
88
|
|
89
|
-
# assure get
|
89
|
+
# assure get does not return nil once after iteration using #each (with auto close)
|
90
90
|
begin
|
91
91
|
f = rio('f.txt')
|
92
92
|
ans = []
|
@@ -96,8 +96,8 @@ class TC_get < Test::RIO::TestCase
|
|
96
96
|
end
|
97
97
|
assert_equal(expa,ans)
|
98
98
|
|
99
|
-
rec = f.get
|
100
|
-
assert_nil(rec)
|
99
|
+
#rec = f.get
|
100
|
+
#assert_nil(rec)
|
101
101
|
|
102
102
|
rec = f.get
|
103
103
|
assert_equal(expa[0],rec)
|
@@ -114,7 +114,7 @@ class TC_get < Test::RIO::TestCase
|
|
114
114
|
ans << rec
|
115
115
|
end
|
116
116
|
rec = f.get
|
117
|
-
|
117
|
+
assert_equal(expa[0],rec)
|
118
118
|
end
|
119
119
|
|
120
120
|
begin
|
@@ -137,15 +137,16 @@ class TC_get < Test::RIO::TestCase
|
|
137
137
|
begin
|
138
138
|
f = rio('f.txt')
|
139
139
|
ans = []
|
140
|
-
|
140
|
+
# read all the lines
|
141
141
|
(0...n_lines).each do |n|
|
142
142
|
rec = f.get
|
143
143
|
assert_equal(expa[n],rec)
|
144
144
|
end
|
145
|
+
assert(f.eof?)
|
145
146
|
f.each do |rec|
|
146
147
|
ans << rec
|
147
148
|
end
|
148
|
-
assert_equal(
|
149
|
+
assert_equal([],ans)
|
149
150
|
end
|
150
151
|
end
|
151
152
|
end
|
data/test/tc/getrec.rb
CHANGED
@@ -85,9 +85,6 @@ class TC_RIO_getrec < Test::Unit::TestCase
|
|
85
85
|
end
|
86
86
|
assert_equal(expa,ans)
|
87
87
|
|
88
|
-
rec = f.getrec
|
89
|
-
assert_nil(rec)
|
90
|
-
|
91
88
|
rec = f.getrec
|
92
89
|
assert_equal(expa[0],rec)
|
93
90
|
end
|
@@ -103,7 +100,7 @@ class TC_RIO_getrec < Test::Unit::TestCase
|
|
103
100
|
ans << rec
|
104
101
|
end
|
105
102
|
rec = f.getrec
|
106
|
-
|
103
|
+
assert_equal(expa[0],rec)
|
107
104
|
end
|
108
105
|
|
109
106
|
begin
|
@@ -134,7 +131,7 @@ class TC_RIO_getrec < Test::Unit::TestCase
|
|
134
131
|
f.each do |rec|
|
135
132
|
ans << rec
|
136
133
|
end
|
137
|
-
assert_equal(
|
134
|
+
assert_equal([],ans)
|
138
135
|
end
|
139
136
|
end
|
140
137
|
end
|
data/test/tc/gzip.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
if $0 == __FILE__
|
3
|
+
Dir.chdir File.dirname(__FILE__)+'/../'
|
4
|
+
$:.unshift File.expand_path('../lib/')
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rio'
|
8
|
+
require 'tc/testcase'
|
9
|
+
|
10
|
+
class TC_gzip < Test::RIO::TestCase
|
11
|
+
@@once = false
|
12
|
+
def self.once
|
13
|
+
@@once = true
|
14
|
+
end
|
15
|
+
def setup()
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_string
|
20
|
+
plain_string = "Hello World\n"
|
21
|
+
|
22
|
+
gzip_string = ""
|
23
|
+
ans_string = ""
|
24
|
+
rio(?",plain_string) > rio(?",gzip_string).gzip
|
25
|
+
rio(?",gzip_string).gzip > rio(?",ans_string)
|
26
|
+
assert_equal(plain_string,ans_string)
|
27
|
+
|
28
|
+
gzip_string = ""
|
29
|
+
ans_string = ""
|
30
|
+
rio(?",gzip_string).gzip < rio(?",plain_string)
|
31
|
+
rio(?",ans_string) < rio(?",gzip_string).gzip
|
32
|
+
assert_equal(plain_string,ans_string)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_string2
|
37
|
+
str = "Hello World\n"
|
38
|
+
src = rio(?").print!(str)
|
39
|
+
ans = rio(?")
|
40
|
+
|
41
|
+
ans.string = ""
|
42
|
+
rio(?").gzip < src > ans
|
43
|
+
assert_equal(str,ans.string)
|
44
|
+
|
45
|
+
ans.string = ""
|
46
|
+
src | rio(?").gzip | ans
|
47
|
+
assert_equal(str,ans.string)
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_file
|
52
|
+
str = "Hello World\n"
|
53
|
+
rio('src').print!(str)
|
54
|
+
|
55
|
+
rio('src.gz').delete!
|
56
|
+
rio('ans').delete!
|
57
|
+
rio('src') > rio('src.gz').gzip
|
58
|
+
rio('src.gz').gzip > rio('ans')
|
59
|
+
assert_equal(str,rio('ans').contents)
|
60
|
+
|
61
|
+
rio('src.gz').delete!
|
62
|
+
rio('ans').delete!
|
63
|
+
rio('src.gz').gzip < rio('src')
|
64
|
+
rio('ans') < rio('src.gz').gzip
|
65
|
+
assert_equal(str,rio('ans').contents)
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_tempfile
|
70
|
+
str = "Hello World\n"
|
71
|
+
src = rio(?").print!(str)
|
72
|
+
ans = rio(?")
|
73
|
+
|
74
|
+
tmp = rio(??).gzip
|
75
|
+
tmp < src
|
76
|
+
assert_equal(str,tmp.rewind.contents)
|
77
|
+
tmp.rewind > ans
|
78
|
+
assert_equal(str,ans.contents)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
if $0 == __FILE__
|
3
|
+
Dir.chdir File.dirname(__FILE__)+'/../'
|
4
|
+
$:.unshift File.expand_path('../lib/')
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rio'
|
8
|
+
require 'tc/testcase'
|
9
|
+
|
10
|
+
class TC_io_each_byte < Test::RIO::TestCase
|
11
|
+
@@once = false
|
12
|
+
DATA = "012"
|
13
|
+
FN_RUBY = 'fruby.txt'
|
14
|
+
FN_RIO = 'frio.txt'
|
15
|
+
def self.once
|
16
|
+
@@once = true
|
17
|
+
rio(FN_RUBY) < DATA
|
18
|
+
rio(FN_RIO) < DATA
|
19
|
+
end
|
20
|
+
def setup
|
21
|
+
super
|
22
|
+
self.class.once unless @@once
|
23
|
+
end
|
24
|
+
def open_io(&block)
|
25
|
+
begin
|
26
|
+
fruby = ::File.open(FN_RUBY)
|
27
|
+
frio = rio(FN_RIO)
|
28
|
+
yield(fruby,frio)
|
29
|
+
ensure
|
30
|
+
fruby.close
|
31
|
+
frio.close
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def check_method(fruby,frio,n,sym,*args)
|
36
|
+
n.times {
|
37
|
+
assert_equal(fruby.__send__(sym,*args),frio.__send__(sym,*args))
|
38
|
+
assert_equal(fruby.eof?,frio.eof?)
|
39
|
+
}
|
40
|
+
end
|
41
|
+
def check_calls(fruby,frio,n,*args)
|
42
|
+
check_method(fruby,frio,n,:read,*args)
|
43
|
+
end
|
44
|
+
def check_iter(fruby,frio,sym,*args)
|
45
|
+
ans_ruby = []
|
46
|
+
ans_rio = []
|
47
|
+
fruby.__send__(sym,*args) { |el|
|
48
|
+
ans_ruby << el
|
49
|
+
}
|
50
|
+
frio.__send__(sym,*args) { |el|
|
51
|
+
ans_rio << el
|
52
|
+
}
|
53
|
+
assert_equal(ans_ruby,ans_rio)
|
54
|
+
end
|
55
|
+
def test_basic
|
56
|
+
open_io { |fruby,frio|
|
57
|
+
check_iter(fruby,frio,:each_byte)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
data/test/tc/io_read.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
if $0 == __FILE__
|
3
|
+
Dir.chdir File.dirname(__FILE__)+'/../'
|
4
|
+
$:.unshift File.expand_path('../lib/')
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rio'
|
8
|
+
require 'tc/testcase'
|
9
|
+
|
10
|
+
class TC_io_read < Test::RIO::TestCase
|
11
|
+
@@once = false
|
12
|
+
DATA = "012345"
|
13
|
+
FN_RUBY = 'fruby.txt'
|
14
|
+
FN_RIO = 'frio.txt'
|
15
|
+
def self.once
|
16
|
+
@@once = true
|
17
|
+
rio(FN_RUBY) < DATA
|
18
|
+
rio(FN_RIO) < DATA
|
19
|
+
end
|
20
|
+
def setup
|
21
|
+
super
|
22
|
+
self.class.once unless @@once
|
23
|
+
end
|
24
|
+
def open_io(&block)
|
25
|
+
begin
|
26
|
+
fruby = ::File.open(FN_RUBY)
|
27
|
+
frio = rio(FN_RIO)
|
28
|
+
yield(fruby,frio)
|
29
|
+
ensure
|
30
|
+
fruby.close
|
31
|
+
frio.close
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def check_method(fruby,frio,n,sym,*args)
|
36
|
+
n.times {
|
37
|
+
assert_equal(fruby.__send__(sym,*args),frio.__send__(sym,*args))
|
38
|
+
assert_equal(fruby.eof?,frio.eof?)
|
39
|
+
}
|
40
|
+
end
|
41
|
+
def check_calls(fruby,frio,n,*args)
|
42
|
+
check_method(fruby,frio,n,:read,*args)
|
43
|
+
end
|
44
|
+
def test_positive_integer
|
45
|
+
open_io { |fruby,frio|
|
46
|
+
check_calls(fruby,frio,3,3)
|
47
|
+
}
|
48
|
+
open_io { |fruby,frio|
|
49
|
+
check_calls(fruby,frio,2,4)
|
50
|
+
}
|
51
|
+
open_io { |fruby,frio|
|
52
|
+
check_calls(fruby,frio,2,7)
|
53
|
+
}
|
54
|
+
end
|
55
|
+
def test_positive_integer_buffer
|
56
|
+
open_io { |fruby,frio|
|
57
|
+
buffer = ""
|
58
|
+
check_calls(fruby,frio,1,3,buffer)
|
59
|
+
assert_equal(DATA[0...3],buffer)
|
60
|
+
check_calls(fruby,frio,1,3,buffer)
|
61
|
+
assert_equal(DATA[3...6],buffer)
|
62
|
+
}
|
63
|
+
open_io { |fruby,frio|
|
64
|
+
check_calls(fruby,frio,2,4)
|
65
|
+
}
|
66
|
+
open_io { |fruby,frio|
|
67
|
+
check_calls(fruby,frio,2,7)
|
68
|
+
}
|
69
|
+
end
|
70
|
+
def test_nil
|
71
|
+
open_io { |fruby,frio|
|
72
|
+
check_calls(fruby,frio,2,nil)
|
73
|
+
}
|
74
|
+
end
|
75
|
+
def test_noarg
|
76
|
+
open_io { |fruby,frio|
|
77
|
+
check_calls(fruby,frio,2)
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
data/test/tc/iometh.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
if $0 == __FILE__
|
3
|
+
Dir.chdir File.dirname(__FILE__)+'/../'
|
4
|
+
$:.unshift File.expand_path('../lib/')
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rio'
|
8
|
+
require 'tc/testcase'
|
9
|
+
|
10
|
+
class TC_iometh < Test::RIO::TestCase
|
11
|
+
@@once = false
|
12
|
+
def self.once
|
13
|
+
@@once = true
|
14
|
+
end
|
15
|
+
def setup
|
16
|
+
super
|
17
|
+
self.class.once unless @@once
|
18
|
+
end
|
19
|
+
def test_file
|
20
|
+
(0..4).each do |n_lines|
|
21
|
+
get_each(n_lines)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
def get_each(n_lines)
|
25
|
+
f = rio('f.txt')
|
26
|
+
expa = (0..n_lines-1).map { |a| "Line#{a}\n" }
|
27
|
+
f < expa
|
28
|
+
|
29
|
+
f = rio('f.txt')
|
30
|
+
assert_equal(expa,f[])
|
31
|
+
# $trace_states = true
|
32
|
+
|
33
|
+
# iterate twice using #get (no auto close)
|
34
|
+
begin
|
35
|
+
f = rio('f.txt').nocloseoneof
|
36
|
+
ans = []
|
37
|
+
while rec = f.get
|
38
|
+
ans << rec
|
39
|
+
end
|
40
|
+
assert_equal(expa,ans)
|
41
|
+
while rec = f.get
|
42
|
+
ans << rec
|
43
|
+
end
|
44
|
+
assert_equal(expa,ans)
|
45
|
+
end
|
46
|
+
|
47
|
+
# iterate using #get then using #each (no auto close)
|
48
|
+
begin
|
49
|
+
f = rio('f.txt').nocloseoneof
|
50
|
+
ans = []
|
51
|
+
while rec = f.get
|
52
|
+
ans << rec
|
53
|
+
end
|
54
|
+
assert_equal(expa,ans)
|
55
|
+
f.each do |rec|
|
56
|
+
ans << rec
|
57
|
+
end
|
58
|
+
assert_equal(expa,ans)
|
59
|
+
end
|
60
|
+
|
61
|
+
# iterate using #each then using #get (no auto close)
|
62
|
+
begin
|
63
|
+
f = rio('f.txt').nocloseoneof
|
64
|
+
ans = []
|
65
|
+
f.each do |rec|
|
66
|
+
ans << rec
|
67
|
+
end
|
68
|
+
assert_equal(expa,ans)
|
69
|
+
while rec = f.get
|
70
|
+
ans << rec
|
71
|
+
end
|
72
|
+
assert_equal(expa,ans)
|
73
|
+
end
|
74
|
+
|
75
|
+
# iterate twice using #get (with auto close)
|
76
|
+
begin
|
77
|
+
f = rio('f.txt')
|
78
|
+
ans = []
|
79
|
+
while rec = f.get
|
80
|
+
ans << rec
|
81
|
+
end
|
82
|
+
assert_equal(expa,ans)
|
83
|
+
while rec = f.get
|
84
|
+
ans << rec
|
85
|
+
end
|
86
|
+
assert_equal(expa+expa,ans)
|
87
|
+
end
|
88
|
+
|
89
|
+
# assure get returns nil once after iteration using #get (with auto close)
|
90
|
+
begin
|
91
|
+
f = rio('f.txt')
|
92
|
+
ans = []
|
93
|
+
|
94
|
+
f.each do |rec|
|
95
|
+
ans << rec
|
96
|
+
end
|
97
|
+
assert_equal(expa,ans)
|
98
|
+
|
99
|
+
rec = f.get
|
100
|
+
assert_equal(expa[0],rec)
|
101
|
+
end
|
102
|
+
|
103
|
+
begin
|
104
|
+
f = rio('f.txt')
|
105
|
+
ans = []
|
106
|
+
|
107
|
+
rec = f.get
|
108
|
+
assert_equal(expa[0],rec)
|
109
|
+
ans << rec unless rec.nil?
|
110
|
+
f.each do |rec|
|
111
|
+
ans << rec
|
112
|
+
end
|
113
|
+
rec = f.get
|
114
|
+
assert_equal(expa[0],rec)
|
115
|
+
end
|
116
|
+
|
117
|
+
begin
|
118
|
+
f = rio('f.txt')
|
119
|
+
ans = []
|
120
|
+
|
121
|
+
(0...n_lines).each do |n|
|
122
|
+
rec = f.get
|
123
|
+
assert_equal(expa[n],rec)
|
124
|
+
end
|
125
|
+
rec = f.get
|
126
|
+
assert_nil(rec)
|
127
|
+
|
128
|
+
f.each do |rec|
|
129
|
+
ans << rec
|
130
|
+
end
|
131
|
+
assert_equal(expa,ans)
|
132
|
+
end
|
133
|
+
|
134
|
+
begin
|
135
|
+
f = rio('f.txt')
|
136
|
+
ans = []
|
137
|
+
|
138
|
+
(0...n_lines).each do |n|
|
139
|
+
rec = f.get
|
140
|
+
assert_equal(expa[n],rec)
|
141
|
+
end
|
142
|
+
assert(f.eof?)
|
143
|
+
f.each do |rec|
|
144
|
+
ans << rec
|
145
|
+
end
|
146
|
+
assert_equal([],ans)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|