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
@@ -1,14 +1,17 @@
1
1
  require 'test/unit'
2
2
  require 'tc/testcase'
3
3
 
4
- #require 'tc/yaml'
5
-
4
+ require 'tc/yaml'
5
+ require 'tc/truncate'
6
+ require 'tc/line_record_row'
7
+ require 'tc/path_parts'
6
8
  require 'tc/abs'
7
9
  require 'tc/tonl'
8
10
  require 'tc/files_select'
9
11
  require 'tc/emptyriodir'
10
12
  require 'tc/entsel'
11
13
  require 'tc/base'
14
+ require 'tc/base2'
12
15
  require 'tc/clearsel'
13
16
  require 'tc/closeoncopy'
14
17
  require 'tc/closeoneof'
@@ -19,6 +22,7 @@ require 'tc/copy-to'
19
22
  require 'tc/copyarray'
20
23
  require 'tc/copydest'
21
24
  require 'tc/copydir'
25
+ require 'tc/copy-dir-samevar'
22
26
  require 'tc/copydirlines'
23
27
  require 'tc/copylines'
24
28
  require 'tc/create'
@@ -43,7 +47,7 @@ require 'tc/io_read'
43
47
  require 'tc/iometh'
44
48
  require 'tc/likeio'
45
49
  require 'tc/lines'
46
- require 'tc/methods'
50
+ require 'tc/clone'
47
51
  require 'tc/misc'
48
52
  require 'tc/nolines'
49
53
  require 'tc/noqae'
@@ -52,7 +56,6 @@ require 'tc/overload'
52
56
  require 'tc/pa'
53
57
  require 'tc/paths'
54
58
  require 'tc/pid'
55
- require 'tc/pid'
56
59
  require 'tc/piper' unless $mswin32
57
60
  require 'tc/qae'
58
61
  require 'tc/qae_riovar'
@@ -65,6 +68,8 @@ require 'tc/selnosel'
65
68
  require 'tc/skip'
66
69
  require 'tc/skiplines'
67
70
  require 'tc/split'
71
+ require 'tc/splitpath'
72
+ require 'tc/splitlines'
68
73
  require 'tc/symlink' unless $mswin32
69
74
  require 'tc/symlink0' unless $mswin32
70
75
  require 'tc/symlink1' unless $mswin32
@@ -25,7 +25,7 @@ class TC_base < Test::RIO::TestCase
25
25
  assert_equal('/tmp/zippy',r.abs.path)
26
26
  end
27
27
  def test_longer_base
28
- r = rio('zippy',{:base => '/tmp'})
28
+ r = rio('zippy',{:base => '/tmp/'})
29
29
  assert_equal('/tmp/zippy',r.abs.path)
30
30
  end
31
31
  end
@@ -0,0 +1,87 @@
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_base2 < 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
+ @base_urls = {
19
+ 'abshttp' => 'http://localhost/riotest/dir/index.html',
20
+ 'rootdir' => '/rootdir/dir/',
21
+ 'reldir' => 'reldir/dir/',
22
+ }
23
+ @links = {
24
+ 'abshttp' => 'http://localhost/riotest/hw.html',
25
+ 'relfile' => '../hw.html',
26
+ 'absfile' => '/riotest/hw.html',
27
+ }
28
+ end
29
+
30
+ def test_abshttp_absfile
31
+ bk = 'abshttp'
32
+ lk = 'absfile'
33
+ b = @base_urls[bk]
34
+ l = @links[lk]
35
+ exp = [l,l,l,@links['abshttp'],l,b,@links['abshttp']]
36
+ run_case(bk,lk,exp)
37
+ end
38
+ def run_case(bk,lk,exp)
39
+ bs = @base_urls[bk]
40
+ ls = @links[lk]
41
+
42
+ [bs,URI(bs)].each do |b|
43
+ [ls,URI(ls),rio(ls)].each do |l|
44
+ u = rio(ls)
45
+ msg = mkmsg(bk,lk,b,l)
46
+ assert_equal(exp[0].to_s,u.to_s,msg)
47
+ assert_equal(exp[1].to_s,u.base.to_s,msg)
48
+ assert_equal(exp[2].to_s,u.abs.to_s,msg)
49
+ #p "run_case: b=#{b} abs=#{u.abs(b)}"
50
+ assert_equal(exp[3].to_s,u.abs(b).to_s,msg)
51
+ end
52
+ end
53
+
54
+
55
+ [bs,URI(bs)].each do |b|
56
+ [ls,URI(ls),rio(ls)].each do |l|
57
+ #p "b=#{b.inspect} l=#{l.inspect}"
58
+ u = rio(l,{:base => b})
59
+ msg = mkmsg(bk,lk,b,l)
60
+ assert_equal(exp[4].to_s,u.to_s,msg)
61
+ assert_equal(exp[5].to_s,u.base.to_s,msg)
62
+ assert_equal(exp[6].to_s,u.abs.to_s,msg)
63
+ end
64
+ end
65
+ end
66
+ def test_abshttp_relfile
67
+ bk = 'abshttp'
68
+ lk = 'relfile'
69
+ b = @base_urls[bk]
70
+ l = @links[lk]
71
+ wd = ::Dir.getwd+'/'
72
+ abs = ::Pathname.new(wd + l).cleanpath
73
+ exp = [l,wd,abs,@links['abshttp'],l,b,@links['abshttp']]
74
+ run_case(bk,lk,exp)
75
+ end
76
+ def test_abshttp_abshttp
77
+ bk = 'abshttp'
78
+ lk = 'abshttp'
79
+ b = @base_urls[bk]
80
+ l = @links[lk]
81
+ exp = [l,l,l,l,l,b,l]
82
+ run_case(bk,lk,exp)
83
+ end
84
+ def mkmsg(basekey,linkkey,base,link)
85
+ "Base[#{basekey}](#{base.class}) Link[#{linkkey}](#{link.class})"
86
+ end
87
+ end
@@ -4,13 +4,31 @@ if $0 == __FILE__
4
4
  $:.unshift File.expand_path('../lib/')
