~ubuntu-branches/ubuntu/lucid/jruby/lucid

« back to all changes in this revision

Viewing changes to test/testClasses.rb

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Delafond
  • Date: 2009-12-09 17:30:55 UTC
  • Revision ID: james.westby@ubuntu.com-20091209173055-8ffzikq1768gywux
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'test/minirunit'
 
2
test_check "Test Classes"
 
3
class Hello
 
4
  def saveHelloWorld
 
5
    @hello = "Hello World."
 
6
  end
 
7
  def getHelloWorld
 
8
    @hello
 
9
  end
 
10
end
 
11
 
 
12
hello = Hello.new
 
13
test_equal("Hello World." , hello.saveHelloWorld)
 
14
test_equal("Hello World." , hello.getHelloWorld)
 
15
 
 
16
c = Class.new
 
17
test_equal(Object, c.superclass)
 
18
c = Class.new(String)
 
19
test_equal(String, c.superclass)
 
20
test_exception(TypeError) {
 
21
  Class.new(Kernel)
 
22
}
 
23
 
 
24
module TestClasses
 
25
  testClass = Class.new
 
26
 
 
27
  TestClass = testClass
 
28
  test_equal('TestClasses::TestClass', testClass.name)
 
29
 
 
30
  DifferentNameForTestClass = testClass
 
31
  test_equal('TestClasses::TestClass', testClass.name)
 
32
 
 
33
  testModule = Module.new
 
34
 
 
35
  TestModule = testModule
 
36
  test_equal('TestClasses::TestModule', testModule.name)
 
37
 
 
38
  DifferentNameForTestModule = testModule
 
39
  test_equal('TestClasses::TestModule', testModule.name)
 
40
 
 
41
  def TestClasses.virtual
 
42
    class << self
 
43
      self
 
44
    end
 
45
  end
 
46
end
 
47
 
 
48
begin
 
49
  class X < Foo::Bar
 
50
  end
 
51
  fail
 
52
rescue NameError => e
 
53
  test_equal("uninitialized constant Foo", e.to_s)
 
54
end
 
55
 
 
56
begin
 
57
  class X < TestClasses::Bar
 
58
  end
 
59
  fail
 
60
rescue NameError => e
 
61
  test_equal("uninitialized constant TestClasses::Bar", e.to_s)
 
62
end
 
63
 
 
64
begin
 
65
  class X < Class
 
66
  end
 
67
  fail
 
68
rescue TypeError => e
 
69
  test_equal("can't make subclass of Class", e.to_s)
 
70
end
 
71
 
 
72
begin 
 
73
  class X < TestClasses.virtual
 
74
  end
 
75
rescue TypeError => e
 
76
  test_equal("can't make subclass of virtual class", e.to_s)
 
77
end
 
78
 
 
79
class MockObject
 
80
  def self.mock methodName
 
81
    define_method "showBug" do 
 
82
      @results ||= {}
 
83
      @results["C"] = "Z"
 
84
      fail "Hash should have something" if @results == {}
 
85
      @results ||= {}
 
86
      fail "||= destroyed a perfectly good hash" if @results == {}
 
87
    end
 
88
  end
 
89
  mock :foo
 
90
end
 
91
 
 
92
mock = MockObject.new
 
93
mock.showBug