Skip to content

Commit

Permalink
add == and != to bool class
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevan Little committed Apr 14, 2013
1 parent 0a0c1c2 commit c32c265
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/main/scala/org/moe/runtime/builtins/BoolClass.scala
Expand Up @@ -24,6 +24,26 @@ object BoolClass {

import r.NativeObjects._

// equality operators

boolClass.addMethod(
new MoeMethod(
"infix:<==>",
new MoeSignature(List(new MoePositionalParameter("$other"))),
env,
(e) => self(e).equal_to(r, e.get("$other").get)
)
)

boolClass.addMethod(
new MoeMethod(
"infix:<!=>",
new MoeSignature(List(new MoePositionalParameter("$other"))),
env,
(e) => self(e).not_equal_to(r, e.get("$other").get)
)
)

// coercion

boolClass.addMethod(
Expand Down
Expand Up @@ -11,6 +11,14 @@ class MoeBoolObject(

// runtime methods

def equal_to (r: MoeRuntime, other: MoeObject): MoeBoolObject = r.NativeObjects.getBool(
(isTrue && other.isTrue) || (isFalse && other.isFalse)
)

def not_equal_to (r: MoeRuntime, other: MoeObject): MoeBoolObject = r.NativeObjects.getBool(
(isTrue && other.isFalse) || (isFalse && other.isTrue)
)

// MoeNativeObject overrides

override def copy = new MoeBoolObject(getNativeValue, getAssociatedClass)
Expand Down
23 changes: 21 additions & 2 deletions src/test/scala/org/moe/parser/BooleanLiteralTestSuite.scala
Expand Up @@ -19,9 +19,28 @@ class BooleanLiteralTestSuite extends FunSuite with BeforeAndAfter with ParserTe
val result = interpretCode("false")
assert(result.unboxToBoolean.get === false)
}
test("... basic test with a not true") {
val result = interpretCode(" false ")

test("... basic test with equality (true == true)") {
val result = interpretCode("true == true")
assert(result.unboxToBoolean.get === true)
}

test("... basic test with equality (true == false") {
val result = interpretCode("true == false")
assert(result.unboxToBoolean.get === false)
}

test("... basic test with equality (false == false") {
val result = interpretCode("false == false")
assert(result.unboxToBoolean.get === true)
}

test("... basic test with equality (false == true") {
val result = interpretCode("false == true")
assert(result.unboxToBoolean.get === false)
}




}

0 comments on commit c32c265

Please sign in to comment.