summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-10 17:50:38 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-10 17:50:38 +0000
commit4dedfc3cc97c2470f1926eaef49e381839e157ef (patch)
treeb79a762c2874916fde94a7397bfd76d4114edb9c /test
parent68ebbbfebe5b666cf76ab41f1e6191a172d62690 (diff)
Add tests for rb_time_timespec_new
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/-ext-/time/test_new.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/-ext-/time/test_new.rb b/test/-ext-/time/test_new.rb
new file mode 100644
index 0000000000..b25bdf6bd2
--- /dev/null
+++ b/test/-ext-/time/test_new.rb
@@ -0,0 +1,39 @@
+require 'test/unit'
+require "-test-/time"
+
+class Bug::Time::Test_New < Test::Unit::TestCase
+ def test_nano_new
+ assert_equal(Time.at(1447087832, 476451.125), Bug::Time.nano_new(1447087832, 476451125))
+ assert_not_equal(Time.at(1447087832, 476451.325), Bug::Time.nano_new(1447087832, 476451125))
+ assert_equal(false, Bug::Time.nano_new(1447087832, 476451125).utc?)
+ end
+
+ def assert_time_equal(a, b, msg=nil)
+ assert_equal(a, b, msg)
+ assert_equal(a.gmtoff, b.gmtoff, msg)
+ assert_equal(a.utc?, b.utc?, msg)
+ end
+
+ def test_timespec_new
+ assert_time_equal(Time.at(1447087832, 476451.125).localtime(32400),
+ Bug::Time.timespec_new(1447087832, 476451125, 32400))
+ assert_not_equal(Time.at(1447087832, 476451.128).localtime(32400),
+ Bug::Time.timespec_new(1447087832, 476451125, 32400))
+ assert_equal(false, Bug::Time.timespec_new(1447087832, 476451125, 0).utc?)
+ assert_equal(true, Bug::Time.timespec_new(1447087832, 476451125, 0x7fffffff).utc?)
+ assert_equal(false, Bug::Time.timespec_new(1447087832, 476451125, 0x7ffffffe).utc?)
+ assert_equal(Time.now.gmtoff, Bug::Time.timespec_new(1447087832, 476451125, 0x7ffffffe).gmtoff)
+ assert_time_equal(Time.at(1447087832, 476451.125).localtime(86399),
+ Bug::Time.timespec_new(1447087832, 476451125, 86399))
+ assert_time_equal(Time.at(1447087832, 476451.125).localtime(-86399),
+ Bug::Time.timespec_new(1447087832, 476451125, -86399))
+ assert_raise(ArgumentError){Bug::Time.timespec_new(1447087832, 476451125, 86400)}
+ assert_raise(ArgumentError){Bug::Time.timespec_new(1447087832, 476451125,-86400)}
+ end
+
+ def test_timespec_new
+ t0 = Time.now.to_r
+ t = Bug::Time.timespec_now
+ assert_in_delta 3, t0, t
+ end
+end