Skip to content

Commit

Permalink
trying out shouldmatchers in the int-literal test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
rstrong committed Feb 5, 2013
1 parent af060d3 commit 59b0b62
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/test/scala/org/moe/parser/IntLiteralTestSuite.scala
Expand Up @@ -2,67 +2,68 @@ package org.moe.parser

import org.scalatest.FunSuite
import org.scalatest.BeforeAndAfter
import org.scalatest.matchers.ShouldMatchers

import org.moe.runtime._
import org.moe.interpreter._
import org.moe.ast._
import org.moe.parser._

class IntLiteralTestSuite extends FunSuite with BeforeAndAfter with ParserTestUtils {
class IntLiteralTestSuite extends FunSuite with BeforeAndAfter with ParserTestUtils with ShouldMatchers {

test("... basic test with an int") {
val result = interpretCode("123")
assert(result.asInstanceOf[MoeIntObject].getNativeValue === 123)
result.asInstanceOf[MoeIntObject].getNativeValue should equal (123)
}

test("... basic test with a negative int") {
val result = interpretCode("-123")
assert(result.asInstanceOf[MoeIntObject].getNativeValue === -123)
result.asInstanceOf[MoeIntObject].getNativeValue should equal (-123)
}

test("... basic test with an int - embedded underscore") {
val result = interpretCode("123_456")
assert(result.asInstanceOf[MoeIntObject].getNativeValue === 123456)
result.asInstanceOf[MoeIntObject].getNativeValue should equal (123456)
}

test("... basic test with an octal int") {
val result = interpretCode("0123")
assert(result.asInstanceOf[MoeIntObject].getNativeValue === 83)
result.asInstanceOf[MoeIntObject].getNativeValue should equal (83)
}

test("... basic test with an octal int - embedded underscore") {
val result = interpretCode("0123_456")
assert(result.asInstanceOf[MoeIntObject].getNativeValue === 42798)
result.asInstanceOf[MoeIntObject].getNativeValue should equal (42798)
}

test("... basic test with an hexadecimal int") {
val result = interpretCode("0x123")
assert(result.asInstanceOf[MoeIntObject].getNativeValue === 0x123)
result.asInstanceOf[MoeIntObject].getNativeValue should equal (0x123)
}

test("... basic test with an hexadecimal int - 2") {
val result = interpretCode("0xFFFF")
assert(result.asInstanceOf[MoeIntObject].getNativeValue === 0xFFFF)
result.asInstanceOf[MoeIntObject].getNativeValue should equal (0xFFFF)
}

test("... basic test with an hexadecimal int - embedded underscore") {
val result = interpretCode("0x123_456")
assert(result.asInstanceOf[MoeIntObject].getNativeValue === 0x123456)
result.asInstanceOf[MoeIntObject].getNativeValue should equal (0x123456)
}

test("... basic test with an hexadecimal int - embedded underscore - 2") {
val result = interpretCode("0xAB_CDEF")
assert(result.asInstanceOf[MoeIntObject].getNativeValue === 0xABCDEF)
result.asInstanceOf[MoeIntObject].getNativeValue should equal (0xABCDEF)
}

test("... basic test with an binary int literal") {
val result = interpretCode("0b10110")
assert(result.asInstanceOf[MoeIntObject].getNativeValue === 22)
result.asInstanceOf[MoeIntObject].getNativeValue should equal (22)
}

test("... basic test with an binary int literal - embedded underscore") {
val result = interpretCode("0b1011_0110")
assert(result.asInstanceOf[MoeIntObject].getNativeValue === 182)
result.asInstanceOf[MoeIntObject].getNativeValue should equal (182)
}

}

0 comments on commit 59b0b62

Please sign in to comment.