Navigation Menu

Skip to content

Commit

Permalink
Add some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
monaka committed Apr 6, 2013
1 parent e885e59 commit d1b131e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
15 changes: 15 additions & 0 deletions test/t/comparable.rb
Expand Up @@ -54,3 +54,18 @@ def <=>(x)
(Foo.new >= Foo.new) == true
end

assert('Comparable#between?', '15.3.3.2.6') do
class Foo
include Comparable
def <=>(x)
x
end
end

c = Foo.new
c.between?(-1, 1) == false &&
c.between?(-1, -1) == false &&
c.between?( 1, 1) == false &&
c.between?( 1, -1) == true &&
c.between?(0, 0) == true
end
23 changes: 22 additions & 1 deletion test/t/kernel.rb
Expand Up @@ -155,6 +155,16 @@ def a.test
a.set(2)
c = a.clone

immutables = [ 1, :foo, true, false, nil ]
error_count = 0
immutables.each do |i|
begin
i.clone
rescue TypeError
error_count += 1
end
end

a.get == 2 and b.get == 1 and c.get == 2 &&
a.respond_to?(:test) == true and
b.respond_to?(:test) == false and
Expand Down Expand Up @@ -185,7 +195,18 @@ def a.test
a.set(2)
c = a.dup

a.get == 2 and b.get == 1 and c.get == 2 and
immutables = [ 1, :foo, true, false, nil ]
error_count = 0
immutables.each do |i|
begin
i.dup
rescue TypeError
error_count += 1
end
end

error_count == immutables.size and
a.get == 2 and b.get == 1 and c.get == 2 and
a.respond_to?(:test) == true and
b.respond_to?(:test) == false and
c.respond_to?(:test) == false
Expand Down
23 changes: 23 additions & 0 deletions test/t/module.rb
Expand Up @@ -297,6 +297,29 @@ def hello
not Test4RemoveMethod::Child.instance_methods(false).include? :hello
end

assert('Module.undef_method', '15.2.2.4.42') do
module Test4UndefMethod
class Parent
def hello
end
end

class Child < Parent
def hello
end
end

class GrandChild < Child
end
end

Test4UndefMethod::Child.class_eval{ undef_method :hello }

Test4UndefMethod::Parent.new.respond_to?(:hello) and
not Test4UndefMethod::Child.new.respond_to?(:hello) and
not Test4UndefMethod::GrandChild.new.respond_to?(:hello)
end


# Not ISO specified

Expand Down

0 comments on commit d1b131e

Please sign in to comment.