Skip to content

Commit 24c9e38

Browse files
Add cats integration tests (Eq, Show, coerce)
Tests verify that deriving works with cats typeclasses, confirming the plugin's output is compatible with cats on both Scala 2.13 and 3. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5c17123 commit 24c9e38

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io.estatico.newtype
2+
3+
import io.estatico.newtype.macros._
4+
import io.estatico.newtype.ops._
5+
import org.scalatest.flatspec.AnyFlatSpec
6+
import org.scalatest.matchers.should.Matchers
7+
import cats._
8+
import cats.syntax.all._
9+
10+
class NewTypeCatsTest extends AnyFlatSpec with Matchers {
11+
12+
import NewTypeCatsTest._
13+
14+
behavior of "@newtype with cats"
15+
16+
it should "derive Eq instance" in {
17+
implicit val eqInt: Eq[Int] = Eq.fromUniversalEquals
18+
val eqFoo: Eq[Foo] = Foo.deriving[Eq]
19+
eqFoo.eqv(Foo(1), Foo(1)) shouldBe true
20+
eqFoo.eqv(Foo(1), Foo(2)) shouldBe false
21+
}
22+
23+
it should "derive Show instance" in {
24+
implicit val showInt: Show[Int] = Show.fromToString
25+
val showFoo: Show[Foo] = Foo.deriving[Show]
26+
showFoo.show(Foo(42)) shouldBe "42"
27+
}
28+
29+
it should "coerce with .coerce" in {
30+
val foo: Foo = 42.coerce[Foo]
31+
val i: Int = foo.coerce[Int]
32+
i shouldBe 42
33+
}
34+
}
35+
36+
object NewTypeCatsTest {
37+
@newtype case class Foo(x: Int)
38+
}

0 commit comments

Comments
 (0)