Skip to content

Failing test for macro with classes in a different file #506

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -167,6 +167,7 @@ private[generic] object JSONMacros {
)
else {
val subtypes = collectKnownSubtypes(c)(symbol)
c.info(c.enclosingPosition, symbol.fullName + " Subtypes: " + subtypes.mkString(", "), true)
val idents = Ident(symbol.name) :: subtypes.map { s =>
if (s.isModuleClass) New(TypeTree(s.asClass.toType)) else Ident(s.name)
}.toList
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.sphere.json

object AnotherFileExample {
sealed abstract class Bug {
def name: String
def legs: Int
}
abstract class Insect extends Bug {
def legs = 6
}
case class Spider(name: String) extends Bug {
def legs = 8
}

case class Ant(name: String) extends Insect
case class Grasshopper(name: String) extends Insect
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.sphere.json

import io.sphere.json.generic._
import org.scalatest.OptionValues
import org.scalatest.matchers.must.Matchers
import org.scalatest.wordspec.AnyWordSpec
import cats.data.Validated.Valid
import io.sphere.json.AnotherFileExample._
class MultiFileJSONSpec extends AnyWordSpec with Matchers with OptionValues {
"deriveJSON" should {
"handle classes in another file correctly" in {
implicit val bugJSON = deriveJSON[Bug]
val a = Ant("C. ligniperda")
fromJSON[Bug](toJSON[Bug](a)) must equal(Valid(a))
}
}
}