5
5
  end
6
6
  require 'rio'
7
- require 'test/unit'
8
- require 'test/unit/testsuite'
7
+ require 'tc/testcase'
9
8
 
10
- class TC_RIO_methods < Test::Unit::TestCase
11
- def assert!(a,msg="negative assertion")
12
- assert((!(a)),msg)
9
+ class TC_clone < Test::RIO::TestCase
10
+ @@once = false
11
+ def self.once
12
+ @@once = true
13
13
  end
14
+ def setup
15
+ super
16
+ self.class.once unless @@once
17
+ @lines = (0..8).map { |n| "Line#{n}" }
18
+ @chlines = @lines.map{|el| el.chomp}
19
+ ::File.open('lines1','w') do |f|
20
+ @lines.each do |li|
21
+ f.puts(li)
22
+ end
23
+ end
24
+ ::File.open('lines2','w') do |f|
25
+ @lines.each do |li|
26
+ f.puts(li)
27
+ end
28
+ end
29
+ @lines = rio('lines1').to_a
30
+ end
31
+
14
32
 
15
33
  def check_clone(ios)
16
34
  oexp = []
@@ -66,34 +84,15 @@ class TC_RIO_methods < Test::Unit::TestCase
66
84
  ios.close
67
85
  assert(ios.closed?,"now original closed")
68
86
  end
69
- def setup
70
- #$trace_states = true
71
- @cwd = rio(::Dir.getwd)
72
- @dir = rio('qp/methods')
73
- # $trace_states = true
74
- @dir.mkpath.chdir
75
- @lines = (0..5).map { |n| "Line#{n}" }
76
- @chlines = @lines.map{|el| el.chomp}
77
- ::File.open('lines','w') do |f|
78
- @lines.each do |li|
79
- f.puts(li)
80
- end
81
- end
82
- @lines = rio('lines').to_a
83
- end
84
- def teardown
85
- @cwd.chdir
86
- $trace_states = false
87
- end
88
87
 
89
- def test_clone_like_IO
90
- ios = ::File.open('lines')
88
+ def test_clone_closes_like_IO
89
+ ios = ::File.open('lines1')
91
90
  ioc,oexp,cexp = check_clone(ios)
92
91
  check_clone_close(ios,ioc)
93
92
  ioc.close unless ioc.closed?
94
93
  ios.close unless ios.closed?
95
94
 
96
- ario = rio('lines').nocloseoneof
95
+ ario = rio('lines1').nocloseoneof
97
96
  crio,oans,cans = check_clone(ario)
98
97
  assert_equal(oexp,oans)
99
98
  assert_equal(cexp,cans)
@@ -101,12 +100,12 @@ class TC_RIO_methods < Test::Unit::TestCase
101
100
 
102
101
  end
103
102
 
104
- def test_dup_not_like_IO
103
+ def test_dup_doesnt_close_like_IO
105
104
 
106
- ios = ::File.open('lines')
105
+ ios = ::File.open('lines1')
107
106
  ioc,oexp,cexp = check_dup(ios)
108
107
  check_clone_close(ios,ioc)
109
- ario = rio('lines').nocloseoneof
108
+ ario = rio('lines1').nocloseoneof
110
109
  crio,oans,cans = check_dup(ario)
