Sha256: 3ed9a16767964fdfe0194ffde4c3efbb33b4863d5ff74b9a5354042f4a1b84a5

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

#!/usr/local/bin/ruby
if $0 == __FILE__
  Dir.chdir File.dirname(__FILE__)+'/../'
  $:.unshift File.expand_path('../lib/')
end

require 'rio'
require 'test/unit'
require 'test/unit/testsuite'
require 'extensions/symbol'
require 'tc/testcase'
class TC_dir < Test::Unit::TestCase
  include RIO_TestCase
  def setup()
    super
    rio('a').rmtree.mkpath
    rio('a/d').mkpath
    rio('a/f').touch
    @ents = %w[. .. d f]
    @rents = @ents.map { |ds| rio(ds) }
  end
  def test_read
    d = rio('a')
    ans = []
    while ent = d.read
      ans << ent
    end
    assert_equal(@rents,ans)
    assert(d.closed?)
  end
  def test_rewind
    d = rio('a').nocloseoneof
    ans = []
    while ent = d.read
      ans << ent
    end
    assert_equal(@rents,ans)
    assert!(d.closed?)
    d.rewind
    while ent = d.read
      ans << ent
    end
    assert_equal(@rents+@rents,ans)
    d.close
  end
  def test_seek
    d = rio('a').nocloseoneof
    ans = []
    poss = {}
    while true
      ps = d.tell
      ent = d.read
      break if ent.nil?
      poss[ent] = ps
    end
    poss.each do |e,ps|
      ent = d.seek(ps).read
      assert_equal(e,ent)
    end
    d.close
  end
  def test_pos
    d = rio('a').nocloseoneof
    ans = []
    poss = {}
    while true
      ps = d.pos
      ent = d.read
      break if ent.nil?
      poss[ent] = ps
    end
    poss.each do |e,ps|
      d.pos = ps
      ent = d.read
      assert_equal(e,ent)
    end
    d.close
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rio-0.3.1 test/tc/dir.rb
rio-0.3.2 test/tc/dir.rb
rio-0.3.6 test/tc/dir.rb
rio-0.3.3 test/tc/dir.rb
rio-0.3.4 test/tc/dir.rb