summaryrefslogtreecommitdiffhomepage
path: root/test/t
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-05-14 23:04:13 +0900
committerYukihiro Matsumoto <[email protected]>2012-05-14 23:04:13 +0900
commit8085817cb5737ca0c2a4afb5e3d013a395e12eb4 (patch)
tree633371b8956a39b5c570d745bdfa963e42111158 /test/t
parent0c6ff97b8e88e6f848ba73a2bf799de98d27a526 (diff)
downloadmruby-8085817cb5737ca0c2a4afb5e3d013a395e12eb4.tar.gz
mruby-8085817cb5737ca0c2a4afb5e3d013a395e12eb4.zip
make test restructuring
Diffstat (limited to 'test/t')
-rw-r--r--test/t/_assert.rb44
-rw-r--r--test/t/array.rb40
-rw-r--r--test/t/time.rb73
3 files changed, 157 insertions, 0 deletions
diff --git a/test/t/_assert.rb b/test/t/_assert.rb
new file mode 100644
index 000000000..91751f769
--- /dev/null
+++ b/test/t/_assert.rb
@@ -0,0 +1,44 @@
+$ok_test = 0
+$ko_test = 0
+$asserts = []
+
+##
+# Verify a code block.
+#
+# str : A remark which will be printed in case
+# this assertion fails
+# iso : The ISO reference code of the feature
+# which will be tested by this
+# assertion
+def assert(str = 'Assertion failed', iso = '')
+ if(!yield)
+ $asserts.push([str, iso])
+ $ko_test += 1
+ print "F"
+ else
+ $ok_test += 1
+ print "."
+ end
+end
+
+##
+# Report the test result and print all assertions
+# which were reported broken.
+def report()
+ print "\n"
+ $asserts.each do |str, iso|
+ print("Test Failed: #{str} [#{iso}]\n");
+ end
+
+ $total_test = $ok_test + $ko_test
+ print 'Total tests:'
+ print $total_test
+ print "\n"
+
+ print ' OK: '
+ print $ok_test
+ print "\n"
+ print ' KO: '
+ print $ko_test
+ print "\n"
+end
diff --git a/test/t/array.rb b/test/t/array.rb
new file mode 100644
index 000000000..3b65a80dd
--- /dev/null
+++ b/test/t/array.rb
@@ -0,0 +1,40 @@
+##
+# Array ISO Test
+
+assert('Array', '15.2.12') do
+ Array.class == Class
+end
+
+assert('Array.[]', '15.2.12.4.1') do
+ Array.[](1,2,3) == [1, 2, 3]
+end
+
+assert('Array#*', '15.2.12.5.1') do
+ [1].*(3) == [1, 1, 1]
+end
+
+assert('Array#+', '15.2.12.5.2') do
+ [1].+([1]) == [1, 1]
+end
+
+assert('Array#<<', '15.2.12.5.3') do
+ [1].<<(1) == [1, 1]
+end
+
+assert('Array#[]', '15.2.12.5.4') do
+ [1,2,3].[](1) == 2
+end
+
+assert('Array#[]=', '15.2.12.5.5') do
+ [1,2,3].[]=(1,4) == [1, 4, 3]
+end
+
+assert('Array#clear', '15.2.12.5.6') do
+ a = [1]
+ a.clear
+ a == []
+end
+
+# Not ISO specified
+
+
diff --git a/test/t/time.rb b/test/t/time.rb
new file mode 100644
index 000000000..f33cdde0d
--- /dev/null
+++ b/test/t/time.rb
@@ -0,0 +1,73 @@
+##
+# Time ISO Test
+
+assert('Time', '15.2.19') do
+ Time.class == Class
+end
+
+assert('Time.at', '15.2.19.6.1') do
+ Time.at(1300000000.0)
+end
+
+assert('Time.gm', '15.2.19.6.2') do
+ Time.gm(2012, 12, 23)
+end
+
+assert('Time#asctime', '15.2.19.7.4') do
+ Time.at(1300000000.0).utc.asctime == "Sun Mar 13 07:06:40 UTC 2011"
+end
+
+assert('Time#initialize_copy', '15.2.19.7.17') do
+ time_tmp_2 = Time.at(7.0e6)
+ time_tmp_2.clone == time_tmp_2
+end
+
+assert('Time#mday', '15.2.19.7.19') do
+ Time.gm(2012, 12, 23).mday == 23
+end
+
+assert('Time#month', '15.2.19.7.22') do
+ Time.gm(2012, 12, 23).month == 12
+end
+
+assert('Time#to_f', '15.2.19.7.24') do
+ Time.at(1300000000.0).to_f == 1300000000.0
+end
+
+assert('Time#to_i', '15.2.19.7.25') do
+ Time.at(1300000000.0).to_i == 1300000000
+end
+
+assert('Time#usec', '15.2.19.7.26') do
+ Time.at(1300000000.0).usec == 0
+end
+
+assert('Time#utc', '15.2.19.7.27') do
+ Time.at(1300000000.0).utc
+end
+
+assert('Time#utc?', '15.2.19.7.28') do
+ Time.at(1300000000.0).utc.utc?
+end
+
+assert('Time#wday', '15.2.19.7.30') do
+ Time.at(1300000000.0).utc.wday == 0
+end
+
+assert('Time#yday', '15.2.19.7.31') do
+ Time.at(1300000000.0).utc.yday == 71
+end
+
+assert('Time#year', '15.2.19.7.32') do
+ Time.gm(2012, 12, 23).year == 2012
+end
+
+assert('Time#zone', '15.2.19.7.33') do
+ Time.at(1300000000.0).utc.zone == 'UTC'
+end
+
+# Not ISO specified
+
+assert('Time#new') do
+ Time.new.class == Time
+end