rio 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) hide show
  1. data/README +18 -12
  2. data/Rakefile +57 -87
  3. data/build_doc.rb +19 -17
  4. data/doc/ANNOUNCE +3 -32
  5. data/doc/RELEASE_NOTES +4 -5
  6. data/doc/RIOIS +215 -0
  7. data/doc/generators/template/html/rio.css +428 -0
  8. data/doc/generators/template/html/rio.rb +18 -389
  9. data/doc/generators/template/html/ugly.rb +130 -0
  10. data/doc/pkg_def.rb +66 -0
  11. data/ex/catcsv.rb +64 -0
  12. data/ex/colx.rb +8 -0
  13. data/ex/findinruby +15 -0
  14. data/ex/findruby +14 -0
  15. data/ex/passwd_report.rb +8 -0
  16. data/ex/prompt.rb +25 -0
  17. data/ex/rgb.txt.gz +0 -0
  18. data/ex/riocat +42 -0
  19. data/ex/riogunzip +31 -0
  20. data/ex/riogzip +24 -0
  21. data/ex/rioprompt.rb +10 -0
  22. data/ex/targz2zip +17 -0
  23. data/ex/tonl +10 -0
  24. data/lib/rio.rb +16 -10
  25. data/lib/rio/abstract_method.rb +3 -4
  26. data/lib/rio/argv.rb +3 -4
  27. data/lib/rio/arycopy.rb +3 -4
  28. data/lib/rio/assert.rb +3 -4
  29. data/lib/rio/base.rb +3 -4
  30. data/lib/rio/callstr.rb +3 -4
  31. data/lib/rio/const.rb +3 -4
  32. data/lib/rio/construct.rb +3 -4
  33. data/lib/rio/constructor.rb +12 -8
  34. data/lib/rio/context.rb +15 -30
  35. data/lib/rio/context/autoclose.rb +3 -4
  36. data/lib/rio/context/copying.rb +3 -4
  37. data/lib/rio/context/cxx.rb +3 -4
  38. data/lib/rio/context/dir.rb +3 -4
  39. data/lib/rio/context/gzip.rb +3 -4
  40. data/lib/rio/context/methods.rb +16 -5
  41. data/lib/rio/context/skip.rb +3 -4
  42. data/lib/rio/context/stream.rb +42 -5
  43. data/lib/rio/cp.rb +7 -7
  44. data/lib/rio/def.rb +3 -4
  45. data/lib/rio/dir.rb +3 -4
  46. data/lib/rio/doc.rb +4 -5
  47. data/lib/rio/doc/EXAMPLES.rb +299 -0
  48. data/lib/rio/doc/HOWTO.rb +3 -4
  49. data/lib/rio/doc/INTRO.rb +86 -105
  50. data/lib/rio/doc/OPTIONAL.rb +4 -5
  51. data/lib/rio/doc/SYNOPSIS.rb +7 -6
  52. data/lib/rio/entrysel.rb +21 -23
  53. data/lib/rio/exception.rb +3 -4
  54. data/lib/rio/exception/copy.rb +3 -4
  55. data/lib/rio/exception/notimplemented.rb +57 -0
  56. data/lib/rio/exception/notsupported.rb +3 -4
  57. data/lib/rio/exception/open.rb +3 -4
  58. data/lib/rio/exception/state.rb +3 -4
  59. data/lib/rio/ext.rb +47 -13
  60. data/lib/rio/ext/csv.rb +4 -5
  61. data/lib/rio/ext/if.rb +45 -0
  62. data/lib/rio/ext/mp3info.rb +80 -0
  63. data/lib/rio/ext/splitlines.rb +253 -0
  64. data/lib/rio/ext/yaml.rb +9 -5
  65. data/lib/rio/ext/yaml/doc.rb +133 -0
  66. data/lib/rio/ext/yaml/tie.rb +149 -0
  67. data/lib/rio/ext/zipfile.rb +23 -4
  68. data/lib/rio/ext/zipfile/fs.rb +116 -0
  69. data/lib/rio/ext/zipfile/rl.rb +251 -0
  70. data/lib/rio/ext/zipfile/rootdir.rb +117 -0
  71. data/lib/rio/ext/zipfile/state.rb +161 -0
  72. data/lib/rio/ext/zipfile/wrap.rb +204 -0
  73. data/lib/rio/factory.rb +235 -27
  74. data/lib/rio/file.rb +4 -4
  75. data/lib/rio/filter.rb +3 -4
  76. data/lib/rio/filter/closeoneof.rb +3 -4
  77. data/lib/rio/filter/gzip.rb +9 -4
  78. data/lib/rio/fs/base.rb +3 -4
  79. data/lib/rio/fs/impl.rb +4 -5
  80. data/lib/rio/fs/native.rb +3 -4
  81. data/lib/rio/fs/stream.rb +3 -4
  82. data/lib/rio/fs/url.rb +3 -4
  83. data/lib/rio/ftp/conncache.rb +19 -5
  84. data/lib/rio/ftp/dir.rb +3 -4
  85. data/lib/rio/ftp/fs.rb +30 -24
  86. data/lib/rio/grande.rb +27 -7
  87. data/lib/rio/handle.rb +3 -4
  88. data/lib/rio/if.rb +19 -15
  89. data/lib/rio/if/basic.rb +7 -7
  90. data/lib/rio/if/csv.rb +5 -6
  91. data/lib/rio/if/dir.rb +120 -114
  92. data/lib/rio/if/file.rb +52 -44
  93. data/lib/rio/if/fileordir.rb +217 -211
  94. data/lib/rio/if/grande.rb +674 -644
  95. data/lib/rio/if/grande_entry.rb +321 -313
  96. data/lib/rio/if/grande_stream.rb +653 -553
  97. data/lib/rio/if/internal.rb +3 -4
  98. data/lib/rio/if/path.rb +425 -426
  99. data/lib/rio/if/rubyio.rb +681 -0
  100. data/lib/rio/if/string.rb +42 -5
  101. data/lib/rio/if/temp.rb +3 -4
  102. data/lib/rio/if/test.rb +245 -238
  103. data/lib/rio/if/yaml.rb +15 -41
  104. data/lib/rio/ioh.rb +7 -5
  105. data/lib/rio/iomode.rb +19 -7
  106. data/lib/rio/ios/fail.rb +4 -5
  107. data/lib/rio/ios/generic.rb +4 -5
  108. data/lib/rio/ios/mode.rb +4 -5
  109. data/lib/rio/ios/null.rb +6 -7
  110. data/lib/rio/iowrap.rb +3 -4
  111. data/lib/rio/kernel.rb +3 -5
  112. data/lib/rio/local.rb +3 -4
  113. data/lib/rio/match.rb +3 -4
  114. data/lib/rio/matchrecord.rb +3 -4
  115. data/lib/rio/no_warn.rb +3 -4
  116. data/lib/rio/nullio.rb +3 -4
  117. data/lib/rio/open3.rb +4 -5
  118. data/lib/rio/ops/construct.rb +3 -4
  119. data/lib/rio/ops/create.rb +11 -6
  120. data/lib/rio/ops/dir.rb +19 -8
  121. data/lib/rio/ops/either.rb +6 -5
  122. data/lib/rio/ops/file.rb +3 -4
  123. data/lib/rio/ops/path.rb +14 -35
  124. data/lib/rio/ops/stream.rb +3 -4
  125. data/lib/rio/ops/stream/input.rb +4 -7
  126. data/lib/rio/ops/stream/output.rb +3 -4
  127. data/lib/rio/ops/stream/read.rb +6 -5
  128. data/lib/rio/ops/stream/write.rb +3 -4
  129. data/lib/rio/ops/symlink.rb +3 -4
  130. data/lib/rio/path.rb +22 -18
  131. data/lib/rio/path/reset.rb +4 -5
  132. data/lib/rio/piper.rb +3 -4
  133. data/lib/rio/piper/cp.rb +3 -4
  134. data/lib/rio/prompt.rb +10 -5
  135. data/lib/rio/rectype.rb +5 -5
  136. data/lib/rio/rl/base.rb +17 -71
  137. data/lib/rio/rl/builder.rb +14 -38
  138. data/lib/rio/rl/chmap.rb +66 -0
  139. data/lib/rio/rl/fs2url.rb +82 -0
  140. data/lib/rio/rl/ioi.rb +4 -4
  141. data/lib/rio/rl/path.rb +44 -122
  142. data/lib/rio/rl/pathmethods.rb +19 -8
  143. data/lib/rio/rl/uri.rb +137 -60
  144. data/lib/rio/rl/withpath.rb +295 -0
  145. data/lib/rio/scheme/aryio.rb +3 -4
  146. data/lib/rio/scheme/cmdio.rb +3 -4
  147. data/lib/rio/scheme/cmdpipe.rb +4 -4
  148. data/lib/rio/scheme/fd.rb +3 -4
  149. data/lib/rio/scheme/ftp.rb +7 -7
  150. data/lib/rio/scheme/http.rb +4 -5
  151. data/lib/rio/scheme/null.rb +3 -4
  152. data/lib/rio/scheme/path.rb +3 -4
  153. data/lib/rio/scheme/stderr.rb +3 -4
  154. data/lib/rio/scheme/stdio.rb +3 -4
  155. data/lib/rio/scheme/strio.rb +3 -4
  156. data/lib/rio/scheme/sysio.rb +3 -4
  157. data/lib/rio/scheme/tcp.rb +3 -4
  158. data/lib/rio/scheme/temp.rb +6 -6
  159. data/lib/rio/state.rb +18 -46
  160. data/lib/rio/state/error.rb +3 -4
  161. data/lib/rio/stream.rb +4 -4
  162. data/lib/rio/stream/base.rb +3 -4
  163. data/lib/rio/stream/duplex.rb +3 -4
  164. data/lib/rio/stream/open.rb +3 -8
  165. data/lib/rio/symantics.rb +3 -4
  166. data/lib/rio/tempdir.rb +2 -2
  167. data/lib/rio/to_rio.rb +3 -4
  168. data/lib/rio/to_rio/all.rb +3 -4
  169. data/lib/rio/to_rio/array.rb +4 -5
  170. data/lib/rio/to_rio/io.rb +4 -5
  171. data/lib/rio/to_rio/object.rb +4 -5
  172. data/lib/rio/to_rio/string.rb +4 -5
  173. data/lib/rio/uri/file.rb +41 -5
  174. data/lib/rio/util.rb +3 -4
  175. data/lib/rio/version.rb +4 -5
  176. data/setup.rb +368 -339
  177. data/test/bin/list_dir.rb +1 -1
  178. data/test/ftp/anon_misc.rb +13 -1
  179. data/test/ftp/anon_special.rb +6 -6
  180. data/test/ftp/anon_write.rb +10 -3
  181. data/test/ftp/ftp2ftp.rb +2 -2
  182. data/test/ftp/testdef.rb +9 -6
  183. data/test/http/all.rb +3 -0
  184. data/test/http/copy-from-http.rb +140 -0
  185. data/test/lib/temp_server.rb +44 -0
  186. data/test/runalltests.rb +3 -1
  187. data/test/runhttp.rb +12 -0
  188. data/test/runhttptests.rb +1 -1
  189. data/test/runtests.rb +41 -3
  190. data/test/tc/abs.rb +9 -5
  191. data/test/tc/all.rb +9 -4
  192. data/test/tc/base.rb +1 -1
  193. data/test/tc/base2.rb +87 -0
  194. data/test/tc/{methods.rb → clone.rb} +72 -50
  195. data/test/tc/closeoncopy.rb +13 -2
  196. data/test/tc/copy-dir-samevar.rb +91 -0
  197. data/test/tc/dir_iter.rb +0 -1
  198. data/test/tc/empty.rb +6 -2
  199. data/test/tc/expand_path.rb +36 -54
  200. data/test/tc/ext.rb +42 -18
  201. data/test/tc/gzip.rb +30 -3
  202. data/test/tc/likeio.rb +5 -1
  203. data/test/tc/line_record_row.rb +51 -0
  204. data/test/tc/noqae.rb +71 -70
  205. data/test/tc/path_parts.rb +175 -0
  206. data/test/tc/programs_util.rb +3 -3
  207. data/test/tc/rename.rb +4 -5
  208. data/test/tc/riorl.rb +9 -7
  209. data/test/tc/skip.rb +35 -6
  210. data/test/tc/skiplines.rb +34 -5
  211. data/test/tc/split.rb +8 -50
  212. data/test/tc/splitlines.rb +65 -0
  213. data/test/tc/splitpath.rb +83 -0
  214. data/test/tc/testcase.rb +1 -1
  215. data/test/tc/truncate.rb +39 -0
  216. data/test/tc/yaml.rb +9 -8
  217. metadata +261 -207
  218. data/ChangeLog +0 -1418
  219. data/VERSION +0 -1
  220. data/lib/rio/doc/MISC.rb +0 -259
  221. data/lib/rio/if/stream.rb +0 -680
  222. data/lib/rio/impl/path.rb +0 -87
  223. data/test/tc/copy-from-http.rb +0 -89
