#!/usr/local/bin/ruby -w
# ex:ts=8
# vim:sw=4:sts=4:tw=120
require 'test/unit'
require 'supertime'

class SuperTime__test < Test::Unit::TestCase
    def setup
	assert_nothing_raised {
	    @time = Time.mktime(1950, 1, 2, 3, 4, 5)
	}
    end
    def test_strftime
	assert_equal("1950-01-02 03:04:05", @time.strftime("%Y-%m-%d %H:%M:%S"))
	assert_equal("% %Y1950", @time.strftime("%% %%Y%Y"))
    end
    def test_year
	assert(@time.year == 1950)
    end
    def test_plus
	assert_nothing_raised {
	    time = @time + 10000000000000
	}
    end
    def test_minus
	assert_nothing_raised {
	    time = @time - Time.now
	}
	assert_nothing_raised {
	    time = @time - 10000000000000
	}
    end
    def test_inspect
	assert_equal("Sun Jan 02 03:04:05 CET 1950", @time.inspect)
    end
    def test_self_local
	time = nil
	assert_nothing_raised {
	    #time = Time.mktime(sec, min, hour, day, month, year, wday, yday, isdst, tz)
	    time = Time.mktime(5, 4, 3, 2, 1, 1950, 0, 1, false, "CET")
	}
	assert_equal(time, @time)
    end
    def test_gm
	time = nil
	time2 = nil
	time3 = nil
	assert_nothing_raised {
	    # XXX This STILL generates in the local timezone, even though
	    # it gets a specified timezone that is NOT the local one.
	    # I consider this to be a bug in the original implementation.
	    #time = Time.mktime(5, 4, 3, 2, 1, 1950, 0, 1, false, "GMT")
	    time2 = Time.gm(5, 4, 3, 2, 1, 1950, 0, 1, false, "GMT")
	    time3 = Time.gm(1950, 1, 2, 3, 4, 5)
	}
	#assert_equal("GMT", time.zone,  "time.zone")
	assert_equal("GMT", time2.zone, "time2.zone")
	assert_equal("GMT", time3.zone, "time3.zone")
	#assert_equal(time, time2)
	assert_equal(time2, time3)
    end
end

#
# => ["+", "-", "<", "<=", "<=>", "==", "===", "=~", ">", ">=", "__id__", "__send__", "_dump", "asctime", "between?",
# "class", "clone", "ctime", "day", "display", "dst?", "dup", "eql?", "equal?", "extend", "freeze", "frozen?", "gmt?",
# "gmt_offset", "gmtime", "gmtoff", "hash", "hour", "id", "inspect", "instance_eval", "instance_of?",
# "instance_variables", "is_a?", "isdst", "kind_of?", "localtime", "mday", "method", "methods", "min", "mon", "month",
# "nil?", "private_methods", "protected_methods", "public_methods", "respond_to?", "sec", "send", "singleton_methods",
# "strftime", "taint", "tainted?", "to_a", "to_f", "to_i", "to_s", "tv_sec", "tv_usec", "type", "untaint", "usec",
# "utc", "utc?", "utc_offset", "wday", "yday", "year", "zone"]

#