111
110
  assert_equal(@lines,oans)
112
111
  assert_equal(@lines,cans)
@@ -114,8 +113,7 @@ class TC_RIO_methods < Test::Unit::TestCase
114
113
 
115
114
  end
116
115
 
117
-
118
- def ztest_clone_own_context
116
+ def test_clone_own_context
119
117
 
120
118
  assert(rio.closeoncopy?,"closeoncopy is on")
121
119
  assert!(rio.nocloseoncopy.closeoncopy?,"nocloseoncopy is off")
@@ -128,19 +126,54 @@ class TC_RIO_methods < Test::Unit::TestCase
128
126
  assert!(cl.chomp?,"cloned chomp is off")
129
127
  assert(chomper.chomp?,"original chomp is still on")
130
128
 
131
- chomper.join!('lines')
129
+ chomper.join!('lines1')
132
130
  ans = chomper.to_a
133
131
  assert_equal(@chlines,ans)
134
132
 
135
- cl.join!('lines')
133
+ cl.join!('lines1')
136
134
  ans = cl.to_a
137
135
  assert_equal(@lines,ans)
138
136
 
139
137
  end
140
- def ztest_clone_read_ruby
138
+ def test_read_moves_pos_like_IO
139
+ #$trace_states = true
140
+ fnio = ::File.open('lines1')
141
+ frio = rio('lines2')
142
+ assert_equal(fnio.pos,frio.pos)
143
+
144
+ nrec = fnio.gets
145
+ rrec = frio.gets
146
+ assert_equal(nrec,rrec)
147
+ assert_equal(fnio.pos,frio.pos)
148
+
149
+ cfnio = fnio.clone
150
+ cfrio = frio.clone
151
+ assert_equal(cfnio.pos,cfrio.pos)
152
+ assert_equal(fnio.pos,frio.pos)
153
+ nrec = cfnio.gets
154
+ rrec = cfrio.gets
155
+ assert_equal(nrec,rrec)
156
+ assert_equal(cfnio.pos,cfrio.pos)
157
+ assert_equal(fnio.pos,frio.pos)
158
+
159
+ nrec = cfnio.gets
160
+ rrec = cfrio.gets
161
+
162
+ assert_equal(nrec,rrec)
163
+ assert_equal(cfnio.pos,cfrio.pos)
164
+ assert_equal(fnio.pos,frio.pos)
165
+
166
+ nrec = fnio.gets
167
+ rrec = frio.gets
168
+ assert_equal(nrec,rrec)
169
+ #assert_equal(fnio.pos,frio.pos)
170
+
171
+ end
172
+
173
+ def test_clone_read_ruby
141
174
 
142
175
  #$trace_states = true
143
- afile = ::File.open('lines')
176
+ afile = ::File.open('lines1')
144
177
  arec = afile.gets
145
178
  assert_equal(@lines[0],arec)
146
179
  cfile = afile.dup
@@ -150,12 +183,10 @@ class TC_RIO_methods < Test::Unit::TestCase
150
183
  afile.close
151
184
  end
152
185
  def test_clone_read
153
- return unless $supports_symlink
154
- #$trace_states = true
155
- ario = rio('lines')
186
+ #return unless $supports_symlink
187
+ ario = rio('lines1')
156
188
  arec = ario.getrec
157
189
  assert_equal(@lines[0],arec)
158
- #$trace_states = true
159
190
  crio = ario.clone.chomp
160
191
  #p "POS: ario(#{ario.pos}) crio(#{crio.pos})"
161
192
  crec = crio.getrec
@@ -164,23 +195,14 @@ class TC_RIO_methods < Test::Unit::TestCase
164
195
  assert_equal(@chlines[1],crec)
165
196
 
166
197
  arec = ario.getrec
167
- #$trace_states = false
168
- assert_equal(@lines[1],arec)
169
198
  cremaining = crio.to_a
170
199
 
171
200
  assert_equal(@chlines[2...@lines.size],cremaining)
172
201
  #p "#{crio.eof?} #{crio.closed?}"
202
+ #$trace_states = true
173
203
  assert(crio.eof?,"clone eof?") unless crio.closed?
174
204
  assert(crio.closed?,"clone closed?")
175
205
 
176
- assert!(ario.eof?,"orignal eof?") unless ario.closed?
177
- assert!(ario.closed?,"original closed?")
178
-
179
- aremaining = ario.readlines
180
- assert_equal(@lines[2...@lines.size],aremaining)
181
- assert(ario.eof?,"orignal eof?") unless ario.closed?
182
- assert(ario.closed?,"original closed?")
183
-
184
206
  end
185
207
 
186
208
  end
