Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stevan Little
committed
Apr 10, 2013
1 parent
43b732f
commit 18c8f04
Showing
2 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/test/scala/org/moe/parser/MultiAssignmentTestSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package org.moe.parser | ||
|
||
import org.scalatest.FunSuite | ||
import org.scalatest.BeforeAndAfter | ||
import org.scalatest.matchers.ShouldMatchers | ||
|
||
import org.moe.runtime._ | ||
import org.moe.runtime.nativeobjects._ | ||
import org.moe.interpreter._ | ||
import org.moe.ast._ | ||
import org.moe.parser._ | ||
|
||
class MultiAssignmentTestSuite extends FunSuite with BeforeAndAfter with ParserTestUtils with ShouldMatchers { | ||
|
||
// declaration | ||
|
||
test("... basic multi-declaration") { | ||
val result = interpretCode("my ($x, $y) = (1, 2); [ $x, $y ]") | ||
var a = result.unboxToArrayBuffer.get | ||
a(0).unboxToInt.get should equal (1) | ||
a(1).unboxToInt.get should equal (2) | ||
} | ||
|
||
test("... basic multi-declaration w/ extra var") { | ||
val result = interpretCode("my ($x, $y, $z) = (1, 2); [ $x, $y, $z ]") | ||
var a = result.unboxToArrayBuffer.get | ||
a(0).unboxToInt.get should equal (1) | ||
a(1).unboxToInt.get should equal (2) | ||
a(2) should equal (runtime.NativeObjects.getUndef) | ||
} | ||
|
||
test("... basic multi-declaration w/ extra element") { | ||
val result = interpretCode("my ($x, $y) = (1, 2, 3); [ $x, $y ]") | ||
var a = result.unboxToArrayBuffer.get | ||
a(0).unboxToInt.get should equal (1) | ||
a(1).unboxToInt.get should equal (2) | ||
} | ||
|
||
// assignment | ||
|
||
test("... basic multi-assign") { | ||
val result = interpretCode("my ($x, $y); ($x, $y) = (1, 2); [ $x, $y ]") | ||
var a = result.unboxToArrayBuffer.get | ||
a(0).unboxToInt.get should equal (1) | ||
a(1).unboxToInt.get should equal (2) | ||
} | ||
|
||
test("... basic multi-assign w/ extra var") { | ||
val result = interpretCode("my ($x, $y, $z); ($x, $y, $z) = (1, 2); [ $x, $y, $z ]") | ||
var a = result.unboxToArrayBuffer.get | ||
a(0).unboxToInt.get should equal (1) | ||
a(1).unboxToInt.get should equal (2) | ||
a(2) should equal (runtime.NativeObjects.getUndef) | ||
} | ||
|
||
test("... basic multi-assign w/ extra element") { | ||
val result = interpretCode("my ($x, $y); ($x, $y) = (1, 2, 3); [ $x, $y ]") | ||
var a = result.unboxToArrayBuffer.get | ||
a(0).unboxToInt.get should equal (1) | ||
a(1).unboxToInt.get should equal (2) | ||
} | ||
|
||
// attribute assignment | ||
|
||
private val testClass = """ | ||
class Foo { | ||
has $!x; | ||
has $!y; | ||
has $!z; | ||
method test1 { | ||
($!x, $!y) = (1, 2); | ||
} | ||
method test2 { | ||
($!x, $!y, $!z) = (1, 2); | ||
} | ||
method test3 { | ||
($!x, $!y) = (1, 2, 3); | ||
} | ||
method get { [ $!x, $!y, $!z ] } | ||
} | ||
""" | ||
|
||
test("... basic multi-attribute-assign") { | ||
val result = interpretCode(testClass + "; my $x = ^Foo.new; $x.test1; $x.get") | ||
var a = result.unboxToArrayBuffer.get | ||
a(0).unboxToInt.get should equal (1) | ||
a(1).unboxToInt.get should equal (2) | ||
} | ||
|
||
test("... basic multi-attribute-assign w/ extra var") { | ||
val result = interpretCode(testClass + "; my $x = ^Foo.new; $x.test2; $x.get") | ||
var a = result.unboxToArrayBuffer.get | ||
a(0).unboxToInt.get should equal (1) | ||
a(1).unboxToInt.get should equal (2) | ||
a(2) should equal (runtime.NativeObjects.getUndef) | ||
} | ||
|
||
test("... basic multi-attribute-assign w/ extra element") { | ||
val result = interpretCode(testClass + "; my $x = ^Foo.new; $x.test3; $x.get") | ||
var a = result.unboxToArrayBuffer.get | ||
a(0).unboxToInt.get should equal (1) | ||
a(1).unboxToInt.get should equal (2) | ||
} | ||
|
||
} |