Skip to content

Commit

Permalink
Merge pull request #464 from valencik/munit
Browse files Browse the repository at this point in the history
Migrate tests to Munit
  • Loading branch information
ChristopherDavenport authored Jun 4, 2021
2 parents 61ea46a + a66975d commit 1c47363
Show file tree
Hide file tree
Showing 14 changed files with 542 additions and 582 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ target/
# vim
*.sw?

.vscode/

.DS_Store
**/.DS_Store

# Ignore [ce]tags files
tags
.metals
.bloop
project/metals.sbt
metals.sbt
16 changes: 10 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ val catsEffectTestV = "0.4.2"
val shapelessV = "2.3.3"
val http4sV = "0.21.18"
val catsScalacheckV = "0.3.0"
val specs2V = "4.10.6"
val munitV = "0.7.26"
val munitCatsEffectV = "1.0.3"
val scalacheckEffectV = "1.0.2"

lazy val core = project.in(file("modules/core"))
.settings(commonSettings)
Expand Down Expand Up @@ -129,8 +131,7 @@ lazy val fs2 = project.in(file("modules/fs2"))
name := "cormorant-fs2",
libraryDependencies ++= Seq(
"co.fs2" %% "fs2-core" % "2.4.6",
"co.fs2" %% "fs2-io" % "2.4.6" % Test,
"com.codecommit" %% "cats-effect-testing-specs2" % catsEffectTestV % Test
"co.fs2" %% "fs2-io" % "2.4.6" % Test
)
)

Expand Down Expand Up @@ -190,12 +191,15 @@ lazy val docs = project.in(file("modules"))
lazy val commonSettings = Seq(
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.11.3" cross CrossVersion.full),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
testFrameworks += new TestFramework("munit.Framework"),

libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % catsV,
"org.typelevel" %% "cats-effect" % catsEffectV,
"org.specs2" %% "specs2-core" % specs2V % Test,
"org.specs2" %% "specs2-scalacheck" % specs2V % Test,
"org.scalameta" %% "munit" % munitV % Test,
"org.scalameta" %% "munit-scalacheck" % munitV % Test,
"org.typelevel" %% "munit-cats-effect-2" % munitCatsEffectV % Test,
"org.typelevel" %% "scalacheck-effect-munit" % scalacheckEffectV % Test,
"io.chrisdavenport" %% "cats-scalacheck" % catsScalacheckV % Test,
)
)
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package io.chrisdavenport.cormorant

