aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJon Pretty <jon.pretty@propensive.com>2017-10-30 12:55:57 +0100
committerJon Pretty <jon.pretty@propensive.com>2017-10-30 12:55:57 +0100
commit8edaa6e2adbb4aa724a7829be5003fdabb01628a (patch)
tree4138ee6e39625d8b65001a678e2cf37b6173b383 /tests
parent8cd72499b92d745ce3e3f2621a03ab61ce78ef85 (diff)
downloadmagnolia-8edaa6e2adbb4aa724a7829be5003fdabb01628a.tar.gz
magnolia-8edaa6e2adbb4aa724a7829be5003fdabb01628a.tar.bz2
magnolia-8edaa6e2adbb4aa724a7829be5003fdabb01628a.zip
Derivation working for Show and Eq
Diffstat (limited to 'tests')
-rw-r--r--tests/shared/src/main/scala/magnolia/main.scala24
-rw-r--r--tests/src/main/scala/main.scala81
2 files changed, 81 insertions, 24 deletions
diff --git a/tests/shared/src/main/scala/magnolia/main.scala b/tests/shared/src/main/scala/magnolia/main.scala
deleted file mode 100644
index 9d7accb..0000000
--- a/tests/shared/src/main/scala/magnolia/main.scala
+++ /dev/null
@@ -1,24 +0,0 @@
-package magnolia
-
-import examples.{Address, Branch, Country, Entity, Leaf, Person, Eq}
-import cats.instances.all._
-import cats.syntax.all._
-import examples.catsShowDerivation.ShowDerivation.generic
-import examples.catsShowDerivation.ShowDerivation
-import language.experimental.macros
-
-object Main {
-
- def main(args: Array[String]): Unit = {
- val tree1 = Branch(Branch(Leaf(1), Leaf(2)), Leaf(3))
-
- println(tree1.show)
-
- println(List[Entity](Person("John Smith",
- Address(List("1 High Street", "London", "SW1A 1AA"),
- Country("UK", "GBR", false)))).show)
-
- import Eq.derivation.generic
- println(tree1 isEqualTo tree1)
- }
-}
diff --git a/tests/src/main/scala/main.scala b/tests/src/main/scala/main.scala
new file mode 100644
index 0000000..7dee065
--- /dev/null
+++ b/tests/src/main/scala/main.scala
@@ -0,0 +1,81 @@
+package magnolia.tests
+
+import magnolia._
+import estrapade._
+import contextual.data.scalac._
+import contextual.data.fqt._
+import contextual.data.txt._
+
+import scala.util._
+
+object Tests extends TestApp {
+
+ def tests() = {
+
+ test("construct a Show product instance") {
+ import examples._
+ Show.generic[Person].show(Person("John Smith", 34))
+ }.assert(_ == """{name=John Smith,age=34}""")
+
+ test("construct a Show coproduct instance") {
+ import examples._
+ Show.generic[Person].show(Person("John Smith", 34))
+ }.assert(_ == "{name=John Smith,age=34}")
+
+ test("serialize a Branch") {
+ import magnolia.examples._
+ implicitly[Show[Branch]].show(Branch(Leaf("LHS"), Leaf("RHS")))
+ }.assert(_ == "{left={value=LHS},right={value=RHS}}")
+
+ test("test equality false") {
+ import examples._
+ Eq.generic[Entity].equal(Person("John Smith", 34), Person("", 0))
+ }.assert(_ == false)
+
+ test("test equality true") {
+ import examples._
+ Eq.generic[Entity].equal(Person("John Smith", 34), Person("John Smith", 34))
+ }.assert(_ == true)
+
+ test("test branch equality true") {
+ import examples._
+ Eq.generic[Tree].equal(Branch(Leaf("one"), Leaf("two")), Branch(Leaf("one"), Leaf("two")))
+ }.assert(_ == true)
+
+ /*test("construction of Show instance for Leaf") {
+ scalac"""
+ import magnolia.examples._
+ implicitly[Show[Leaf]]
+ """
+ }.assert(_ == Returns(fqt"magnolia.examples.Show[magnolia.examples.Leaf]"))
+
+ test("construction of Show instance for Tree") {
+ scalac"""
+ import magnolia.examples._
+ implicitly[Show[Tree]]
+ """
+ }.assert(_ == Returns(fqt"magnolia.examples.Show[magnolia.examples.Tree]"))
+
+ test("serialize a Leaf") {
+ import magnolia.examples._
+ implicitly[Show[Leaf]].show(Leaf("testing"))
+ }.assert(_ == "{value=testing}")
+
+ test("serialize a Branch as a Tree") {
+ import magnolia.examples._
+ implicitly[Show[Tree]].show(Branch(Leaf("LHS"), Leaf("RHS")))
+ }.assert(_ == "{left={value=LHS},right={value=RHS}}")
+
+ test("show error stack") {
+ scalac"""
+ import magnolia.examples._
+ case class Alpha(integer: Int)
+ case class Beta(alpha: Alpha)
+ Show.generic[Beta]
+ """
+ }.assert(_ == TypecheckError(txt"""magnolia: could not find typeclass for type Int
+ | in parameter 'integer' of product type Alpha
+ | in parameter 'alpha' of product type Beta
+ |"""))*/
+ }
+}