Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tests for array/hash element assignment
  • Loading branch information
prakashk committed Apr 7, 2013
1 parent d53831c commit a504fc7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/test/scala/org/moe/parser/ArrayHashIndexingTestSuite.scala
Expand Up @@ -48,6 +48,23 @@ class ArrayHashIndexingTestSuite extends FunSuite with BeforeAndAfter with Parse
assert(result.isUndef)
}

test("... basic test with a simple array element assignment (existing element)") {
val result = interpretCode("my @x = [1, 2, 3]; @x[2] = 42; @x")

val array = result.unboxToArrayBuffer.get
assert(array.length === 3)
assert(array(2).unboxToInt.get === 42)
}

test("... basic test with a simple array element assignment (new element)") {
val result = interpretCode("my @x = [1, 2, 3]; @x[4] = 42; @x")

val array = result.unboxToArrayBuffer.get
assert(array.length === 5)
assert(array(3).isUndef)
assert(array(4).unboxToInt.get === 42)
}

// hashes

test("... basic test with a simple hash (indexing one w/ double quotes)") {
Expand All @@ -74,6 +91,18 @@ class ArrayHashIndexingTestSuite extends FunSuite with BeforeAndAfter with Parse
assert(result.isUndef)
}

test("... basic test with a simple hash assignment (existing key)") {
val result = interpretCode(""" my %x = { one => 1, two => 2 }; %x{"one"} = "one"; """)

assert(result.unboxToString.get === "one")
}

test("... basic test with a simple hash assignment (new key)") {
val result = interpretCode(""" my %x = { one => 1, two => 2 }; %x{"three"} = 3; """)

assert(result.unboxToInt.get === 3)
}

// Both

test("... basic test with a complex example (hash index providing array index)") {
Expand Down

0 comments on commit a504fc7

Please sign in to comment.