Skip to content

Commit

Permalink
adding in some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevan Little committed Apr 14, 2013
1 parent e712210 commit 0a0c1c2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/test/scala/org/moe/parser/ClassTestSuite.scala
Expand Up @@ -114,4 +114,40 @@ class ClassTestSuite extends FunSuite with BeforeAndAfter with ParserTestUtils w
result.unboxToString.get should be ("HELLO WORLD")
}

test("... make sure $?SELF and $?CLASS work") {
val result = interpretCode("class Foo { method bar { [ $?SELF, $?CLASS ] } }; ^Foo.new.bar")
val array = result.unboxToArrayBuffer.get
val obj = array(0).asInstanceOf[MoeObject]
val cls = array(1).asInstanceOf[MoeClass]

assert(obj.isInstanceOf("Foo"))

assert(cls.isInstanceOf("Class"))
assert(cls.getName === "Foo")
}

private val submethodTest = """
class Foo {
has $!foo;
submethod BUILD { self.set_foo }
method set_foo { $!foo = "FOO"; }
method get_foo { $!foo }
};
class Bar extends Foo {
has $!bar;
submethod BUILD { self.set_bar }
method set_bar { $!bar = "BAR"; }
method get_bar { $!bar }
};
"""

test("... submethod test") {
val result = interpretCode(submethodTest + "; my $b = ^Bar.new; [ $b.get_foo, $b.get_bar ]")
val array = result.unboxToArrayBuffer.get

assert(array(0).unboxToString.get === "FOO")
assert(array(1).unboxToString.get === "BAR")
}


}

0 comments on commit 0a0c1c2

Please sign in to comment.