@@ -0,0 +1,175 @@
1
+ #!/usr/local/bin/ruby
2
+ if $0 == __FILE__
3
+ Dir.chdir File.dirname(__FILE__)+'/../'
4
+ $:.unshift File.expand_path('../lib/')
5
+ end
6
+ require 'rio'
7
+ require 'tc/testcase'
8
+ require 'pp'
9
+
10
+ class PathGenerator
11
+ ROOTS = ['r1','r 1']
12
+ DIRS = ['d1','d 1']
13
+ FILES = ['f1','f 1','f1.txt','f 1.txt']
14
+ UROOTS = ROOTS.map{|z| z.gsub(/ /,'%20')}
15
+ UDIRS = DIRS.map{|z| z.gsub(/ /,'%20')}
16
+ UFILES = FILES.map{|z| z.gsub(/ /,'%20')}
17
+
18
+ attr_reader :fs_basic_paths,:fs_url_paths,:fs_drive_paths,
19
+ :fs_unc_paths,:fs_paths,:http_paths,:ftp_paths, :uri_paths,:all_paths
20
+
21
+ def initialize()
22
+ @fs_basic_paths = self.class.fs_basic_paths()
23
+ @fs_url_paths = self.class.fs_url_paths()
24
+ @fs_drive_paths = self.class.fs_drive_paths()
25
+ @fs_unc_paths = self.class.fs_unc_paths()
26
+ @fs_paths = @fs_basic_paths + @fs_url_paths + @fs_drive_paths + @fs_unc_paths
27
+ @http_paths = self.class.http_paths()
28
+ @ftp_paths = self.class.ftp_paths()
29
+ @uri_paths = @http_paths + @ftp_paths
30
+
31
+ @all_paths = @fs_paths + @uri_paths
32
+ end
33
+ def self.fs_basic_paths()
34
+ tops = %w{/}
35
+ build_paths(tops,ROOTS,DIRS,FILES)
36
+ end
37
+ def self.fs_url_paths()
38
+ #tops = %w{file:/// file:///x:/ file://h/}
39
+ # tops = %w{file:/// file:///x:/ file://h/}
40
+ tops = %w{file:/// file://h/}
41
+ tops << 'file:///x:/' if $mswin32
42
+ build_paths(tops,ROOTS,DIRS,FILES)
43
+ end
44
+ def self.fs_drive_paths()
45
+ return [] unless $mswin32
46
+ tops = %w{x:/}
47
+ build_paths(tops,ROOTS,DIRS,FILES)
48
+ end
49
+ def self.fs_unc_paths()
50
+ tops = %w{//h/}
51
+ build_paths(tops,ROOTS,DIRS,FILES)
52
+ end
53
+ def self.http_paths()
54
+ htops = %w{http://h/}
55
+ build_paths(htops,UROOTS,UDIRS,UFILES)
56
+ end
57
+ def self.ftp_paths()
58
+ ftops = %w{ftp://h/}
59
+ build_paths(ftops,UROOTS,UDIRS,UFILES)
60
+ end
61
+ def self.build_paths(tops,roots,dirs,files)
62
+ paths = []
63
+ tops.each { |t|
64
+ paths << t
65
+ roots.each{|r| paths << t+r }
66
+ roots.map{|r| t + r + '/'}.each { |r|
67
+ paths << r
68
+ dirs.each{|d| paths << r+d}
69
+ dirs.map{|d| r+d+'/'}.each{|d|
70
+ paths << d
71
+ files.each{|f| paths << d+f}
72
+ files.map{|f| d+f}.each{|f|
73
+ paths << f
74
+ }
75
+ }
76
+ }
77
+ }
78
+ paths
79
+ end
80
+ end
81
+
82
+
83
+ class TC_path_parts < Test::RIO::TestCase
84
+ @@once = false
85
+ @@exp = nil
86
+ @@gen = PathGenerator.new
87
+
88
+ def self.once
89
+ @@once = true
90
+ expfile = RIO.cwd('../../tc/rlparts.ans.yml')
91
+ @@exp = expfile.yaml.get
92
+ end
93
+
94
+ def setup
95
+ super
96
+ self.class.once unless @@once
97
+ end
98
+
99
+ def run_path_tests_exp(paths,sym)
100
+ paths.each do |pstr|
101
+ #p pstr
102
+ r = rio(pstr)
103
+ assert_equal(@@exp[r.to_s][sym],r.__send__(sym).to_s,"rio('#{pstr}').#{sym} failed")
104
+ end
105
+ end
106
+ def run_path_tests_native(paths,sym,*args)
107
+ paths.each do |pstr|
108
+ r = rio(pstr)
109
+ exp = File.__send__(sym,pstr,*args)
110
+ ans = r.__send__(sym,*args).to_s
111
+ #puts "#{sym}[#{r}]: #{exp} <=> #{ans}"
112
+ assert_equal(exp,ans,"rio('#{pstr}').#{sym} failed")
113
+ end
114
+ end
115
+ def run_path_tests_native_fspath(paths,sym,*args)
116
+ paths.each do |pstr|
117
+ r = rio(pstr)
118
+ fpth = r.fspath
119
+ assert_equal(File.__send__(sym,fpth,*args),r.__send__(sym,*args).to_s,"rio('#{pstr}').#{sym} failed")
120
+ end
121
+ end
122
+ def test_filename()
123
+ @@gen.all_paths.each do |pstr|
124
+ assert_equal(rio(pstr).basename(''),rio(pstr).filename)
125
+ assert_equal(rio(pstr).noext.basename,rio(pstr).filename)
126
+ end
127
+ end
128
+ def test_uri_dirname
129
+ run_path_tests_exp(@@gen.uri_paths,:dirname)
130
+ end
131
+ def test_uri_basename
132
+ run_path_tests_exp(@@gen.uri_paths,:basename)
133
+ end
134
+
135
+ def test_fs_dirname
136
+ run_path_tests_native(@@gen.fs_basic_paths,:dirname)
137
+ run_path_tests_native(@@gen.fs_drive_paths,:dirname)
138
+ run_path_tests_exp(@@gen.fs_unc_paths,:dirname)
139
+ end
140
+ def test_fs_url_dirname
141
+ run_path_tests_exp(@@gen.fs_url_paths,:dirname)
142
+ end
143
+ def test_fs_url_basename
144
+ run_path_tests_native_fspath(@@gen.fs_url_paths,:basename,'')
145
+ run_path_tests_native_fspath(@@gen.fs_url_paths,:basename,'.txt')
146
+ end
147
+ def test_fs_basename
148
+ run_path_tests_native(@@gen.fs_basic_paths,:basename,'')
149
+ run_path_tests_native(@@gen.fs_drive_paths,:basename,'')
150
+ run_path_tests_native(@@gen.fs_unc_paths,:basename,'')
151
+ run_path_tests_native(@@gen.fs_basic_paths,:basename,'.txt')
152
+ run_path_tests_native(@@gen.fs_drive_paths,:basename,'.txt')
153
+ run_path_tests_native(@@gen.fs_unc_paths,:basename,'.txt')
154
+ end
155
+
156
+ def test_fs_path
157
+ run_path_tests_exp(@@gen.fs_paths,:path)
158
+ end
159
+ def test_uri_path
160
+ run_path_tests_exp(@@gen.uri_paths,:path)
161
+ end
162
+ def test_fs_fspath
163
+ run_path_tests_exp(@@gen.fs_paths,:fspath)
164
+ end
165
+ def test_uri_fspath
166
+ run_path_tests_exp(@@gen.uri_paths,:fspath)
167
+ end
168
+ def test_fs_urlpath
169
+ run_path_tests_exp(@@gen.fs_paths,:urlpath)
170
+ end
171
+ def test_uri_urlpath
172
+ run_path_tests_exp(@@gen.uri_paths,:urlpath)
173
+ end
174
+
175
+ end
@@ -15,9 +15,9 @@ module Test
15
15
  'list_dir' => "ruby #{TEST_BIN_DIR}/list_dir.rb",
16
16
  }
17
17
  PROG = {
18
- 'count_lines' => XPROGS['count_lines'],
19
- 'find_lines' => XPROGS['find_lines'],
20
- 'list_dir' => XPROGS['list_dir'],
18
+ 'count_lines' => ($mswin32 ? RPROGS['count_lines'] : XPROGS['count_lines']),
19
+ 'find_lines' => ($mswin32 ? RPROGS['find_lines'] : XPROGS['find_lines']),
20
+ 'list_dir' => ($mswin32 ? RPROGS['list_dir'] : XPROGS['list_dir']),
21
21
  }
22
22
  end
23
23
  end
@@ -33,10 +33,9 @@ class TC_rename < Test::RIO::TestCase
33
33
  def test_rename_filename
34
34
  indir = rio('tdir').delete!.mkpath < rio(@d[1]).to_a
35
35
  oldf = indir.files[].map { |f| f.to_s }
36
- expf = oldf.map { |f| f.sub(/f/,'q') + '.txt' }
37
-
36
+ expf = oldf.map { |f| f.sub(/f/,'q') }
38
37
  indir.rename.files do |ent|
39
- nname = ent.filename.to_s.sub(/f/,'q') + '.txt'
38
+ nname = ent.filename.to_s.sub(/f/,'q')
40
39
  ent.filename = nname
41
40
  end
42
41
  assert_array_equal(expf,rio('tdir').files[])
@@ -45,10 +44,10 @@ class TC_rename < Test::RIO::TestCase
45
44
  def test_rename_filename_sub
46
45
  indir = rio('tdir').delete!.mkpath < rio(@d[1]).to_a
47
46
  oldf = indir.files[].map { |f| f.to_s }
48
- expf = oldf.map { |f| f.sub(/f/,'q') + '.txt' }
47
+ expf = oldf.map { |f| f.sub(/f/,'q') }
49
48
 
50
49
  indir.rename.files do |ent|
51
- ent.filename = ent.filename.sub(/f/,'q') + '.txt'
50
+ ent.filename = ent.filename.sub(/f/,'q')
52
51
  end
53
52
  assert_array_equal(expf,rio('tdir').files[])
54
53
 
@@ -150,10 +150,12 @@ class TC_riorl < Test::RIO::TestCase
150
150
  end
151
151
 
152
152
  def mkrios_open()
153
+ require 'tempfile'
154
+ stdlib_temppath = ::Tempfile.new('rio').path
155
+ fnre = "#{@tmppath}(\\.)?\\d+\\.\\d+"
153
156
  rinfo = {
154
157
  ?- => ['stdout',/^$/,nil,nil,/^stdout:$/,/^stdout:$/],
155
- ?? => ['file',%r|//#{@tmppath}\d+\.\d+|,%r|#{@tmppath}\d+\.\d+|,%r|#{@tmppath}\d+\.\d+|,
156
- /#{@tmppath}\d+\.\d+/,/#{@tmppath}\d+\.\d+/],
158
+ ?? => ['file',%r|//#{fnre}|,%r|#{fnre}|,%r|#{fnre}|,/#{fnre}/,/#{fnre}/],
157
159
  }
158
160
  siopq = sprintf("0x%08x",$stdout.object_id)
159
161
  rios = {
@@ -169,11 +171,11 @@ class TC_riorl < Test::RIO::TestCase
169
171
  rios.each do |k,r|
170
172
  #pinfo(fmt,pathinfo(r))
171
173
  assert_equal(rinfo[k][0],r.scheme)
172
- assert(r.opaque =~ rinfo[k][1])
173
- assert(r.to_s =~ rinfo[k][4])
174
- assert(r.to_url =~ rinfo[k][5])
174
+ assert_match(rinfo[k][1],r.opaque)
175
+ assert_match(rinfo[k][4],r.to_s)
176
+ assert_match(rinfo[k][5],r.to_url)
175
177
  end
176
- assert(rinfo[??][2] =~ rios[??].path)
177
- assert(rinfo[??][3] =~ rios[??].fspath)
178
+ assert_match(rinfo[??][2],rios[??].path)
179
+ assert_match(rinfo[??][3],rios[??].fspath)
178
180
  end
179
181
  end
@@ -14,8 +14,8 @@ class TC_skip < Test::RIO::TestCase
14
14
  rio('d0').rmtree.mkpath.chdir {
15
15
  rio('f1') < (0..1).map { |i| "L#{i}:d0/f1\n" }
16
16
  rio('f2') < (0..1).map { |i| "L#{i}:d0/f2\n" }
17
- rio('g1') < (0..1).map { |i| "L#{i}:d0/g1\n" }
18
- rio('g2') < (0..1).map { |i| "L#{i}:d0/g2\n" }
17
+ rio('g1') < (0..20).map { |i| "L#{i}:d0/g1\n" }
18
+ rio('g2') < (0..20).map { |i| "L#{i}:d0/g2\n" }
19
19
  if $supports_symlink
20
20
  rio('x1').symlink('n1')
21
21
  rio('x2').symlink('n2')
@@ -30,28 +30,57 @@ class TC_skip < Test::RIO::TestCase
30
30
  super
31
31
  self.class.once unless @@once
32
32
  @d0 = rio('d0')
33
+ @g1 = @d0/'g1'
34
+ @g2 = @d0/'g2'
33
35
  end
34
36
 
35
- def test_prefix_files
37
+ def test_ent_prefix_files
36
38
  exprio = rio(@d0).skipfiles(/1/)
37
39
  ansrio = rio(@d0).skip.files(/1/)
38
40
  assert_equal(smap(exprio[]),smap(ansrio[]))
39
41
  end
40
- def test_prefix_dirs
42
+ def test_ent_prefix_dirs
41
43
  exprio = rio(@d0).skipdirs(/1/)
42
44
  ansrio = rio(@d0).skip.dirs(/1/)
43
45
  assert_equal(exprio[],ansrio[])
44
46
  end
45
- def test_prefix_entries
47
+ def test_ent_prefix_entries
46
48
  exprio = rio(@d0).skipentries(/1/)
47
49
  ansrio = rio(@d0).skip.entries(/1/)
48
50
  assert_equal(exprio[],ansrio[])
49
51
  end
50
- def test_prefix_alone
52
+ def test_ent_alone
51
53
  exprio = rio(@d0).skipentries(/1/)
52
54
  ansrio = rio(@d0).skip(/1/)
53
55
  assert_equal(exprio[],ansrio[])
54
56
  end
57
+ def test_ent_alone_a
58
+ exp = rio(@d0).skipentries[/1/]
59
+ ans = rio(@d0).skip[/1/]
60
+ assert_equal(exp,ans)
61
+ end
62
+ def test_ent_postfix_a
63
+ exp = rio(@d0).files(/1/).skipfiles[:symlink?]
64
+ ans = rio(@d0).files(/1/).skip[:symlink?]
65
+
66
+ assert_equal(exp,ans)
67
+ end
68
+ def test_rec_prefix_a
69
+ exp = rio(@g2).skiplines[/1/]
70
+ ans = rio(@g2).skip.lines[/1/]
71
+
72
+ assert_equal(exp,ans)
73
+ end
74
+ def test_rec_postfix_a
75
+ exp = rio(@g1).lines[/2/]
76
+ #p exp
77
+ exp = rio(@g1).records(/2/).skip[/L2/]
78
+ #p exp
79
+ # ans = rio(@g1).lines(/2/).skip[0..5]
80
+ # p ans
81
+
82
+ # assert_equal(exp,ans)
83
+ end
55
84
  def test_prefix_atend
56
85
  # exprio = rio(@d0).skipentries(/1/)
57
86
  ansrio = rio(@d0).skip[]
@@ -9,20 +9,49 @@ require 'tc/testcase'
9
9
 
10
10
  class TC_skiplines < Test::RIO::TestCase
11
11
  @@once = false
12
- N_LINES = 4
12
+ N_LINES = 25
13
13
  def self.once
14
14
  @@once = true
15
- rio('f1') < (0...N_LINES).map { |i| "L#{i}:f1\n" }
16
- rio('f2') < (0...N_LINES).map { |i| "L#{i}:f2\n" }
17
- rio('g1') < (0...N_LINES).map { |i| "L#{i}:g1\n" }
18
- rio('g2') < (0...N_LINES).map { |i| "L#{i}:g2\n" }
15
+ #rio('f1') < (0...N_LINES).map { |i| "L#{i}:f1" + $/ }
16
+ rio('f2') < (0...N_LINES).map { |i| "L#{i}:f2" + $/ }
17
+ #rio('g1') < (0...N_LINES).map { |i| "L#{i}:g1" + $/ }
18
+ #rio('g2') < (0...N_LINES).map { |i| "L#{i}:g2" + $/ }
19
19
  end
20
20
  def setup
21
21
  super
22
22
  self.class.once unless @@once
23
23
 
24
+ @lines = {}
25
+ #%w[f1 f2 g1 g2].each do |fname|
26
+ %w[f2].each do |fname|
27
+ @lines[fname] = rio(fname).to_a
28
+ end
24
29
  end
25
30
 
31
+ def test_basic
32
+ fname = 'f2'
33
+
34
+ re = /1/
35
+ exp = @lines[fname].reject{ |l| l =~ re }
36
+
37
+ ans = []
38
+ rio(fname).skiplines(re) { |l| ans << l }
39
+ assert_equal(exp,ans,"skiplines using #each with regular expression")
40
+ ans = rio(fname).skiplines[re]
41
+ assert_equal(exp,ans,"skiplines using array operator with regular expression")
42
+
43
+ rng = (2..9)
44
+
45
+ exp = @lines[fname][0..rng.first-1] + @lines[fname][rng.last+1...N_LINES]
46
+
47
+ ans = []
48
+ rio(fname).skiplines(rng) { |l| ans << l }
49
+ assert_equal(exp,ans,"skiplines using #each with line range")
50
+ ans = rio(fname).skiplines[rng]
51
+ assert_equal(exp,ans,"skiplines using array operator with line range")
52
+
53
+
54
+ end
26
55
  def test_prefix_lines
27
56
  # exprio = rio(@d0).skipfiles(/1/)
28
57
  # ansrio = rio(@d0).skip.files(/1/)
@@ -16,55 +16,13 @@ class TC_split < Test::RIO::TestCase
16
16
  super
17
17
  self.class.once unless @@once
18
18
  end
19
- def test_basic
20
- r = rio('b/c/d')
21
- ary = r.split
22
- assert_equal([rio('b'),rio('c'),rio('d')],ary)
23
- assert_equal(r,ary.to_rio)
24
- end
25
- def test_abs_ne
26
- r = rio('/a/b/c/d')
27
- ary = r.split
28
- assert_equal([rio('/'),rio('a'),rio('b'),rio('c'),rio('d')],ary)
29
- assert_equal(r,ary.to_rio)
30
- assert_equal(rio('d'),ary[-1])
31
- assert_equal(r,ary[-1].abs)
32
- end
33
-
34
- def test_abs_drive
35
- r = rio('q:/a/b')
36
- ary = r.split
37
- exp = [rio('q:/'),rio('a'),rio('b')]
38
- assert_equal(exp,ary)
39
- assert_equal(r,ary.to_rio)
40
- assert_equal(rio('b'),ary[-1])
41
- assert_equal(r,ary[-1].abs)
42
- end
43
- def test_abs_host
44
- r = rio('//ahost/a/b/c')
45
- ary = r.split
46
- exp = [rio('file://ahost/'),rio('a'),rio('b'),rio('c')]
47
- assert_equal(exp,ary)
48
- assert_equal(r,ary.to_rio)
49
- assert_equal(rio('c'),ary[-1])
50
- assert_equal(r,ary[-1].abs)
51
- end
52
- def test_abs_url
53
- r = rio('file://ahost/a/b/c')
54
- ary = r.split
55
- exp = [rio('file://ahost/'),rio('a'),rio('b'),rio('c')]
56
- assert_equal(exp,ary)
57
- assert_equal(r,ary.to_rio)
58
- assert_equal(rio('c'),ary[-1])
59
- assert_equal(r,ary[-1].abs)
60
- end
61
- def test_rel
62
- r = rio('a/b/c')
63
- ary = r.split
64
- exp = [rio('a'),rio('b'),rio('c')]
65
- assert_equal(exp,ary)
66
- assert_equal(r,ary.to_rio)
67
- assert_equal(rio('c'),ary[-1])
68
- assert_equal(r.abs,ary[-1].abs)
19
+ def test_type
20
+ rtn = rio('a/b/c').split
21
+ assert_kind_of(::Array,rtn)
22
+ for el in rtn
23
+ assert_kind_of(RIO::Rio,el)
24
+ end
25
+ rtn = rio('hw.txt')
26
+ assert_kind_of(RIO::Rio,rtn)
69
27
  end
70
28
  end
@@ -0,0 +1,65 @@
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_splitlines < 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
+ @str = "a,b,c,d\n"
19
+ @infile = rio('infile') < @str * 3
20
+ end
21
+ def test_get
22
+ ans = rio(@infile).split(',').get
23
+ exp = @str.split(',')
24
+ assert_equal(exp,ans)
25
+ ans = rio(@infile).chomp.split(',').get
26
+ exp = @str.chop
27
+ exp = exp.split(',')
28
+ assert(exp,ans)
29
+ end
30
+ def test_each
31
+ exp = @str.chomp.split(',')
32
+ @infile.chomp.split(',') { |ary|
33
+ assert_equal(exp,ary)
34
+ }
35
+ end
36
+ def test_copy_array_in
37
+ expstr = @str.chomp.split(',').join(':')
38
+ exp = rio(?").puts(expstr).puts(expstr).puts!(expstr)
39
+ aoa = rio(@infile).split(',')[]
40
+ rio('ans').split(':') < aoa
41
+ ans = rio('ans')
42
+ assert_equal(exp.chomp[],ans.chomp[])
43
+ end
44
+ def test_copy_array_out
45
+ expary = @str.chomp.split(',')
46
+ exp = [expary,expary,expary]
47
+ aoa = []
48
+ rio(@infile).chomp.split(',') > aoa
49
+ assert_equal(exp,aoa)
50
+ end
51
+ def test_copy_left
52
+ expstr = @str.chomp.split(',').join(':')
53
+ exp = rio(?").puts(expstr).puts(expstr).puts!(expstr)
54
+ rio('ans').split(':') < rio(@infile).split(',')
55
+ ans = rio('ans')
56
+ assert_equal(exp.chomp[],ans.chomp[])
57
+ end
58
+ def test_copy_right
59
+ expstr = @str.chomp.split(',').join(':')
60
+ exp = rio(?").puts(expstr).puts(expstr).puts!(expstr)
61
+ rio(@infile).split(',') > rio('ans').split(':')
62
+ ans = rio('ans')
63
+ assert_equal(exp.chomp[],ans.chomp[])
64
+ end
65
+ end