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

Update to kantan.sbt 2.8.2 #323

Merged
merged 1 commit into from
Feb 16, 2022
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 @@ -26,7 +26,7 @@ package kantan.codecs
* rather than [[Decoder]] / [[Encoder]], however, they'll find themselves with a lower precedence and only be used
* if no other, more specific instance is found.
*/
package object export {
package object `export` {

/** [[Decoder]] instance that should only be used when no specific one is found. */
type DerivedDecoder[E, D, F, T] = Exported[Decoder[E, D, F, T]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import scala.annotation.nowarn
trait DecoderInstances {

implicit def enumeratumDecoder[E, D <: EnumEntry, F, T](
implicit enum: Enum[D],
implicit enumD: Enum[D],
decoder: Decoder[E, String, F, T],
error: IsError[F]
): Decoder[E, D, F, T] = {
// Enum is not serializable. The following is to make sure that the generated Decoder doesn't embark a
// non-serializable value and becomes non-serializable itself.
val map = enum.namesToValuesMap
val enumLabel = enum.values.map(_.entryName).mkString("[", ", ", "]")
val map = enumD.namesToValuesMap
val enumLabel = enumD.values.map(_.entryName).mkString("[", ", ", "]")

decoder.emap { name =>
map.get(name).toRight(error.fromMessage(s"'$name' is not a member of enumeration $enumLabel"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ trait DecoderInstances {

@SuppressWarnings(Array("org.wartremover.warts.StringPlusAny"))
def enumeratumDecoder[V, E, D <: ValueEnumEntry[V], F, T](
implicit enum: ValueEnum[V, D],
implicit valueEnum: ValueEnum[V, D],
decoder: Decoder[E, V, F, T],
error: IsError[F]
): Decoder[E, D, F, T] = {
// ValueEnum is not serializable. The following is to make sure that the generated Decoder doesn't embark a
// non-serializable value and becomes non-serializable itself.
val map = enum.valuesToEntriesMap
val enumLabel = enum.values.map(_.value).mkString("[", ", ", "]")
val map = valueEnum.valuesToEntriesMap
val enumLabel = valueEnum.values.map(_.value).mkString("[", ", ", "]")

decoder.emap { value =>
map.get(value).toRight(error.fromMessage(s"'$value' is not in values $enumLabel"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ trait ArbitraryInstances
// -------------------------------------------------------------------------------------------------------------------

def arbLegalEnumeratedValue[V: StringEncoder, A <: ValueEnumEntry[V]](
enum: ValueEnum[V, A]
valueEnum: ValueEnum[V, A]
): Arbitrary[LegalString[A]] =
Arbitrary(
Gen.oneOf(
enum.values.map(v => LegalValue[String, A, codecs.type](StringEncoder[V].encode(v.value), v))
valueEnum.values.map(v => LegalValue[String, A, codecs.type](StringEncoder[V].encode(v.value), v))
)
)

def arbIllegalEnumeratedValue[V: StringEncoder, A <: ValueEnumEntry[V]](
enum: ValueEnum[V, A]
valueEnum: ValueEnum[V, A]
): Arbitrary[IllegalValue[String, A, codecs.type]] = {
val legal = enum.values.map(a => StringEncoder[V].encode(a.value))
val legal = valueEnum.values.map(a => StringEncoder[V].encode(a.value))
Arbitrary {
arb[String].suchThat(s => !legal.contains(s)).map(s => IllegalValue(s))
}
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("com.nrinaudo" % "kantan.sbt-kantan" % "2.8.1")
addSbtPlugin("com.nrinaudo" % "kantan.sbt-scalajs" % "2.8.1")
addSbtPlugin("com.nrinaudo" % "kantan.sbt-kantan" % "2.8.2")
addSbtPlugin("com.nrinaudo" % "kantan.sbt-scalajs" % "2.8.2")