class ErrorSpec extends org.specs2.mutable.Specification{
"Error.DecodeFailure" should {
"toString should work" in {
Error.DecodeFailure.single("reason").toString()
.must_===("DecodeFailure(NonEmptyList(reason))")
}
class ErrorSpec extends munit.FunSuite {
test("Error.DecodeFailure toString should work") {
assertEquals(
Error.DecodeFailure.single("reason").toString(),
"DecodeFailure(NonEmptyList(reason))"
)
}
"Error.ParseFailure" should {
"toString should work" in {
Error.ParseFailure.invalidInput("invalid").toString()
.must_===("ParseFailure(Invalid Input: Received invalid)")
}

test("Error.ParseFailure toString should work") {
assertEquals(
Error.ParseFailure.invalidInput("invalid").toString(),
"ParseFailure(Invalid Input: Received invalid)"
)
}

"Error.PrintFailure" should {
"toString should work" in {
Error.PrintFailure("reason").toString()
.must_===("PrintFailure(reason)")
}
test("Error.PrintFailure toString should work") {
assertEquals(
Error.PrintFailure("reason").toString(),
"PrintFailure(reason)"
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package io.chrisdavenport.cormorant

import org.specs2._
import _root_.cats.data._

object PrinterSpec extends Specification {
override def is = s2"""
Print a simple csv $simpleCSVPrint
Printer field with a surrounded field $fieldSurroundedCorrectly
Printer field with escaped field $fieldEscapedCorrectly
"""
class PrinterSpec extends munit.FunSuite {

def simpleCSVPrint = {
test("Print a simple csv") {
val csv = CSV.Complete(
CSV.Headers(
NonEmptyList.of(CSV.Header("Color"), CSV.Header("Food"), CSV.Header("Number"))
Expand All @@ -28,22 +22,20 @@ object PrinterSpec extends Specification {
|Red,Margarine,2
|Yellow,Broccoli,3""".stripMargin

Printer.default.print(csv) should_=== expectedCSVString
assertEquals(Printer.default.print(csv), expectedCSVString)
}


def fieldSurroundedCorrectly = {
test("Printer field with a surrounded field") {
val csv = CSV.Field("Snow, John")
val expectedCSVString = "\"Snow, John\""
Printer.default.print(csv) should_=== expectedCSVString

assertEquals(Printer.default.print(csv), expectedCSVString)
}

def fieldEscapedCorrectly = {
test("Printer field with escaped field") {
val csv = CSV.Field("Snow, \"John\"")
val expectedCSVString = "\"Snow, \"\"John\"\"\""

Printer.default.print(csv) should_=== expectedCSVString
}

}
assertEquals(Printer.default.print(csv), expectedCSVString)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,45 @@ package fs2

import cats.data.NonEmptyList
import cats.effect._
import cats.effect.testing.specs2.CatsIO
import munit.CatsEffectSuite
import _root_.fs2.Stream
import io.chrisdavenport.cormorant._
// import io.chrisdavenport.cormorant.implicits._
// import scala.concurrent.duration._
import java.io.ByteArrayInputStream
import java.io.InputStream

class StreamingParserSpec extends CormorantSpec with CatsIO {
class StreamingParserSpec extends CatsEffectSuite {

def ruinDelims(str: String) = augmentString(str).flatMap {
case '\n' => "\r\n"
case c => c.toString
}

"Streaming Parser" should {
// https://github.com/ChristopherDavenport/cormorant/pull/84
"parse a known value that did not work with streaming" in {
val x = """First Name,Last Name,Email
// https://github.com/ChristopherDavenport/cormorant/pull/84
test("Streaming Parser parses a known value that did not work with streaming") {
val x = """First Name,Last Name,Email
Larry,Bordowitz,[email protected]
Anonymous,Hippopotamus,[email protected]"""
val source = IO.pure(new ByteArrayInputStream(ruinDelims(x).getBytes): InputStream)
Stream.resource(Blocker[IO]).flatMap{blocker =>
_root_.fs2.io.readInputStream(
source,
chunkSize = 4,
blocker
)
}
.through(_root_.fs2.text.utf8Decode)
.through(parseComplete[IO])
.compile
.toVector
.map{ v =>
val header = CSV.Headers(NonEmptyList.of(CSV.Header("First Name"), CSV.Header("Last Name"), CSV.Header("Email")))
val row1 = CSV.Row(NonEmptyList.of(CSV.Field("Larry"), CSV.Field("Bordowitz"), CSV.Field("[email protected]")))
val row2 = CSV.Row(NonEmptyList.of(CSV.Field("Anonymous"), CSV.Field("Hippopotamus"), CSV.Field("[email protected]")))
Vector(
(header, row1),
(header, row2)
) must_=== v
}
val source = IO.pure(new ByteArrayInputStream(ruinDelims(x).getBytes): InputStream)
Stream.resource(Blocker[IO]).flatMap{blocker =>
_root_.fs2.io.readInputStream(
source,
chunkSize = 4,
blocker
)
}
.through(_root_.fs2.text.utf8Decode)
.through(parseComplete[IO])
.compile
.toVector
.map{ v =>
val header = CSV.Headers(NonEmptyList.of(CSV.Header("First Name"), CSV.Header("Last Name"), CSV.Header("Email")))
val row1 = CSV.Row(NonEmptyList.of(CSV.Field("Larry"), CSV.Field("Bordowitz"), CSV.Field("[email protected]")))
val row2 = CSV.Row(NonEmptyList.of(CSV.Field("Anonymous"), CSV.Field("Hippopotamus"), CSV.Field("[email protected]")))
assertEquals(Vector(
(header, row1),
(header, row2)
), v)
}
}


Expand Down
Loading

0 comments on commit 1c47363

Please sign in to comment.