Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.ruby.test/src/com/oracle/truffle/ruby/test/language/ClassTests.java @ 13514:0fbee3eb71f0
Ruby: import project.
author | Chris Seaton <chris.seaton@oracle.com> |
---|---|
date | Mon, 06 Jan 2014 17:12:09 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13513:64a23ce736a0 | 13514:0fbee3eb71f0 |
---|---|
1 /* | |
2 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. This | |
3 * code is released under a tri EPL/GPL/LGPL license. You can use it, | |
4 * redistribute it and/or modify it under the terms of the: | |
5 * | |
6 * Eclipse Public License version 1.0 | |
7 * GNU General Public License version 2 | |
8 * GNU Lesser General Public License version 2.1 | |
9 */ | |
10 package com.oracle.truffle.ruby.test.language; | |
11 | |
12 import org.junit.*; | |
13 | |
14 import com.oracle.truffle.ruby.test.*; | |
15 | |
16 /** | |
17 * Test {@code class} expressions. | |
18 */ | |
19 public class ClassTests extends RubyTests { | |
20 | |
21 @Test | |
22 public void testDefine() { | |
23 assertPrints("Foo\n", "class Foo; end; puts Foo"); | |
24 } | |
25 | |
26 @Test | |
27 public void testMethods() { | |
28 assertPrints("14\n", "class Foo; def test; return 14; end; end; foo=Foo.new; puts foo.test"); | |
29 assertPrints("14\n", "class Foo; def test(x); return x; end; end; foo=Foo.new; puts foo.test(14)"); | |
30 } | |
31 | |
32 @Test | |
33 public void testDefineHasScope() { | |
34 assertPrints("14\n", "x=14; class Foo; x=0; end; puts x"); | |
35 assertPrints("14\n", "class Foo; x=14; puts x; end"); | |
36 } | |
37 | |
38 @Test | |
39 public void testInitialise() { | |
40 assertPrints("14\n", "class Foo; def initialize; puts 14; end; end; Foo.new"); | |
41 assertPrints("14\n", "class Foo; def initialize(x); puts x; end; end; Foo.new 14"); | |
42 assertPrints("14\n", "class Foo; def initialize(x); puts x; end; end; Foo.new(14)"); | |
43 } | |
44 | |
45 @Test | |
46 public void testInstanceVariables() { | |
47 assertPrints("14\n", "class Foo; def a; @x=14; end; def b; @x; end; end; foo=Foo.new; foo.a; puts foo.b"); | |
48 } | |
49 | |
50 @Test | |
51 public void testMissingVariables() { | |
52 assertPrints("NilClass\n", "class Foo; def a; @x; end; end; foo=Foo.new; puts foo.a.class"); | |
53 } | |
54 | |
55 @Test | |
56 public void testClassConstants() { | |
57 assertPrints("14\n", "class Foo; X=14; def foo; puts X; end; end; foo=Foo.new; foo.foo"); | |
58 } | |
59 | |
60 @Test | |
61 public void testReopeningSingletonClass() { | |
62 assertPrints("1\n", "foo = Object.new; class << foo; def bar; puts 1; end; end; foo.bar"); | |
63 } | |
64 | |
65 @Test | |
66 public void testInheritance() { | |
67 assertPrints("14\n", "class Foo; def foo; puts 14; end; end; class Bar < Foo; end; Bar.new.foo"); | |
68 } | |
69 | |
70 @Test | |
71 public void testSingletonInheritance() { | |
72 assertPrints("14\n", "class Foo; def self.foo; puts 14; end; end; class Bar < Foo; end; Bar.foo"); | |
73 } | |
74 | |
75 @Test | |
76 public void testNestedClass() { | |
77 assertPrints("14\n", "class Foo; class Bar; def bar; 14; end; end; def foo; Bar.new; end; end; puts Foo.new.foo.bar"); | |
78 } | |
79 | |
80 } |