@@ -13,6 +13,9 @@ class TC_closeoncopy < Test::RIO::TestCase
13
13
  @@once = true
14
14
 
15
15
  make_lines_file(3,'f0')
16
+ rio('d0').delete!.mkdir.chdir {
17
+ make_lines_file(3,'f1')
18
+ }
16
19
  end
17
20
  def setup
18
21
  super
@@ -85,7 +88,15 @@ class TC_closeoncopy < Test::RIO::TestCase
85
88
  ato(rio(@f0),rio('copyto').open('a'))
86
89
  ato(rio(@f0),orio)
87
90
  end
88
-
89
-
91
+ def test_cx_set
92
+ rio('d0').files { |f|
93
+ assert(f.closeoncopy?)
94
+ }
95
+ end
96
+ def test_cx_bequeath
97
+ rio('d0').nocloseoncopy.files { |f|
98
+ assert!(f.closeoncopy?)
99
+ }
100
+ end
90
101
  end
91
102
  __END__
@@ -0,0 +1,91 @@
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_copy_dir_samevar < Test::RIO::TestCase
11
+ @@once = false
12
+ def self.once
13
+ @@once = true
14
+
15
+ rio('d0').rmtree.mkpath
16
+ rio('d0/d1').rmtree.mkpath
17
+ make_lines_file(1,'d0/f0.txt')
18
+ make_lines_file(2,'d0/f1.txt')
19
+ make_lines_file(5,'d0/d1/f2.txt')
20
+ make_lines_file(6,'d0/d1/f3.txt')
21
+ rio('d2').rmtree.mkpath
22
+ make_lines_file(3,'d2/f4.txt')
23
+ end
24
+ def setup
25
+ super
26
+ self.class.once unless @@once
27
+
28
+ @d0 = rio('d0')
29
+ @d1 = rio('d0/d1')
30
+ @f0 = rio('d0/f0.txt')
31
+ @f1 = rio('d0/f1.txt')
32
+ @f2 = rio('d0/d1/f2.txt')
33
+ @f3 = rio('d0/d1/f3.txt')
34
+ @d2 = rio('d2')
35
+ @f4 = rio('d2/f4.txt')
36
+ rio('exp').delete!.mkdir < rio(@d0)
37
+ rio('exp2').delete!.mkdir < rio(@d2)
38
+ end
39
+ def test_copy_files
40
+ rio(@d0).files { |f|
41
+ f < f.contents
42
+ }
43
+ assert_rios_equal(rio('exp',@f0),rio(@f0))
44
+ assert_rios_equal(rio('exp',@f1),rio(@f1))
45
+ end
46
+ def test_copy_files_contents_gsub
47
+ rio(@d0).files { |f|
48
+ f < f.contents.gsub(/^L1/,'Line1')
49
+ }
50
+ assert_rios_equal(rio('exp',@f0),rio(@f0))
51
+ exp = rio('exp',@f1).chomp.lines[].map{|l| l.sub(/^L1/,'Line1')}
52
+ assert_equal(exp,rio(@f1).chomp[])
53
+ end
54
+ def test_copy_files_array
55
+ rio(@d0).files { |f|
56
+ f < f.lines[]
57
+ }
58
+ assert_rios_equal(rio('exp',@f0),rio(@f0))
59
+ assert_rios_equal(rio('exp',@f1),rio(@f1))
60
+ end
61
+ def test_copy_files_array_sel
62
+ rio(@d0).files { |f|
63
+ f < f.lines[/^L0/]
64
+ }
65
+ assert_rios_equal(rio('exp',@f0),rio(@f0))
66
+ exp = rio('exp',@f1).lines[0]
67
+ assert_equal(exp,rio(@f1).lines[])
68
+ end
69
+ def test_copy_all_files_array
70
+ rio(@d0).all.files { |f|
71
+ f < f.lines[]
72
+ }
73
+ assert_rios_equal(rio('exp',@f0),rio(@f0))
74
+ assert_rios_equal(rio('exp',@f1),rio(@f1))
75
+ end
76
+ def test_copy_all_files
77
+ rio(@d0).all.files { |f|
78
+ f < f.contents
79
+ }
80
+ assert_rios_equal(rio('exp',@f0),rio(@f0))
81
+ assert_rios_equal(rio('exp',@f1),rio(@f1))
82
+ assert_rios_equal(rio('exp',@f2),rio(@f2))
83
+ assert_rios_equal(rio('exp',@f3),rio(@f3))
84
+ end
85
+ def cptest(src)
86
+ dst = rio('dst').delete!.mkpath
87
+ dst < src.clone
88
+ assert_rios_equal(src.clone,rio(dst,src.filename),"rio copy")
89
+ end
90
+
91
+ end