summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-05-04 22:39:21 +0900
committerYukihiro Matsumoto <[email protected]>2012-05-04 22:39:21 +0900
commite806f55e69e1671743395b10def1a33577e854e6 (patch)
treead4de3ffe71a811d8ae442c6d7c2c70bdc701a41 /test
parent5a6193ffddf6c0d8b3d564a04133d66baf54e511 (diff)
downloadmruby-e806f55e69e1671743395b10def1a33577e854e6.tar.gz
mruby-e806f55e69e1671743395b10def1a33577e854e6.zip
move mrb_str_new prototype to mruby.h
Diffstat (limited to 'test')
-rw-r--r--test/test_time.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/test_time.rb b/test/test_time.rb
new file mode 100644
index 000000000..ce68f4c45
--- /dev/null
+++ b/test/test_time.rb
@@ -0,0 +1,49 @@
+$ok = 0
+$failed = 0
+$ftest = []
+
+def assert(str = "Assertion failed")
+ if(!yield)
+ $ftest.push(str)
+ $failed += 1
+ print "F"
+ else
+ $ok += 1
+ print "."
+ end
+end
+
+def report()
+ print "\n"
+ $ftest.each do |str|
+ puts("Test Failed: #{str}");
+ end
+ $total = $ok + $failed
+ puts "Ran #{$total} tests: #{$ok} OK and #{$failed} failed."
+end
+
+doom = Time.gm(2012, 12, 23)
+assert("Time.gm") { doom }
+assert("gm year") { doom.year == 2012 }
+assert("gm month") { doom.month == 12 }
+assert("gm day") { doom.mday == 23 }
+
+t0 = Time.new
+assert("Can create time.") { t0 }
+
+t1 = Time.new(1300000000.0e6).utc
+assert("asctime") { t1.asctime == "Sun Mar 13 16:06:40 UTC 2011" }
+assert("usec") { t1.usec == 0 }
+assert("to_i") { t1.to_i == 1300000000 }
+assert("to_f") { t1.to_f == 1300000000.0 }
+assert("utc?") { t1.utc? }
+assert("zone") { t1.zone == "UTC" }
+assert("wday") { t1.wday == 0 }
+assert("yday") { t1.yday == 71 }
+assert("year") { t1.year == 2011 }
+
+t2 = Time.new(7.0e6)
+t1.initialize_copy(t2)
+assert("initialize_copy") { t1 == t2 }
+
+report()