Fix for JRUBY-2882. Handle error messages related to constructors better
[jruby.git] / test / testNesting.rb
blob7a38331b53c89e0308559d870f5b826baf0a1141
1 require 'test/minirunit'
3 class Object
4   def add(name, c)
5     class_eval("#{name} = c")
6   end
7 end
9 module A1
10   add("FOO", String)
11   def do
12     FOO.new("foo")
13   end
14 end
16 class B1
17   include A1
18 end
20 test_equal(["FOO"], A1.constants)
21 test_equal(["FOO"], B1.constants)
22 test_equal(B1.const_get("FOO"), String)
23 test_equal("foo", B1.new.do)
25 # tests nesting of classes inside modues
26 module A2
27   class B2
28     add("FOO", String)
29     def do
30       FOO.new("foo")
31     end
32   end
33 end
35 test_equal(["FOO"], A2::B2.constants)
36 test_equal(A2::B2.const_get("FOO"), String)
37 test_equal("foo", A2::B2.new.do)
39 # confirm class_eval is nested the same as the calling scope
40 class A3
41   class B3
42     test_equal([A3::B3, A3], Module.nesting)
43   end
44 end
46 test_equal([A3::B3], A3::B3.class_eval("Module.nesting"))
48 class C3
49   test_equal([A3::B3, C3], A3::B3.class_eval("Module.nesting"))
50 end
52 # tests lookup of :: scoped classes
53 class A4
54   class B4
55   end
56 end
58 class A4::B4
59   class ::A4
60     test_ok(self == A4)
61     def foo
62       "foo"
63     end
64   end
65   
66   class ::C4
67   end
68 end
70 test_equal("foo", A4.new.foo)
71 test_ok(C4)