Sha256: 58eaea151bf3313207fafb0e9c79526d865628a8b7534f4a5897cdd369c36a1a

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

$:.unshift(File.dirname(__FILE__) + "/../lib/")
require 'test/unit'
require 'dbf'

class ReadTest < Test::Unit::TestCase
  
  def setup
    @dbf = DBF::Reader.new(File.join(File.dirname(__FILE__),'databases', 'foxpro.dbf'))
  end
  
  def test_records
    assert_kind_of Array, @dbf.records
    assert_kind_of Array, @dbf.rows
  end
  
  def test_record
    assert_equal @dbf.record(0), @dbf.records[0]
    assert_equal @dbf.record(99), @dbf.records[99]
  end
  
  def test_field_count
    assert_equal @dbf.field_count, @dbf.fields.size
  end
  
  def test_header_info
    assert_equal 59, @dbf.field_count
    assert_equal 975, @dbf.record_count
    assert @dbf.has_memo_file?
  end
  
  def test_character_fields
    @dbf.records.each do |record| 
      assert record['NOM'].is_a?(String)
    end
  end
  
  def test_date_fields
    @dbf.records.each do |record| 
      assert record['DATN'].is_a?(Date) || record['DATN'].nil?
    end
  end
  
  def test_numeric_fields
    @dbf.records.each do |record|
      assert record['NF'].is_a?(Fixnum)
    end
  end
  
  def test_logical_fields
    # need a test database that has a logical field
  end
  
  def test_memo_fields
    @dbf.records.each_with_index do |record, index|
      if [1,3,5].include?(index)
        assert record['OBSE'].is_a?(String)
      elsif [2].include?(index)
        assert record['OBSE'].nil?
      else
        assert record['OBSE'].is_a?(String) || record['OBSE'].nil?
      end
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dbf-0.1.0 test/read_test.rb