aboutsummaryrefslogtreecommitdiff
path: root/tests/src/main/scala/tests.scala
diff options
context:
space:
mode:
authorJon Pretty <jon.pretty@propensive.com>2017-12-28 11:56:11 +0000
committerJon Pretty <jon.pretty@propensive.com>2017-12-28 11:56:11 +0000
commit89478a78f807d9bb28dcf6bdc60a16a391a3524c (patch)
treeb48b1dd51343ae0563082b2f38ec0f5252ce0e0b /tests/src/main/scala/tests.scala
parentbd5f2dc411b1d63b9ee4dfec6476ba27d8410e2a (diff)
downloadmagnolia-virtual-params.tar.gz
magnolia-virtual-params.tar.bz2
magnolia-virtual-params.zip
Scala-fmt updatesvirtual-params
Diffstat (limited to 'tests/src/main/scala/tests.scala')
-rw-r--r--tests/src/main/scala/tests.scala30
1 files changed, 23 insertions, 7 deletions
diff --git a/tests/src/main/scala/tests.scala b/tests/src/main/scala/tests.scala
index 7b1fbe3..9e82d91 100644
--- a/tests/src/main/scala/tests.scala
+++ b/tests/src/main/scala/tests.scala
@@ -59,10 +59,18 @@ case class Account(id: String, emails: String*)
case class Portfolio(companies: Company*)
+trait ProductOnly[T]
+object ProductOnly {
+ type Typeclass[T] = ProductOnly[T]
+ def combine[T](ctx: CaseClass[ProductOnly, T, _]): ProductOnly[T] = null
+ implicit def gen[T]: ProductOnly[T] = macro Magnolia.gen[T]
+
+ implicit val productOnlyString: ProductOnly[String] = null
+}
object Tests extends TestApp {
- def tests() = for(i <- 1 to 1000) {
+ def tests() = for (i <- 1 to 100) {
import examples._
test("construct a Show product instance with alternative apply functions") {
@@ -223,12 +231,10 @@ object Tests extends TestApp {
// LabelledBox being invariant in L <: String prohibits the derivation for LabelledBox[Int, _]
test("can't show a Box with invariant label") {
scalac"Show.gen[Box[Int]]"
- }.assert { _ == TypecheckError(
- txt"""magnolia: could not find typeclass for type L
+ }.assert { _ == TypecheckError(txt"""magnolia: could not find typeclass for type L
| in parameter 'label' of product type magnolia.tests.LabelledBox[Int, _ <: String]
| in coproduct type magnolia.tests.Box[Int]
- |""")
- }
+ |""") }
class ParentClass() {
case class LocalClass(name: String)
@@ -243,7 +249,7 @@ object Tests extends TestApp {
Default.gen[LocalClassWithDefault].default
}.assert(_ == LocalClassWithDefault("foo"))
}
-
+
new ParentClass()
test("show an Account") {
@@ -257,7 +263,7 @@ object Tests extends TestApp {
test("show a Portfolio of Companies") {
Show.gen[Portfolio].show(Portfolio(Company("Alice Inc"), Company("Bob & Co")))
}.assert(_ == "Portfolio(companies=[Company(name=Alice Inc),Company(name=Bob & Co)])")
-
+
test("sealed trait typeName should be complete and unchanged") {
TypeName.gen[Color].name
}.assert(_ == "magnolia.tests.Color")
@@ -266,6 +272,16 @@ object Tests extends TestApp {
implicit val stringTypeName: TypeName[String] = new TypeName[String] { def name = "" }
TypeName.gen[Fruit].name
}.assert(_ == "magnolia.tests.Fruit")
+
+ test("attempt to derive typeclass without `dispatch` works for products") {
+ ProductOnly.gen[Fruit]
+ }.returns()
+
+ test("attempt to derive typeclass without `dispatch` fails for coproducts") {
+ scalac"ProductOnly.gen[Color]"
+ }.assert(_ == TypecheckError("""magnolia: the method `dispatch` should be defined, taking a """+
+ """single parameter of type SealedTrait[Typeclass, _]"""))
+
()
}
}