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

Enable and fix doctests on 2.13 #3155

Merged
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
7 changes: 1 addition & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ lazy val commonSettings = commonScalaVersionSettings ++ Seq(
Test / unmanagedSourceDirectories ++= scalaVersionSpecificFolders("test", baseDirectory.value, scalaVersion.value),
resolvers ++= Seq(Resolver.sonatypeRepo("releases"), Resolver.sonatypeRepo("snapshots")),
parallelExecution in Test := false,
scalacOptions in (Compile, doc) := (scalacOptions in (Compile, doc)).value.filter(_ != "-Xfatal-warnings"),
// TODO: reenable doctests on 2.13 once it's officially released. it's disabled for now due to changes to the `toString` impl of collections
doctestGenTests := {
val unchanged = doctestGenTests.value
if (priorTo2_13(scalaVersion.value)) unchanged else Nil
}
scalacOptions in (Compile, doc) := (scalacOptions in (Compile, doc)).value.filter(_ != "-Xfatal-warnings")
) ++ warnUnusedImport

def macroDependencies(scalaVersion: String) =
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/scala/cats/NonEmptyTraverse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ import simulacrum.typeclass
* scala> import cats.implicits._
* scala> import cats.data.NonEmptyList
* scala> def countWords(words: List[String]): Map[String, Int] = words.groupBy(identity).map { case (k, v) => (k, v.length) }
* scala> NonEmptyList.of(List("How", "do", "you", "fly"), List("What", "do", "you", "do")).nonEmptyTraverse(countWords)
* res0: Map[String,cats.data.NonEmptyList[Int]] = Map(do -> NonEmptyList(1, 2), you -> NonEmptyList(1, 1))
* scala> val expectedResult = Map("do" -> NonEmptyList.of(1, 2), "you" -> NonEmptyList.of(1, 1))
* scala> val x = List("How", "do", "you", "fly")
* scala> val y = List("What", "do", "you", "do")
* scala> val result = NonEmptyList.of(x, y).nonEmptyTraverse(countWords)
* scala> result === expectedResult
* res0: Boolean = true
* }}}
*/
def nonEmptyTraverse[G[_]: Apply, A, B](fa: F[A])(f: A => G[B]): G[F[B]]
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/arrow/Choice.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import simulacrum.typeclass
* Example:
* {{{
* scala> import cats.implicits._
* scala> val b: Boolean => String = _ + " is a boolean"
* scala> val i: Int => String = _ + " is an integer"
* scala> val b: Boolean => String = _.toString + " is a boolean"
* scala> val i: Int => String = _.toString + " is an integer"
* scala> val f: (Either[Boolean, Int]) => String = b ||| i
*
* scala> f(Right(3))
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/NonEmptyChain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ class NonEmptyChainOps[A](private val value: NonEmptyChain[A]) extends AnyVal {
* scala> import cats.data.NonEmptyChain
* scala> val as = NonEmptyChain(1, 2, 3)
* scala> val bs = NonEmptyChain("A", "B", "C")
* scala> as.zipWith(bs)(_ + _)
* scala> as.zipWith(bs)(_.toString + _)
* res0: cats.data.NonEmptyChain[String] = Chain(1A, 2B, 3C)
* }}}
*/
Expand Down
30 changes: 18 additions & 12 deletions core/src/main/scala/cats/data/NonEmptyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ final case class NonEmptyList[+A](head: A, tail: List[A]) {
* scala> import cats.data.NonEmptyList
* scala> val as = NonEmptyList.of(1, 2, 3)
* scala> val bs = NonEmptyList.of("A", "B", "C")
* scala> as.zipWith(bs)(_ + _)
* scala> as.zipWith(bs)(_.toString + _)
* res0: cats.data.NonEmptyList[String] = NonEmptyList(1A, 2B, 3C)
* }}}
*/
Expand Down Expand Up @@ -369,10 +369,12 @@ final case class NonEmptyList[+A](head: A, tail: List[A]) {
* {{{
* scala> import scala.collection.immutable.SortedMap
* scala> import cats.data.NonEmptyList
* scala> import cats.instances.boolean._
* scala> import cats.implicits._
* scala> val nel = NonEmptyList.of(12, -2, 3, -5)
* scala> nel.groupBy(_ >= 0)
* res0: SortedMap[Boolean, cats.data.NonEmptyList[Int]] = Map(false -> NonEmptyList(-2, -5), true -> NonEmptyList(12, 3))
* scala> val expectedResult = SortedMap(false -> NonEmptyList.of(-2, -5), true -> NonEmptyList.of(12, 3))
* scala> val result = nel.groupBy(_ >= 0)
* scala> result === expectedResult
* res0: Boolean = true
* }}}
*/
def groupBy[B](f: A => B)(implicit B: Order[B]): SortedMap[B, NonEmptyList[A]] = {
Expand All @@ -398,11 +400,13 @@ final case class NonEmptyList[+A](head: A, tail: List[A]) {
* of the keys produced by the given mapping function.
*
* {{{
* scala> import cats.data._
* scala> import cats.instances.boolean._
* scala> import cats.data.{NonEmptyList, NonEmptyMap}
* scala> import cats.implicits._
* scala> val nel = NonEmptyList.of(12, -2, 3, -5)
* scala> nel.groupByNem(_ >= 0)
* res0: NonEmptyMap[Boolean, NonEmptyList[Int]] = Map(false -> NonEmptyList(-2, -5), true -> NonEmptyList(12, 3))
* scala> val expectedResult = NonEmptyMap.of(false -> NonEmptyList.of(-2, -5), true -> NonEmptyList.of(12, 3))
* scala> val result = nel.groupByNem(_ >= 0)
* scala> result === expectedResult
* res0: Boolean = true
* }}}
*/
def groupByNem[B](f: A => B)(implicit B: Order[B]): NonEmptyMap[B, NonEmptyList[A]] =
Expand All @@ -411,11 +415,13 @@ final case class NonEmptyList[+A](head: A, tail: List[A]) {
/**
* Creates new `NonEmptyMap`, similarly to List#toMap from scala standard library.
*{{{
* scala> import cats.data._
* scala> import cats.instances.int._
* scala> import cats.data.{NonEmptyList, NonEmptyMap}
* scala> import cats.implicits._
* scala> val nel = NonEmptyList((0, "a"), List((1, "b"),(0, "c"), (2, "d")))
* scala> nel.toNem
* res0: NonEmptyMap[Int,String] = Map(0 -> c, 1 -> b, 2 -> d)
* scala> val expectedResult = NonEmptyMap.of(0 -> "c", 1 -> "b", 2 -> "d")
* scala> val result = nel.toNem
* scala> result === expectedResult
* res0: Boolean = true
*}}}
*
*/
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/NonEmptySet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ sealed class NonEmptySetOps[A](val value: NonEmptySet[A]) {
* scala> import cats.implicits._
* scala> val as = NonEmptySet.of(1, 2, 3)
* scala> val bs = NonEmptySet.of("A", "B", "C")
* scala> as.zipWith(bs)(_ + _)
* scala> as.zipWith(bs)(_.toString + _)
* res0: cats.data.NonEmptySet[String] = TreeSet(1A, 2B, 3C)
* }}}
*/
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/NonEmptyVector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ final class NonEmptyVector[+A] private (val toVector: Vector[A]) extends AnyVal
* scala> import cats.data.NonEmptyVector
* scala> val as = NonEmptyVector.of(1, 2, 3)
* scala> val bs = NonEmptyVector.of("A", "B", "C")
* scala> as.zipWith(bs)(_ + _)
* scala> as.zipWith(bs)(_.toString + _)
* res0: cats.data.NonEmptyVector[String] = NonEmptyVector(1A, 2B, 3C)
* }}}
*/
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/flatMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class FlattenOps[F[_], A](private val ffa: F[F[A]]) extends AnyVal {
* {{{
* scala> import cats.implicits._
* scala> type ErrorOr[A] = Either[String, A]
* scala> val x: ErrorOr[ErrorOr[Int]] = Right(Right(3))
* scala> val x: ErrorOr[ErrorOr[Int]] = 3.asRight.asRight
* scala> x.flatten
* res0: ErrorOr[Int] = Right(3)
* }}}
Expand Down
12 changes: 8 additions & 4 deletions core/src/main/scala/cats/syntax/list.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ final class ListOps[A](private val la: List[A]) extends AnyVal {
*
* scala> val list = List(12, -2, 3, -5)
*
* scala> list.groupByNel(_ >= 0)
* res0: SortedMap[Boolean, NonEmptyList[Int]] = Map(false -> NonEmptyList(-2, -5), true -> NonEmptyList(12, 3))
* scala> val expectedResult = SortedMap(false -> NonEmptyList.of(-2, -5), true -> NonEmptyList.of(12, 3))
*
* scala> list.groupByNel(_ >= 0) === expectedResult
* res0: Boolean = true
* }}}
*/
def groupByNel[B](f: A => B)(implicit B: Order[B]): SortedMap[B, NonEmptyList[A]] = {
Expand All @@ -67,8 +69,10 @@ final private[syntax] class ListOpsBinCompat0[A](private val la: List[A]) extend
*
* scala> val list = List(12, -2, 3, -5)
*
* scala> list.groupByNec(_ >= 0)
* res0: SortedMap[Boolean, NonEmptyChain[Int]] = Map(false -> Chain(-2, -5), true -> Chain(12, 3))
* scala> val expectedResult = SortedMap(false -> NonEmptyChain(-2, -5), true -> NonEmptyChain(12, 3))
*
* scala> list.groupByNec(_ >= 0) === expectedResult
* res0: Boolean = true
* }}}
*/
def groupByNec[B](f: A => B)(implicit B: Order[B]): SortedMap[B, NonEmptyChain[A]] = {
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/scala/cats/syntax/set.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ final class SetOps[A](private val se: SortedSet[A]) extends AnyVal {
*
* scala> val sortedSet = SortedSet(12, -2, 3, -5)
*
* scala> sortedSet.groupByNes(_ >= 0)
* res0: SortedMap[Boolean, NonEmptySet[Int]] = Map(false -> TreeSet(-5, -2), true -> TreeSet(3, 12))
* scala> val expectedResult = SortedMap(false -> NonEmptySet.of(-5, -2), true -> NonEmptySet.of(3, 12))
*
* scala> sortedSet.groupByNes(_ >= 0) === expectedResult
* res0: Boolean = true
* }}}
*/
def groupByNes[B](f: A => B)(implicit B: Order[B]): SortedMap[B, NonEmptySet[A]] = {
Expand Down