From 83d04a539e3e765b2e82d02cfbcde4a77808eb29 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 9 Jun 2013 03:51:44 +0800 Subject: Improve undef tests --- test/t/methods.rb | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/t/methods.rb (limited to 'test/t/methods.rb') diff --git a/test/t/methods.rb b/test/t/methods.rb new file mode 100644 index 000000000..701ebe326 --- /dev/null +++ b/test/t/methods.rb @@ -0,0 +1,65 @@ +## +# Chapter 13 "Class and modules" ISO Test + +assert('The undef statement', '13.3.7 a) 4)') do + # check that undef is undefining method + # based on the method name + + def existing_method_a; true; end + def existing_method_b; true; end + def existing_method_c; true; end + def existing_method_d; true; end + def existing_method_e; true; end + def existing_method_f; true; end + + # check that methods are defined + + assert_true(existing_method_a, 'Method should be defined') + assert_true(existing_method_b, 'Method should be defined') + assert_true(existing_method_c, 'Method should be defined') + assert_true(existing_method_d, 'Method should be defined') + assert_true(existing_method_e, 'Method should be defined') + assert_true(existing_method_f, 'Method should be defined') + + # undefine in all possible ways and check that method + # is undefined + + undef existing_method_a + assert_raise(NoMethodError) do + existing_method_a + end + + undef :existing_method_b + assert_raise(NoMethodError) do + existing_method_b + end + + undef existing_method_c, existing_method_d + assert_raise(NoMethodError) do + existing_method_c + end + assert_raise(NoMethodError) do + existing_method_d + end + + undef :existing_method_e, :existing_method_f + assert_raise(NoMethodError) do + existing_method_e + end + assert_raise(NoMethodError) do + existing_method_f + end +end + +assert('The undef statement (method undefined)', '13.3.7 a) 5)') do + # check that undef is raising NameError if + # non-existing method should be undefined + + assert_raise(NameError) do + undef non_existing_method + end + + assert_raise(NameError) do + undef :non_existing_method + end +end -- cgit v1.2.3 From 39b6d087c7fdcc5d02d42ec0de7fca5b23b4fb77 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 9 Jun 2013 04:04:19 +0800 Subject: Improve alias tests --- test/t/class.rb | 23 ----------------------- test/t/methods.rb | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 24 deletions(-) (limited to 'test/t/methods.rb') diff --git a/test/t/class.rb b/test/t/class.rb index e6d7128fa..eb470e416 100644 --- a/test/t/class.rb +++ b/test/t/class.rb @@ -229,26 +229,3 @@ end assert('Class Dup 2') do module M; end; M.dup.class == Module end - -assert('Class Alias 1') do - class A - def test; 1; end - - alias test2 test - alias :test3 :test - end - - A.new.test2 == 1 and A.new.test3 == 1 -end - -assert('Class Alias 2') do - class A - def test; 1; end - - alias test2 test - - def test; 2; end - end - - A.new.test == 2 and A.new.test2 == 1 -end diff --git a/test/t/methods.rb b/test/t/methods.rb index 701ebe326..bbd8ee09d 100644 --- a/test/t/methods.rb +++ b/test/t/methods.rb @@ -1,5 +1,49 @@ ## -# Chapter 13 "Class and modules" ISO Test +# Chapter 13.3 "Methods" ISO Test + +assert('The alias statement', '13.3.6 a) 4)') do + # check aliasing in all possible ways + + def alias_test_method_original; true; end + + alias alias_test_method_a alias_test_method_original + alias :alias_test_method_b :alias_test_method_original + + assert_true(alias_test_method_original) + assert_true(alias_test_method_a) + assert_true(alias_test_method_b) +end + +assert('The alias statement (overwrite original)', '13.3.6 a) 4)') do + # check that an aliased method can be overwritten + # without side effect + + def alias_test_method_original; true; end + + alias alias_test_method_a alias_test_method_original + alias :alias_test_method_b :alias_test_method_original + + assert_true(alias_test_method_original) + + def alias_test_method_original; false; end + + assert_false(alias_test_method_original) + assert_true(alias_test_method_a) + assert_true(alias_test_method_b) +end + +assert('The alias statement', '13.3.6 a) 5)') do + # check that alias is raising NameError if + # non-existing method should be undefined + + assert_raise(NameError) do + alias new_name_a non_existing_method + end + + assert_raise(NameError) do + alias :new_name_b :non_existing_method + end +end assert('The undef statement', '13.3.7 a) 4)') do # check that undef is undefining method -- cgit v1.2.3