Skip to content

Commit

Permalink
Merge branch 'master' into update/scala3-library-3.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bplommer authored Jan 7, 2024
2 parents 430454d + 5b16c8d commit e4912d2
Show file tree
Hide file tree
Showing 101 changed files with 191 additions and 104 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ val refinedVersion = "0.10.3"
val scalaCollectionCompatVersion = "2.9.0"
val shapeless3Version = "3.3.0"
val shapelessVersion = "2.3.10"
val slf4jNopVersion = "2.0.7"
val slf4jNopVersion = "2.0.9"

val scala212 = "2.12.17"
val scala212 = "2.12.18"
val scala213 = "2.13.10"
val scala3 = "3.3.1"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala-2/AvroDoc.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala-2/AvroNamespace.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala-2/vulcan/CodecCompat.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala-2/vulcan/internal/tags.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala-3/vulcan/CodecCompat.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala/vulcan/Avro.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala/vulcan/AvroError.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala/vulcan/AvroException.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
22 changes: 19 additions & 3 deletions modules/core/src/main/scala/vulcan/Codec.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/

package vulcan

import cats.{Invariant, Show, ~>}
import cats.data.{Chain, NonEmptyChain, NonEmptyList, NonEmptySet, NonEmptyVector}
import cats.data.{Chain, NonEmptyChain, NonEmptyList, NonEmptyMap, NonEmptySet, NonEmptyVector}
import cats.free.FreeApplicative
import cats.implicits._

Expand All @@ -23,7 +23,7 @@ import vulcan.Avro.Bytes
import vulcan.internal.{Deserializer, Serializer}

import scala.annotation.implicitNotFound
import scala.collection.immutable.SortedSet
import scala.collection.immutable.{SortedMap, SortedSet}
import vulcan.internal.converters.collection._
import vulcan.internal.syntax._
import vulcan.internal.schema.adaptForSchema
Expand Down Expand Up @@ -972,6 +972,22 @@ object Codec extends CodecCompanionCompat {
)(_.toVector)
.withTypeName("NonEmptyVector")

/**
* @group Cats
*/
implicit final def nonEmptyMap[A](
implicit codec: Codec[A]
): Codec.Aux[Avro.Map[codec.AvroType], NonEmptyMap[String, A]] =
Codec
.map[A]
.imapError(
map =>
NonEmptyMap
.fromMap(SortedMap.apply(map.toList: _*))
.toRight(AvroError.decodeEmptyCollection)
)(_.toSortedMap)
.withTypeName("NonEmptyMap")

/**
* @group General
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala/vulcan/Prism.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala/vulcan/Props.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala/vulcan/internal/schema.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala/vulcan/internal/syntax.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala-2/vulcan/AvroDocSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala-2/vulcan/DerivationSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/cats/tests/CatsEquality.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/cats/tests/CatsSuite.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/vulcan/AvroErrorEqSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/vulcan/AvroErrorSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/vulcan/AvroExceptionSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/vulcan/BaseSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
73 changes: 72 additions & 1 deletion modules/core/src/test/scala/vulcan/CodecSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -1556,6 +1556,77 @@ final class CodecSpec extends BaseSpec with CodecSpecHelpers {
}
}

describe("nonEmptyMap") {
describe("schema") {
it("should be encoded as map") {
assertSchemaIs[NonEmptyMap[String, Int]] {
"""{"type":"map","values":"int"}"""
}
}
}

describe("encode") {
it("should encode as java map using encoder for value") {
assertEncodeIs[NonEmptyMap[String, Int]](
NonEmptyMap.of("key1" -> 1, "key2" -> 2, "key3" -> 3),
Right(
Map(Avro.String("key1") -> 1, Avro.String("key2") -> 2, Avro.String("key3") -> 3).asJava
)
)
}
}

describe("decode") {
it("should error if schema is not map") {
assertDecodeError[NonEmptyMap[String, Int]](
unsafeEncode[NonEmptyMap[String, Int]](NonEmptyMap.one("key", 1)),
SchemaBuilder.builder().intType(),
"Error decoding NonEmptyMap: Error decoding Map: Got unexpected schema type INT, expected schema type MAP"
)
}

it("should error if value is not java.util.Map") {
assertDecodeError[NonEmptyMap[String, Int]](
123,
unsafeSchema[NonEmptyMap[String, Int]],
"Error decoding NonEmptyMap: Error decoding Map: Got unexpected type java.lang.Integer, expected type java.util.Map"
)
}

it("should error if keys are not strings") {
assertDecodeError[NonEmptyMap[String, Int]](
NonEmptyMap.one(1, 2).toSortedMap.asJava,
unsafeSchema[NonEmptyMap[String, Int]],
"Error decoding NonEmptyMap: Error decoding Map: Got unexpected map key with type java.lang.Integer, expected Utf8"
)
}

it("should error if any keys are null") {
assertDecodeError[NonEmptyMap[String, Int]](
Map((null, 2)).asJava,
unsafeSchema[NonEmptyMap[String, Int]],
"Error decoding NonEmptyMap: Error decoding Map: Got unexpected map key with type null, expected Utf8"
)
}

it("should error on empty collection") {
assertDecodeError[NonEmptyMap[String, Int]](
unsafeEncode(Map.empty[String, Int]),
unsafeSchema[NonEmptyMap[String, Int]],
"Error decoding NonEmptyMap: Got unexpected empty collection"
)
}

it("should decode to map using decoder for value") {
val value = NonEmptyMap.of("key1" -> 1, "key2" -> 2, "key3" -> 3)
assertDecodeIs[NonEmptyMap[String, Int]](
unsafeEncode[NonEmptyMap[String, Int]](value),
Right(value)
)
}
}
}

describe("option") {
describe("schema") {
it("should be encoded as union") {
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/vulcan/EitherValues.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/vulcan/PrismSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/vulcan/PropsSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/vulcan/RoundtripSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 OVO Energy Limited
* Copyright 2019-2024 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Loading

0 comments on commit e4912d2

Please sign in to comment.