1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
##############################################################################
# tc_date.rb
#
# Test case for the DBI::Date class (currently) located in the utils.rb file.
##############################################################################
$LOAD_PATH.unshift(Dir.pwd)
$LOAD_PATH.unshift(File.dirname(Dir.pwd))
$LOAD_PATH.unshift("../../lib")
$LOAD_PATH.unshift("../../lib/dbi")
$LOAD_PATH.unshift("lib")
require 'date'
require 'dbi'
require 'test/unit'
Deprecate.set_action(proc { })
class TC_DBI_Date < Test::Unit::TestCase
def setup
@date = Date.new
@time = Time.now
@dbi_date = DBI::Date.new
end
def test_constructor
assert_nothing_raised{ DBI::Date.new(2006) }
assert_nothing_raised{ DBI::Date.new(2006, 1) }
assert_nothing_raised{ DBI::Date.new(2006, 1, 20) }
assert_nothing_raised{ DBI::Date.new(Date.new) }
assert_nothing_raised{ DBI::Date.new(Time.now) }
end
def test_year
assert_respond_to(@dbi_date, :year)
assert_respond_to(@dbi_date, :year=)
assert_equal(0, @dbi_date.year)
end
def test_month
assert_respond_to(@dbi_date, :month)
assert_respond_to(@dbi_date, :month=)
end
# An alias for :month, :month=
def test_mon
assert_respond_to(@dbi_date, :mon)
assert_respond_to(@dbi_date, :mon=)
assert_equal(0, @dbi_date.mon)
end
def test_day
assert_respond_to(@dbi_date, :day)
assert_respond_to(@dbi_date, :day=)
assert_equal(0, @dbi_date.day)
end
# An alias for :day, :day=
def test_mday
assert_respond_to(@dbi_date, :mday)
assert_respond_to(@dbi_date, :mday=)
end
def test_to_time
assert_respond_to(@dbi_date, :to_time)
assert_equal(@time, DBI::Date.new(@time).to_time)
assert_equal(@time.object_id, DBI::Date.new(@time).to_time.object_id)
end
def test_to_date
assert_respond_to(@dbi_date, :to_date)
assert_equal(@date, DBI::Date.new(@date).to_date)
assert_equal(@date.object_id, DBI::Date.new(@date).to_date.object_id)
end
# We test .to_s because it has an explicit implementation
def test_to_s
assert_respond_to(@dbi_date, :to_s)
assert_nothing_raised{ @dbi_date.to_s }
assert_kind_of(String, @dbi_date.to_s)
assert_equal("0000-00-00", @dbi_date.to_s)
end
def teardown
@date = nil
@time = nil
@dbi_date = nil
end
end
|