Skip to content

Commit

Permalink
add tests for macros with new classes
Browse files Browse the repository at this point in the history
  • Loading branch information
winitzki committed Dec 22, 2016
1 parent 2a705be commit 96cb545
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/src/test/scala/code/winitzki/jc/BlockingMoleculesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,42 @@ class BlockingMoleculesSpec extends FlatSpec with Matchers with TimeLimitedTests

behavior of "syntax of blocking molecules with unit values / replies"

it should "allow non-unit values and non-unit replies" in {
val f = new B[Int,Int]("f")
site(tp0)( _go { case f(x, r) if x == 123 => r(456) })
f(123) shouldEqual 456
}

it should "allow non-unit values and non-unit replies with timeout" in {
val f = new B[Int,Int]("f")
site(tp0)( _go { case f(x, r) if x != 123 => r(456) })
f.timeout(200 millis)(123) shouldEqual None
}

it should "allow non-unit values and unit replies" in {
val f = new BE[Int]("f")
site(tp0)( _go { case f(x, r) if x == 123 => r() })
f(123) shouldEqual (())
}

it should "allow non-unit values and unit replies with timeout" in {
val f = new BE[Int]("f")
site(tp0)( _go { case f(x, r) if x != 123 => r() })
f.timeout(200 millis)(123) shouldEqual None
}

it should "allow unit values and unit replies" in {
val f = new EE("f")
site(tp0)( _go { case f(x, r) if x == (()) => r() })
f() shouldEqual (())
}

it should "allow unit values and unit replies with timeout" in {
val f = new EE("f")
site(tp0)( _go { case f(x, r) if x != (()) => r() })
f.timeout(200 millis)() shouldEqual None
}

behavior of "reaction sites with invalid replies"

it should "use the first reply when a reaction attempts to reply twice" in {
Expand Down
20 changes: 20 additions & 0 deletions macros/src/test/scala/code/winitzki/jc/MacrosSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ class MacrosSpec extends FlatSpec with Matchers with BeforeAndAfterEach {
s.toString shouldEqual "s/B"
}

it should "create an emitter of class E for m[Unit]" in {
val a = m[Unit]
a.isInstanceOf[E] shouldEqual true
}

it should "create an emitter of class BE[Int] for b[Int, Unit]" in {
val a = b[Int, Unit]
a.isInstanceOf[BE[Int]] shouldEqual true
}

it should "create an emitter of class EB[Int] for b[Unit, Int]" in {
val a = b[Unit, Int]
a.isInstanceOf[EB[Int]] shouldEqual true
}

it should "create an emitter of class EE for b[Unit, Unit]" in {
val a = b[Unit, Unit]
a.isInstanceOf[EE] shouldEqual true
}

behavior of "macros for inspecting a reaction body"


Expand Down

0 comments on commit 96cb545

Please sign in to comment.