From 2664eb5ca6aba1351dfb467cd5a3bb4c2d04c309 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 24 May 2012 05:33:29 +0800 Subject: Add ISO Test Cases for Kernel --- test/t/kernel.rb | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 test/t/kernel.rb (limited to 'test/t') diff --git a/test/t/kernel.rb b/test/t/kernel.rb new file mode 100644 index 000000000..eda07074b --- /dev/null +++ b/test/t/kernel.rb @@ -0,0 +1,125 @@ +## +# Kernel ISO Test + +assert('Kernel', '15.3.1') do + Kernel.class == Module +end + +assert('Kernel.block_given?', '15.3.1.2.2') do + Kernel.block_given? == false +end + +assert('Kernel.global_variables', '15.3.1.2.4') do + Kernel.global_variables.class == Array +end + +assert('Kernel.iterator?', '15.3.1.2.5') do + Kernel.iterator? == false +end + +assert('Kernel.lambda', '15.3.1.2.6') do + l = Kernel.lambda do + true + end + + l.call and l.class == Proc +end + +assert('Kernel.local_variables', '15.3.1.2.7') do + Kernel.local_variables.class == Array +end + +assert('Kernel.loop', '15.3.1.2.8') do + i = 0 + + Kernel.loop do + i += 1 + break if i == 100 + end + + i == 100 +end + +assert('Kernel.p', '15.3.1.2.9') do + # TODO search for a way to test p to stdio + true +end + +assert('Kernel.print', '15.3.1.2.10') do + # TODO search for a way to test print to stdio + true +end + +assert('Kernel.puts', '15.3.1.2.11') do + # TODO search for a way to test puts to stdio + true +end + +# TODO fails at the moment without arguments +assert('Kernel.raise', '15.3.1.2.12') do + e_list = [] + + begin + raise RuntimeError.new + rescue => e + e_list << e + end + + e_list[0].class == RuntimeError +end + +assert('Kernel#hash', '15.3.1.2.15') do + hash == hash +end + +assert('Kernel#local_variables', '15.3.1.2.28') do + local_variables.class == Array +end + +assert('Kernel#loop', '15.3.1.2.29') do + i = 0 + + loop do + i += 1 + break if i == 100 + end + + i == 100 +end + +assert('Kernel#methods', '15.3.1.2.31') do + methods.class == Array +end + +assert('Kernel#nil?', '15.3.1.2.32') do + # TODO why is Kernel nil ???? + nil? == true +end + +assert('Kernel#private_methods', '15.3.1.2.36') do + private_methods.class == Array +end + +assert('Kernel#protected_methods', '15.3.1.2.37') do + protected_methods.class == Array +end + +assert('Kernel#public_methods', '15.3.1.2.38') do + public_methods.class == Array +end + +assert('Kernel#respond_to?', '15.3.1.2.43') do + respond_to? :nil? +end + +# TODO at the moment doesn't comply to ISO assert('Kernel#send', '15.3.1.2.44') do + +assert('Kernel#singleton_methods', '15.3.1.2.45') do + singleton_methods.class == Array +end + +assert('Kernel#to_s', '15.3.1.2.46') do + # TODO looks strange.. + to_s == '' +end + -- cgit v1.2.3 From 150b235fb650f15277e99080bc639bc4b60e08ba Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 25 May 2012 14:01:14 +0800 Subject: Add Tests for all Exception classes, for false, true, Proc, Module, nil and Object --- test/t/argumenterror.rb | 7 ++ test/t/bs_class.rb | 121 ----------------------------- test/t/bs_exception.rb | 158 -------------------------------------- test/t/class.rb | 126 ++++++++++++++++++++++++++++++ test/t/exception.rb | 195 +++++++++++++++++++++++++++++++++++++++++++++++ test/t/false.rb | 27 +++++++ test/t/indexerror.rb | 7 ++ test/t/localjumperror.rb | 10 +++ test/t/module.rb | 11 +++ test/t/nameerror.rb | 15 ++++ test/t/nil.rb | 27 +++++++ test/t/nomethoderror.rb | 14 ++++ test/t/object.rb | 7 ++ test/t/proc.rb | 45 +++++++++++ test/t/rangeerror.rb | 7 ++ test/t/regexperror.rb | 5 ++ test/t/runtimeerror.rb | 15 ++++ test/t/standarderror.rb | 7 ++ test/t/struct.rb | 7 ++ test/t/true.rb | 27 +++++++ test/t/typeerror.rb | 7 ++ 21 files changed, 566 insertions(+), 279 deletions(-) create mode 100644 test/t/argumenterror.rb delete mode 100644 test/t/bs_class.rb delete mode 100644 test/t/bs_exception.rb create mode 100644 test/t/class.rb create mode 100644 test/t/exception.rb create mode 100644 test/t/false.rb create mode 100644 test/t/indexerror.rb create mode 100644 test/t/localjumperror.rb create mode 100644 test/t/module.rb create mode 100644 test/t/nameerror.rb create mode 100644 test/t/nil.rb create mode 100644 test/t/nomethoderror.rb create mode 100644 test/t/object.rb create mode 100644 test/t/proc.rb create mode 100644 test/t/rangeerror.rb create mode 100644 test/t/regexperror.rb create mode 100644 test/t/runtimeerror.rb create mode 100644 test/t/standarderror.rb create mode 100644 test/t/struct.rb create mode 100644 test/t/true.rb create mode 100644 test/t/typeerror.rb (limited to 'test/t') diff --git a/test/t/argumenterror.rb b/test/t/argumenterror.rb new file mode 100644 index 000000000..be1dec974 --- /dev/null +++ b/test/t/argumenterror.rb @@ -0,0 +1,7 @@ +## +# ArgumentError ISO Test + +assert('ArgumentError', '15.2.24') do + ArgumentError.class == Class +end + diff --git a/test/t/bs_class.rb b/test/t/bs_class.rb deleted file mode 100644 index d8bb63c05..000000000 --- a/test/t/bs_class.rb +++ /dev/null @@ -1,121 +0,0 @@ -## -# Bootstrap tests for Class - -assert('BS Class 1') do - class C; end - C.class == Class -end - -assert('BS Class 2') do - class C; end - C.new.class == C -end - -assert('BS Class 3') do - class C; end - C.new.class.class == Class -end - -assert('BS Class 4') do - class A; end - class C < A; end - C.class == Class -end - -assert('BS Class 5') do - class A; end - class C < A; end - C.new.class == C -end - -assert('BS Class 6') do - class A; end - class C < A; end - C.new.class.class == Class -end - -assert('BS Class Module 1') do - module M; end - M.class == Module -end - -assert('BS Class Module 2') do - module M; end - class C; include M; end - C.new.class == C -end - -# nested class -assert('BS Class Nested 1') do - class A; end - class A::B; end - A::B == A::B -end - -assert('BS Class Nested 2') do - class A; end - class A::B; end - A::B.new.class == A::B -end - -assert('BS Class Nested 3') do - class A; end - class A::B; end - A::B.new.class.class == Class -end - -assert('BS Class Nested 4') do - class A; end - class A::B; end - class A::B::C; end - A::B::C == A::B::C -end - -assert('BS Class Nested 5') do - class A; end - class A::B; end - class A::B::C; end - A::B::C.class == Class -end - -assert('BS Class Nested 6') do - class A; end - class A::B; end - class A::B::C; end - A::B::C.new.class == A::B::C -end - -assert('BS Class Nested 7') do - class A; end - class A::B; end - class A::B2 < A::B; end - A::B2 == A::B2 -end - -assert('BS Class Nested 8') do - class A; end - class A::B; end - class A::B2 < A::B; end - A::B2.class == Class -end - -assert('BS Class Colon 1') do - class A; end; A::C = 1; A::C == 1 -end - -assert('BS Class Colon 2') do - class A; class ::C; end end; C == C -end - -assert('BS Class Colon 3') do - class A; class ::C; end end; C.class == Class -end - -assert('BS Class Dup 1') do - class C; end; C.dup.class == Class -end - -assert('BS Class Dup 2') do - module M; end; M.dup.class == Module -end - diff --git a/test/t/bs_exception.rb b/test/t/bs_exception.rb deleted file mode 100644 index 6ab2cee2a..000000000 --- a/test/t/bs_exception.rb +++ /dev/null @@ -1,158 +0,0 @@ -## -# Bootstrap tests for Exceptions - -assert('BS Exception 1') do - begin - 1+1 - ensure - 2+2 - end == 2 -end - -assert('BS Exception 2') do - begin - 1+1 - begin - 2+2 - ensure - 3+3 - end - ensure - 4+4 - end == 4 -end - -assert('BS Exception 3') do - begin - 1+1 - begin - 2+2 - ensure - 3+3 - end - ensure - 4+4 - begin - 5+5 - ensure - 6+6 - end - end == 4 -end - -assert('BS Exception 4') do - a = nil - 1.times{|e| - begin - rescue => err - end - a = err.class - } - a == NilClass -end - -assert('BS Exception 5') do - $ans = [] - def m - $! - end - def m2 - 1.times{ - begin - return - ensure - $ans << m - end - } - end - m2 - $ans == [nil] -end - -assert('BS Exception 6') do - $i = 0 - def m - iter{ - begin - $i += 1 - begin - $i += 2 - break - ensure - - end - ensure - $i += 4 - end - $i = 0 - } - end - - def iter - yield - end - m - $i == 7 -end - -assert('BS Exception 7') do - $i = 0 - def m - begin - $i += 1 - begin - $i += 2 - return - ensure - $i += 3 - end - ensure - $i += 4 - end - p :end - end - m - $i == 10 -end - -assert('BS Exception 8') do - begin - 1 - rescue - 2 - else - 3 - end == 3 -end - -assert('BS Exception 9') do - begin - 1+1 - rescue - 2+2 - else - 3+3 - ensure - 4+4 - end == 6 -end - -assert('BS Exception 10') do - begin - 1+1 - begin - 2+2 - rescue - 3+3 - else - 4+4 - end - rescue - 5+5 - else - 6+6 - ensure - 7+7 - end == 12 -end - diff --git a/test/t/class.rb b/test/t/class.rb new file mode 100644 index 000000000..92f3df51d --- /dev/null +++ b/test/t/class.rb @@ -0,0 +1,126 @@ +## +# Class ISO Test + +assert('Class', '15.2.3') do + Class.class == Class +end + +# Not ISO specified + +assert('Class 1') do + class C; end + C.class == Class +end + +assert('Class 2') do + class C; end + C.new.class == C +end + +assert('Class 3') do + class C; end + C.new.class.class == Class +end + +assert('Class 4') do + class A; end + class C < A; end + C.class == Class +end + +assert('Class 5') do + class A; end + class C < A; end + C.new.class == C +end + +assert('Class 6') do + class A; end + class C < A; end + C.new.class.class == Class +end + +assert('Class Module 1') do + module M; end + M.class == Module +end + +assert('Class Module 2') do + module M; end + class C; include M; end + C.new.class == C +end + +# nested class +assert('Class Nested 1') do + class A; end + class A::B; end + A::B == A::B +end + +assert('Class Nested 2') do + class A; end + class A::B; end + A::B.new.class == A::B +end + +assert('Class Nested 3') do + class A; end + class A::B; end + A::B.new.class.class == Class +end + +assert('Class Nested 4') do + class A; end + class A::B; end + class A::B::C; end + A::B::C == A::B::C +end + +assert('Class Nested 5') do + class A; end + class A::B; end + class A::B::C; end + A::B::C.class == Class +end + +assert('Class Nested 6') do + class A; end + class A::B; end + class A::B::C; end + A::B::C.new.class == A::B::C +end + +assert('Class Nested 7') do + class A; end + class A::B; end + class A::B2 < A::B; end + A::B2 == A::B2 +end + +assert('Class Nested 8') do + class A; end + class A::B; end + class A::B2 < A::B; end + A::B2.class == Class +end + +assert('Class Colon 1') do + class A; end; A::C = 1; A::C == 1 +end + +assert('Class Colon 2') do + class A; class ::C; end end; C == C +end + +assert('Class Colon 3') do + class A; class ::C; end end; C.class == Class +end + +assert('Class Dup 1') do + class C; end; C.dup.class == Class +end + +assert('Class Dup 2') do + module M; end; M.dup.class == Module +end diff --git a/test/t/exception.rb b/test/t/exception.rb new file mode 100644 index 000000000..6b46314d0 --- /dev/null +++ b/test/t/exception.rb @@ -0,0 +1,195 @@ +## +# Exception ISO Test + +assert('Exception', '15.2.22') do + Exception.class == Class +end + +assert('Exception.exception', '15.2.22.4.1') do + e = Exception.exception('a') + + e.class == Exception +end + +assert('Exception#exception', '15.2.22.5.1') do + e1 = Exception.exception() + e2 = Exception.exception('b') + + e1.class == Exception and e2.class == Exception +end + +assert('Exception#message', '15.2.22.5.2') do + e = Exception.exception('a') + + e.message == 'a' +end + +assert('Exception#to_s', '15.2.22.5.3') do + e = Exception.exception('a') + + e.to_s == 'a' +end + +assert('Exception.exception', '15.2.22.4.1') do + e = Exception.exception() + e.initialize('a') + + e.message == 'a' +end + +# Not ISO specified + +assert('Exception 1') do + begin + 1+1 + ensure + 2+2 + end == 2 +end + +assert('Exception 2') do + begin + 1+1 + begin + 2+2 + ensure + 3+3 + end + ensure + 4+4 + end == 4 +end + +assert('Exception 3') do + begin + 1+1 + begin + 2+2 + ensure + 3+3 + end + ensure + 4+4 + begin + 5+5 + ensure + 6+6 + end + end == 4 +end + +assert('Exception 4') do + a = nil + 1.times{|e| + begin + rescue => err + end + a = err.class + } + a == NilClass +end + +assert('Exception 5') do + $ans = [] + def m + $! + end + def m2 + 1.times{ + begin + return + ensure + $ans << m + end + } + end + m2 + $ans == [nil] +end + +assert('Exception 6') do + $i = 0 + def m + iter{ + begin + $i += 1 + begin + $i += 2 + break + ensure + + end + ensure + $i += 4 + end + $i = 0 + } + end + + def iter + yield + end + m + $i == 7 +end + +assert('Exception 7') do + $i = 0 + def m + begin + $i += 1 + begin + $i += 2 + return + ensure + $i += 3 + end + ensure + $i += 4 + end + p :end + end + m + $i == 10 +end + +assert('Exception 8') do + begin + 1 + rescue + 2 + else + 3 + end == 3 +end + +assert('Exception 9') do + begin + 1+1 + rescue + 2+2 + else + 3+3 + ensure + 4+4 + end == 6 +end + +assert('Exception 10') do + begin + 1+1 + begin + 2+2 + rescue + 3+3 + else + 4+4 + end + rescue + 5+5 + else + 6+6 + ensure + 7+7 + end == 12 +end diff --git a/test/t/false.rb b/test/t/false.rb new file mode 100644 index 000000000..3fd885a7f --- /dev/null +++ b/test/t/false.rb @@ -0,0 +1,27 @@ +## +# FalseClass ISO Test + +assert('FalseClass', '15.2.6') do + FalseClass.class == Class +end + +assert('FalseClass false', '15.2.6.1') do + not false +end + +assert('FalseClass#&', '15.2.6.3.1') do + not FalseClass.new.&(true) and not FalseClass.new.&(false) +end + +assert('FalseClass#^', '15.2.6.3.2') do + FalseClass.new.^(true) and not FalseClass.new.^(false) +end + +assert('FalseClass#to_s', '15.2.6.3.3') do + FalseClass.new.to_s == 'false' +end + +assert('FalseClass#|', '15.2.6.3.4') do + FalseClass.new.|(true) and not FalseClass.new.|(false) +end + diff --git a/test/t/indexerror.rb b/test/t/indexerror.rb new file mode 100644 index 000000000..dcf9d283b --- /dev/null +++ b/test/t/indexerror.rb @@ -0,0 +1,7 @@ +## +# IndexError ISO Test + +assert('IndexError', '15.2.33') do + IndexError.class == Class +end + diff --git a/test/t/localjumperror.rb b/test/t/localjumperror.rb new file mode 100644 index 000000000..132acd81e --- /dev/null +++ b/test/t/localjumperror.rb @@ -0,0 +1,10 @@ +## +# LocalJumpError ISO Test + +assert('LocalJumoError', '15.2.25') do + LocalJumpError.class == Class +end + +# TODO 15.2.25.2.1 LocalJumpError#exit_value +# TODO 15.2.25.2.2 LocalJumpError#reason + diff --git a/test/t/module.rb b/test/t/module.rb new file mode 100644 index 000000000..f9efa553a --- /dev/null +++ b/test/t/module.rb @@ -0,0 +1,11 @@ +## +# Module ISO Test + +assert('Module', '15.2.2') do + Module.class == Class +end + +# TODO not implemented ATM assert('Module.constants', '15.2.2') do + +# TODO not implemented ATM assert('Module.nesting', '15.2.2') do + diff --git a/test/t/nameerror.rb b/test/t/nameerror.rb new file mode 100644 index 000000000..23158fce2 --- /dev/null +++ b/test/t/nameerror.rb @@ -0,0 +1,15 @@ +## +# NameError ISO Test + +assert('NameError', '15.2.31') do + NameError.class == Class +end + +# TODO 15.2.31.2.1 NameError#name + +assert('NameError#initialize', '15.2.31.2.2') do + e = NameError.new.initialize('a') + + e.class == NameError and e.message == 'a' +end + diff --git a/test/t/nil.rb b/test/t/nil.rb new file mode 100644 index 000000000..9a4855a62 --- /dev/null +++ b/test/t/nil.rb @@ -0,0 +1,27 @@ +## +# NilClass ISO Test + +assert('NilClass', '15.2.4') do + NilClass.class == Class +end + +assert('NilClass#&', '15.2.4.3.1') do + not NilClass.new.& and not NilClass.new.&(nil) +end + +assert('NilClass#^', '15.2.4.3.2') do + NilClass.new.^(true) and not NilClass.new.^(false) +end + +assert('NilClass#|', '15.2.4.3.3') do + NilClass.new.|(true) and not NilClass.new.|(false) +end + +assert('NilClass#nil?', '15.2.4.3.4') do + NilClass.new.nil? +end + +assert('NilClass#to_s', '15.2.4.3.5') do + NilClass.new.to_s == '' +end + diff --git a/test/t/nomethoderror.rb b/test/t/nomethoderror.rb new file mode 100644 index 000000000..4c4fb3fdf --- /dev/null +++ b/test/t/nomethoderror.rb @@ -0,0 +1,14 @@ +## +# NoMethodError ISO Test + +assert('NoMethodError', '15.2.32') do + e2 = nil + begin + doesNotExistAsAMethodNameForVerySure("") + rescue => e1 + e2 = e1 + end + + NoMethodError.class == Class and e2.class == NoMethodError +end + diff --git a/test/t/object.rb b/test/t/object.rb new file mode 100644 index 000000000..8d9938a48 --- /dev/null +++ b/test/t/object.rb @@ -0,0 +1,7 @@ +## +# Object ISO Test + +assert('Object', '15.2.1') do + Object.class == Class +end + diff --git a/test/t/proc.rb b/test/t/proc.rb new file mode 100644 index 000000000..68d8ca8f6 --- /dev/null +++ b/test/t/proc.rb @@ -0,0 +1,45 @@ +## +# Proc ISO Test + +assert('Proc', '15.2.17') do + Proc.class == Class +end + +assert('Proc.new', '15.2.17.3.1') do + a = nil + + begin + Proc.new + rescue => e + a = e + end + + b = Proc.new {} + + a.class == ArgumentError and b.class == Proc +end + +assert('Proc#[]', '15.2.17.4.1') do + a = 0 + b = Proc.new { a += 1 } + b.[] + + a2 = 0 + b2 = Proc.new { |i| a2 += i } + b2.[](5) + + a == 1 and a2 == 5 +end + +assert('Proc#call', '15.2.17.4.3') do + a = 0 + b = Proc.new { a += 1 } + b.call + + a2 = 0 + b2 = Proc.new { |i| a2 += i } + b2.call(5) + + a == 1 and a2 == 5 +end + diff --git a/test/t/rangeerror.rb b/test/t/rangeerror.rb new file mode 100644 index 000000000..da8e9bf88 --- /dev/null +++ b/test/t/rangeerror.rb @@ -0,0 +1,7 @@ +## +# RangeError ISO Test + +assert('RangeError', '15.2.26') do + RangeError.class == Class +end + diff --git a/test/t/regexperror.rb b/test/t/regexperror.rb new file mode 100644 index 000000000..2ce2edd7f --- /dev/null +++ b/test/t/regexperror.rb @@ -0,0 +1,5 @@ +## +# RegexpError ISO Test + +# TODO broken ATM assert('RegexpError', '15.2.27') do + diff --git a/test/t/runtimeerror.rb b/test/t/runtimeerror.rb new file mode 100644 index 000000000..b410dd64f --- /dev/null +++ b/test/t/runtimeerror.rb @@ -0,0 +1,15 @@ +## +# RuntimeError ISO Test + +assert('RuntimeError', '15.2.28') do + e2 = nil + begin + # this will cause an exception due to the wrong location + retry + rescue => e1 + e2 = e1 + end + + RuntimeError.class == Class and e2.class == RuntimeError +end + diff --git a/test/t/standarderror.rb b/test/t/standarderror.rb new file mode 100644 index 000000000..f6c63ac12 --- /dev/null +++ b/test/t/standarderror.rb @@ -0,0 +1,7 @@ +## +# StandardError ISO Test + +assert('StandardError', '15.2.23') do + StandardError.class == Class +end + diff --git a/test/t/struct.rb b/test/t/struct.rb new file mode 100644 index 000000000..04279d532 --- /dev/null +++ b/test/t/struct.rb @@ -0,0 +1,7 @@ +## +# Struct ISO Test + +assert('Struct', '15.2.18') do + Struct.class == Class +end + diff --git a/test/t/true.rb b/test/t/true.rb new file mode 100644 index 000000000..af4caeeec --- /dev/null +++ b/test/t/true.rb @@ -0,0 +1,27 @@ +## +# TrueClass ISO Test + +assert('TrueClass', '15.2.5') do + TrueClass.class == Class +end + +assert('TrueClass true', '15.2.5.1') do + true +end + +assert('TrueClass#&', '15.2.5.3.1') do + TrueClass.new.&(true) and not TrueClass.new.&(false) +end + +assert('TrueClass#^', '15.2.5.3.2') do + not TrueClass.new.^(true) and TrueClass.new.^(false) +end + +assert('TrueClass#to_s', '15.2.5.3.3') do + TrueClass.new.to_s == 'true' +end + +assert('TrueClass#|', '15.2.5.3.4') do + TrueClass.new.|(true) and TrueClass.new.|(false) +end + diff --git a/test/t/typeerror.rb b/test/t/typeerror.rb new file mode 100644 index 000000000..12cf64e70 --- /dev/null +++ b/test/t/typeerror.rb @@ -0,0 +1,7 @@ +## +# TypeError ISO Test + +assert('TypeError', '15.2.29') do + TypeError.class == Class +end + -- cgit v1.2.3 From 74fb270298225c392ec1b31a29f1ef10a36925c3 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 27 May 2012 00:50:39 +0800 Subject: add Enumerable tests and identify data corruption with merge in Hash --- test/t/enumerable.rb | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 test/t/enumerable.rb (limited to 'test/t') diff --git a/test/t/enumerable.rb b/test/t/enumerable.rb new file mode 100644 index 000000000..909531045 --- /dev/null +++ b/test/t/enumerable.rb @@ -0,0 +1,74 @@ +## +# Enumerable ISO Test + +assert('Enumerable', '15.3.2') do + Enumerable.class == Module +end + +assert('Enumerable#all?', '15.3.2.2.1') do + [1,2,3].all? and not [1,false,3].all? +end + +assert('Enumerable#any?', '15.3.2.2.2') do + [false,true,false].any? and not [false,false,false].any? +end + +assert('Enumerable#collect', '15.3.2.2.3') do + [1,2,3].collect { |i| i + i } == [2,4,6] +end + +assert('Enumerable#detect', '15.3.2.2.4') do + [1,2,3].detect() { true } and [1,2,3].detect("a") { false } == 'a' +end + +assert('Array#each_with_index', '15.3.2.2.5') do + a = nil + b = nil + + [1].each_with_index {|e,i| a = e; b = i} + + a == 1 and b == 0 +end + +assert('Enumerable#entries', '15.3.2.2.6') do + [1].entries == [1] +end + +assert('Enumerable#find', '15.3.2.2.7') do + [1,2,3].find() { true } and [1,2,3].find("a") { false } == 'a' +end + +assert('Enumerable#find_all', '15.3.2.2.8') do + [1,2,3,4,5,6,7,8,9].find_all() {|i| i%2 == 0} == [2,4,6,8] +end + +assert('Enumerable#grep', '15.3.2.2.9') do + [1,2,3,4,5,6,7,8,9].grep(4..6) == [4,5,6] +end + +assert('Enumerable#include?', '15.3.2.2.10') do + [1,2,3,4,5,6,7,8,9].include?(5) and + not [1,2,3,4,5,6,7,8,9].include?(0) +end + +assert('Enumerable#inject', '15.3.2.2.11') do + [1,2,3,4,5,6].inject() {|s, n| s + n} == 21 and + [1,2,3,4,5,6].inject(1) {|s, n| s + n} == 22 +end + +assert('Enumerable#map', '15.3.2.2.12') do + [1,2,3].map { |i| i + i } == [2,4,6] +end + +assert('Enumerable#max', '15.3.2.2.13') do + a = ['aaa', 'bb', 'c'] + a.max == 'c' and + a.max {|i1,i2| i1.length <=> i2.length} == 'aaa' +end + +assert('Enumerable#min', '15.3.2.2.14') do + a = ['aaa', 'bb', 'c'] + a.min == 'aaa' and + a.min {|i1,i2| i1.length <=> i2.length} == 'c' +end + -- cgit v1.2.3 From 31e9705022d585d818a5c869f0f91e4d6b7c252e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 29 May 2012 01:20:46 +0800 Subject: Add Test cases for Literals, Enumeration, Exceptions and clean line endings --- test/t/argumenterror.rb | 12 ++++++++++-- test/t/array.rb | 42 ++++++++++++++++++++++++++++++++++++++---- test/t/bs_block.rb | 1 - test/t/bs_literal.rb | 1 - test/t/enumerable.rb | 29 +++++++++++++++++++++++++++++ test/t/false.rb | 1 - test/t/float.rb | 1 - test/t/hash.rb | 1 - test/t/indexerror.rb | 1 - test/t/integer.rb | 1 - test/t/kernel.rb | 1 - test/t/localjumperror.rb | 1 - test/t/module.rb | 1 - test/t/nameerror.rb | 1 - test/t/nil.rb | 1 - test/t/nomethoderror.rb | 1 - test/t/numeric.rb | 1 - test/t/object.rb | 1 - test/t/proc.rb | 1 - test/t/range.rb | 1 - test/t/rangeerror.rb | 1 - test/t/regexperror.rb | 1 - test/t/runtimeerror.rb | 1 - test/t/standarderror.rb | 1 - test/t/string.rb | 1 - test/t/struct.rb | 1 - test/t/symbol.rb | 1 - test/t/time.rb | 1 - test/t/true.rb | 1 - test/t/typeerror.rb | 1 - 30 files changed, 77 insertions(+), 33 deletions(-) (limited to 'test/t') diff --git a/test/t/argumenterror.rb b/test/t/argumenterror.rb index be1dec974..ca998f8de 100644 --- a/test/t/argumenterror.rb +++ b/test/t/argumenterror.rb @@ -2,6 +2,14 @@ # ArgumentError ISO Test assert('ArgumentError', '15.2.24') do - ArgumentError.class == Class -end + e2 = nil + a = [] + begin + # this will cause an exception due to the wrong arguments + a[] + rescue => e1 + e2 = e1 + end + ArgumentError.class == Class and e2.class == ArgumentError +end diff --git a/test/t/array.rb b/test/t/array.rb index 3b9dfedfb..dba1b035d 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -22,11 +22,47 @@ assert('Array#<<', '15.2.12.5.3') do end assert('Array#[]', '15.2.12.5.4') do - [1,2,3].[](1) == 2 + e2 = nil + e3 = nil + a = Array.new + begin + # this will cause an exception due to the wrong arguments + a.[]() + rescue => e1 + e2 = e1 + end + begin + # this will cause an exception due to the wrong arguments + a.[](1,2,3) + rescue => e1 + e3 = e1 + end + + [1,2,3].[](1) == 2 and + e2.class == ArgumentError and + e3.class == ArgumentError end assert('Array#[]=', '15.2.12.5.5') do - [1,2,3].[]=(1,4) == [1, 4, 3] + e2 = nil + e3 = nil + a = Array.new + begin + # this will cause an exception due to the wrong arguments + a.[]=() + rescue => e1 + e2 = e1 + end + begin + # this will cause an exception due to the wrong arguments + a.[]=(1,2,3,4) + rescue => e1 + e3 = e1 + end + + [1,2,3].[]=(1,4) == [1, 4, 3] and + e2.class == ArgumentError and + e3.class == ArgumentError end assert('Array#clear', '15.2.12.5.6') do @@ -193,5 +229,3 @@ assert('Array#unshift', '15.2.12.5.30') do end # Not ISO specified - - diff --git a/test/t/bs_block.rb b/test/t/bs_block.rb index acbade449..b290cb914 100644 --- a/test/t/bs_block.rb +++ b/test/t/bs_block.rb @@ -388,4 +388,3 @@ assert('BS Block [ruby-core:14395]') do t = Controller.new t.test_for_bug end - diff --git a/test/t/bs_literal.rb b/test/t/bs_literal.rb index b1ae3a5d6..842d8704c 100644 --- a/test/t/bs_literal.rb +++ b/test/t/bs_literal.rb @@ -36,4 +36,3 @@ end assert('BS Literal 9') do Fixnum == 1234.class end - diff --git a/test/t/enumerable.rb b/test/t/enumerable.rb index 909531045..de0bb5a34 100644 --- a/test/t/enumerable.rb +++ b/test/t/enumerable.rb @@ -72,3 +72,32 @@ assert('Enumerable#min', '15.3.2.2.14') do a.min {|i1,i2| i1.length <=> i2.length} == 'c' end +assert('Enumerable#member?', '15.3.2.2.15') do + [1,2,3,4,5,6,7,8,9].member?(5) and + not [1,2,3,4,5,6,7,8,9].member?(0) +end + +assert('Enumerable#partion', '15.3.2.2.16') do + [0,1,2,3,4,5,6,7,8,9].partition do |i| + i % 2 == 0 + end == [[0,2,4,6,8], [1,3,5,7,9]] +end + +assert('Enumerable#reject', '15.3.2.2.17') do + [0,1,2,3,4,5,6,7,8,9].reject do |i| + i % 2 == 0 + end == [1,3,5,7,9] +end + +assert('Enumerable#select', '15.3.2.2.18') do + [1,2,3,4,5,6,7,8,9].select() {|i| i%2 == 0} == [2,4,6,8] +end + +assert('Enumerable#sort', '15.3.2.2.19') do + [7,3,1,2,6,4].sort == [1,2,3,4,6,7] and + [7,3,1,2,6,4].sort {|e1,e2| e2<=>e1} == [7,6,4,3,2,1] +end + +assert('Enumerable#to_a', '15.3.2.2.20') do + [1].to_a == [1] +end diff --git a/test/t/false.rb b/test/t/false.rb index 3fd885a7f..c2db283c8 100644 --- a/test/t/false.rb +++ b/test/t/false.rb @@ -24,4 +24,3 @@ end assert('FalseClass#|', '15.2.6.3.4') do FalseClass.new.|(true) and not FalseClass.new.|(false) end - diff --git a/test/t/float.rb b/test/t/float.rb index fd87bb04f..fc87a5b22 100644 --- a/test/t/float.rb +++ b/test/t/float.rb @@ -99,4 +99,3 @@ end assert('Float#truncate', '15.2.9.3.15') do 3.123456789.truncate == 3 end - diff --git a/test/t/hash.rb b/test/t/hash.rb index bb2ef1209..af662688a 100644 --- a/test/t/hash.rb +++ b/test/t/hash.rb @@ -224,4 +224,3 @@ assert('Hash#values', '15.2.13.4.28') do a.values == ['abc_value'] end - diff --git a/test/t/indexerror.rb b/test/t/indexerror.rb index dcf9d283b..d0cb81f32 100644 --- a/test/t/indexerror.rb +++ b/test/t/indexerror.rb @@ -4,4 +4,3 @@ assert('IndexError', '15.2.33') do IndexError.class == Class end - diff --git a/test/t/integer.rb b/test/t/integer.rb index 5e73b41b5..8c112861a 100644 --- a/test/t/integer.rb +++ b/test/t/integer.rb @@ -168,4 +168,3 @@ assert('Integer#upto', '15.2.8.3.27') do end a == 6 end - diff --git a/test/t/kernel.rb b/test/t/kernel.rb index eda07074b..cd1f2d99e 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -122,4 +122,3 @@ assert('Kernel#to_s', '15.3.1.2.46') do # TODO looks strange.. to_s == '' end - diff --git a/test/t/localjumperror.rb b/test/t/localjumperror.rb index 132acd81e..9d1df9594 100644 --- a/test/t/localjumperror.rb +++ b/test/t/localjumperror.rb @@ -7,4 +7,3 @@ end # TODO 15.2.25.2.1 LocalJumpError#exit_value # TODO 15.2.25.2.2 LocalJumpError#reason - diff --git a/test/t/module.rb b/test/t/module.rb index f9efa553a..854be75a5 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -8,4 +8,3 @@ end # TODO not implemented ATM assert('Module.constants', '15.2.2') do # TODO not implemented ATM assert('Module.nesting', '15.2.2') do - diff --git a/test/t/nameerror.rb b/test/t/nameerror.rb index 23158fce2..67451ecf8 100644 --- a/test/t/nameerror.rb +++ b/test/t/nameerror.rb @@ -12,4 +12,3 @@ assert('NameError#initialize', '15.2.31.2.2') do e.class == NameError and e.message == 'a' end - diff --git a/test/t/nil.rb b/test/t/nil.rb index 9a4855a62..3188a9516 100644 --- a/test/t/nil.rb +++ b/test/t/nil.rb @@ -24,4 +24,3 @@ end assert('NilClass#to_s', '15.2.4.3.5') do NilClass.new.to_s == '' end - diff --git a/test/t/nomethoderror.rb b/test/t/nomethoderror.rb index 4c4fb3fdf..9eb122158 100644 --- a/test/t/nomethoderror.rb +++ b/test/t/nomethoderror.rb @@ -11,4 +11,3 @@ assert('NoMethodError', '15.2.32') do NoMethodError.class == Class and e2.class == NoMethodError end - diff --git a/test/t/numeric.rb b/test/t/numeric.rb index 40b5845c0..924889a0e 100644 --- a/test/t/numeric.rb +++ b/test/t/numeric.rb @@ -22,4 +22,3 @@ end assert('Numeric#**') do 2.0**3 == 8.0 end - diff --git a/test/t/object.rb b/test/t/object.rb index 8d9938a48..96929031b 100644 --- a/test/t/object.rb +++ b/test/t/object.rb @@ -4,4 +4,3 @@ assert('Object', '15.2.1') do Object.class == Class end - diff --git a/test/t/proc.rb b/test/t/proc.rb index 68d8ca8f6..6d98cb40c 100644 --- a/test/t/proc.rb +++ b/test/t/proc.rb @@ -42,4 +42,3 @@ assert('Proc#call', '15.2.17.4.3') do a == 1 and a2 == 5 end - diff --git a/test/t/range.rb b/test/t/range.rb index 42677e72e..05bac8779 100644 --- a/test/t/range.rb +++ b/test/t/range.rb @@ -62,4 +62,3 @@ assert('Range#member?', '15.2.14.4.11') do a.member?(5) and not a.member?(20) end - diff --git a/test/t/rangeerror.rb b/test/t/rangeerror.rb index da8e9bf88..7edb5d2d9 100644 --- a/test/t/rangeerror.rb +++ b/test/t/rangeerror.rb @@ -4,4 +4,3 @@ assert('RangeError', '15.2.26') do RangeError.class == Class end - diff --git a/test/t/regexperror.rb b/test/t/regexperror.rb index 2ce2edd7f..b8f8c2c1f 100644 --- a/test/t/regexperror.rb +++ b/test/t/regexperror.rb @@ -2,4 +2,3 @@ # RegexpError ISO Test # TODO broken ATM assert('RegexpError', '15.2.27') do - diff --git a/test/t/runtimeerror.rb b/test/t/runtimeerror.rb index b410dd64f..9157293cd 100644 --- a/test/t/runtimeerror.rb +++ b/test/t/runtimeerror.rb @@ -12,4 +12,3 @@ assert('RuntimeError', '15.2.28') do RuntimeError.class == Class and e2.class == RuntimeError end - diff --git a/test/t/standarderror.rb b/test/t/standarderror.rb index f6c63ac12..550c337c1 100644 --- a/test/t/standarderror.rb +++ b/test/t/standarderror.rb @@ -4,4 +4,3 @@ assert('StandardError', '15.2.23') do StandardError.class == Class end - diff --git a/test/t/string.rb b/test/t/string.rb index 7fd48761c..76df18aaf 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -319,4 +319,3 @@ assert('String#upcase!', '15.2.10.5.43') do a == 'ABC' end - diff --git a/test/t/struct.rb b/test/t/struct.rb index 04279d532..c41319f8a 100644 --- a/test/t/struct.rb +++ b/test/t/struct.rb @@ -4,4 +4,3 @@ assert('Struct', '15.2.18') do Struct.class == Class end - diff --git a/test/t/symbol.rb b/test/t/symbol.rb index 325c8d990..e9c310971 100644 --- a/test/t/symbol.rb +++ b/test/t/symbol.rb @@ -20,4 +20,3 @@ end assert('Symbol#to_sym', '15.2.11.3.4') do :abc.to_sym == :abc end - diff --git a/test/t/time.rb b/test/t/time.rb index 9ad0e4aff..22fc2e7c3 100644 --- a/test/t/time.rb +++ b/test/t/time.rb @@ -71,4 +71,3 @@ end assert('Time#new') do Time.new.class == Time end - diff --git a/test/t/true.rb b/test/t/true.rb index af4caeeec..bb648a7cd 100644 --- a/test/t/true.rb +++ b/test/t/true.rb @@ -24,4 +24,3 @@ end assert('TrueClass#|', '15.2.5.3.4') do TrueClass.new.|(true) and TrueClass.new.|(false) end - diff --git a/test/t/typeerror.rb b/test/t/typeerror.rb index 12cf64e70..c4434aa24 100644 --- a/test/t/typeerror.rb +++ b/test/t/typeerror.rb @@ -4,4 +4,3 @@ assert('TypeError', '15.2.29') do TypeError.class == Class end - -- cgit v1.2.3 From b19575e5ac1e15c83797a0d8974bc4cc02b83fe6 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 29 May 2012 01:33:17 +0800 Subject: Forgot Literals file --- test/t/literals.rb | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/t/literals.rb (limited to 'test/t') diff --git a/test/t/literals.rb b/test/t/literals.rb new file mode 100644 index 000000000..92f9bd755 --- /dev/null +++ b/test/t/literals.rb @@ -0,0 +1,49 @@ +## +# Literals ISO Test + +assert('Literals Numerical', '8.7.6.2') do + # signed and unsigned integer + 1 == 1 and -1 == -1 and +1 == +1 and + # signed and unsigned float + 1.0 == 1.0 and -1.0 == -1.0 and + # binary + 0b10000000 == 128 and 0B10000000 == 128 + # octal + 0o10 == 8 and 0O10 == 8 and 0_10 == 8 + # hex + 0xff == 255 and 0Xff == 255 and + # decimal + 0d999 == 999 and 0D999 == 999 and + # decimal seperator + 10_000_000 == 10000000 and 1_0 == 10 and + # integer with exponent + 1e1 == 10.0 and 1e-1 == 0.1 and 1e+1 == 10.0 + # float with exponent + 1.0e1 == 10.0 and 1.0e-1 == 0.1 and 1.0e+1 == 10.0 +end + +#assert('Literals Strings Single Quoted', '8.7.6.3.2') do +# creates segmentation fault for now +# 'abc' == 'abc' and '\'' == '\'' and '\\' == '\\' +#end + +assert('Literals Strings Double Quoted', '8.7.6.3.3') do + a = "abc" + + "abc" == "abc" and "\"" == "\"" and "\\" == "\\" and + "#{a}" == "abc" +end + +#creates segmentation fault for now +#assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do +# a = %q{abc} +# b = %q(abc) +# c = %q[abc] +# d = %q +# e = %/abc/ +# f = %/ab\/c/ + +# a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and +# e == 'abc' and f 'ab/c' +#end + -- cgit v1.2.3 From 61a47e344db34211c8d299660d6e0eabc4463d4b Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 29 May 2012 07:23:17 +0800 Subject: Raise SEGV by using String literal --- test/t/literals.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'test/t') diff --git a/test/t/literals.rb b/test/t/literals.rb index 92f9bd755..477e499a0 100644 --- a/test/t/literals.rb +++ b/test/t/literals.rb @@ -22,10 +22,9 @@ assert('Literals Numerical', '8.7.6.2') do 1.0e1 == 10.0 and 1.0e-1 == 0.1 and 1.0e+1 == 10.0 end -#assert('Literals Strings Single Quoted', '8.7.6.3.2') do -# creates segmentation fault for now -# 'abc' == 'abc' and '\'' == '\'' and '\\' == '\\' -#end +assert('Literals Strings Single Quoted', '8.7.6.3.2') do + 'abc' == 'abc' and '\'' == '\'' and '\\' == '\\' +end assert('Literals Strings Double Quoted', '8.7.6.3.3') do a = "abc" -- cgit v1.2.3 From b92f302d59aa4fbbbf0dba3e6ea59cda4a27e367 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 29 May 2012 13:52:59 +0800 Subject: SEGV by adding a new assert --- test/t/literals.rb | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'test/t') diff --git a/test/t/literals.rb b/test/t/literals.rb index 477e499a0..1f755863a 100644 --- a/test/t/literals.rb +++ b/test/t/literals.rb @@ -33,16 +33,20 @@ assert('Literals Strings Double Quoted', '8.7.6.3.3') do "#{a}" == "abc" end -#creates segmentation fault for now -#assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do -# a = %q{abc} -# b = %q(abc) -# c = %q[abc] -# d = %q -# e = %/abc/ -# f = %/ab\/c/ - -# a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and -# e == 'abc' and f 'ab/c' -#end +assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do + a = %q{abc} + b = %q(abc) + c = %q[abc] + d = %q + e = %q/abc/ + f = %q/ab\/c/ + + a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and + e == 'abc' and f == 'ab/c' +end + +assert('Literals Strings Quoted Expanded', '8.7.6.3.5') do + # segv atm + true +end -- cgit v1.2.3 From 82d600da24bb0866472126b4117c55dda773908d Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 29 May 2012 23:51:51 +0800 Subject: Add literal tests for currently working String literals and make notice about literals which yet need to be proper implementation --- test/t/literals.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'test/t') diff --git a/test/t/literals.rb b/test/t/literals.rb index 1f755863a..700c4c846 100644 --- a/test/t/literals.rb +++ b/test/t/literals.rb @@ -46,7 +46,22 @@ assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do end assert('Literals Strings Quoted Expanded', '8.7.6.3.5') do - # segv atm - true + a = %Q{abc} + b = %Q(abc) + c = %Q[abc] + d = %Q + e = %Q/abc/ + f = %Q/ab\/c/ + g = %Q{#{a}} + + a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and + e == 'abc' and f == 'ab/c' and g == 'abc' end +# Not Implemented ATM assert('Literals Strings Here documents', '8.7.6.3.6') do + +# Not Implemented ATM assert('Literals Array', '8.7.6.4') do + +# Not Implemented ATM assert('Literals Regular expression', '8.7.6.5') do + +# Not Implemented ATM assert('Literals Symbol', '8.7.6.6') do -- cgit v1.2.3