Skip to content

Commit

Permalink
Revert "Remove parsing failure tests"
Browse files Browse the repository at this point in the history
This reverts commit 7a1aeb3.
  • Loading branch information
travisbrown authored and BenFradet committed Jan 7, 2019
1 parent 8c68e56 commit 5bb64c3
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/test/scala/io/circe/fs2/Fs2Suite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.circe.fs2

import _root_.fs2.{ Pipe, Stream, text }
import cats.effect.IO
import io.circe.{ DecodingFailure, Json }
import io.circe.{ DecodingFailure, Json, ParsingFailure }
import io.circe.fs2.examples._
import io.circe.generic.auto._
import io.circe.syntax._
Expand Down Expand Up @@ -87,6 +87,30 @@ class Fs2Suite extends CirceSuite {
.compile.toVector.attempt.unsafeRunSync() === Right(foos.toVector))
}

"stringArrayParser" should "return ParsingFailure" in {
testParsingFailure(_.through(stringArrayParser))
}

"stringStreamParser" should "return ParsingFailure" in {
testParsingFailure(_.through(stringStreamParser))
}

"byteArrayParser" should "return ParsingFailure" in {
testParsingFailure(_.through(text.utf8Encode).through(byteArrayParser))
}

"byteStreamParser" should "return ParsingFailure" in {
testParsingFailure(_.through(text.utf8Encode).through(byteStreamParser))
}

"byteArrayParserC" should "return ParsingFailure" in {
testParsingFailure(_.through(text.utf8Encode).chunks.through(byteArrayParserC))
}

"byteStreamParserC" should "return ParsingFailure" in {
testParsingFailure(_.through(text.utf8Encode).chunks.through(byteStreamParserC))
}

"decoder" should "return DecodingFailure" in
forAll { (fooStdStream: StdStream[Foo], fooVector: Vector[Foo]) =>
sealed trait Foo2
Expand All @@ -110,4 +134,13 @@ class Fs2Suite extends CirceSuite {
stream.through(through).compile.toVector.attempt.unsafeRunSync() === Right(foos.toVector))
}
}

private def testParsingFailure(through: Pipe[IO, String, Json]) = {
forAll { (stringStdStream: StdStream[String], stringVector: Vector[String]) =>
val result = Stream("}").append(stringStream(stringStdStream, stringVector))
.through(through)
.compile.toVector.attempt.unsafeRunSync()
assert(result.isLeft && result.left.get.isInstanceOf[ParsingFailure])
}
}
}

0 comments on commit 5bb64c3

Please sign in to comment.