Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add's support for sealed abstract classes #1518

Merged
merged 5 commits into from
Feb 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object SealedTraitOrderedBuf {
import c.universe._

val pf: PartialFunction[c.Type, TreeOrderedBuf[c.type]] = {
case tpe if (tpe.typeSymbol.isClass && tpe.typeSymbol.asClass.isTrait) => SealedTraitOrderedBuf(c)(buildDispatcher, tpe)
case tpe if (tpe.typeSymbol.isClass && (tpe.typeSymbol.asClass.isAbstractClass || tpe.typeSymbol.asClass.isTrait)) => SealedTraitOrderedBuf(c)(buildDispatcher, tpe)
}
pf
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ object TestCC {
} yield TestCaseClassD(aInt)
}

implicit def arbitraryTestEE: Arbitrary[TestCaseClassE] = Arbitrary {
for {
aString <- arb[String]
} yield TestCaseClassE(aString)
}

implicit def arbitraryTestObjectE: Arbitrary[TestObjectE.type] = Arbitrary {
for {
e <- Gen.const(TestObjectE)
Expand All @@ -95,14 +101,28 @@ object TestCC {
t <- Gen.oneOf(cc, bb, dd, TestObjectE)
} yield t
}

implicit def arbitraryTestSealedAbstractClass: Arbitrary[TestSealedAbstractClass] = Arbitrary {
for {
testSealedAbstractClass <- Gen.oneOf(A, B)
} yield testSealedAbstractClass
}

}

sealed abstract class TestSealedAbstractClass(val name: Option[String])
case object A extends TestSealedAbstractClass(None)
case object B extends TestSealedAbstractClass(Some("b"))

sealed trait SealedTraitTest
case class TestCC(a: Int, b: Long, c: Option[Int], d: Double, e: Option[String], f: Option[List[String]], aBB: ByteBuffer) extends SealedTraitTest

case class TestCaseClassB(a: Int, b: Long, c: Option[Int], d: Double, e: Option[String]) extends SealedTraitTest

case class TestCaseClassD(a: Int) extends SealedTraitTest

case class TestCaseClassE(a: String) extends AnyVal

case object TestObjectE extends SealedTraitTest

object MyData {
Expand Down Expand Up @@ -321,6 +341,30 @@ class MacroOrderingProperties extends FunSuite with PropertyChecks with ShouldMa
checkMany[Int]
checkCollisions[Int]
}

test("Test out AnyVal of String") {
import TestCC._
check[TestCaseClassE]
checkMany[TestCaseClassE]
checkCollisions[TestCaseClassE]
}

test("Test out Tuple of AnyVal's of String") {
import TestCC._
primitiveOrderedBufferSupplier[(TestCaseClassE, TestCaseClassE)]
check[(TestCaseClassE, TestCaseClassE)]
checkMany[(TestCaseClassE, TestCaseClassE)]
checkCollisions[(TestCaseClassE, TestCaseClassE)]
}

test("Test out Tuple of TestSealedAbstractClass") {
import TestCC._
primitiveOrderedBufferSupplier[TestSealedAbstractClass]
check[TestSealedAbstractClass]
checkMany[TestSealedAbstractClass]
checkCollisions[TestSealedAbstractClass]
}

test("Test out jl.Integer") {
implicit val a = arbMap { b: Int => java.lang.Integer.valueOf(b) }
check[java.lang.Integer]
Expand Down