Starting to write tests for character reader.
This commit is contained in:
parent
7ae19980d9
commit
fdb150b12d
2 changed files with 50 additions and 0 deletions
11
modules/parser/src/test/resources/test-source-1.ava
Normal file
11
modules/parser/src/test/resources/test-source-1.ava
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
namespace tests
|
||||||
|
|
||||||
|
given A
|
||||||
|
class Semigroup
|
||||||
|
defn combine: A -> A -> A
|
||||||
|
end class
|
||||||
|
|
||||||
|
given A :: Semigroup
|
||||||
|
class Monoid
|
||||||
|
defn empty: A
|
||||||
|
end class
|
|
@ -0,0 +1,39 @@
|
||||||
|
package ava.parser
|
||||||
|
|
||||||
|
import cats.effect.IO
|
||||||
|
import cats.effect.unsafe.IORuntime
|
||||||
|
import java.io.InputStream
|
||||||
|
import scala.io.Source
|
||||||
|
|
||||||
|
class CharacterReaderTests extends munit.FunSuite:
|
||||||
|
import CharacterReaderTests.*
|
||||||
|
|
||||||
|
implicit val runtime: IORuntime = cats.effect.unsafe.IORuntime.global
|
||||||
|
|
||||||
|
test("should read a file end to end") {
|
||||||
|
val file = Files.TestSource1
|
||||||
|
val expected = loadFileToString(file)
|
||||||
|
val reader = CharacterReader.forInputStream(loadFileToStream(file))
|
||||||
|
|
||||||
|
val output = fs2.Stream
|
||||||
|
.repeatEval(IO(reader.consume()))
|
||||||
|
.takeWhile(_.isDefined)
|
||||||
|
.compile
|
||||||
|
.toList
|
||||||
|
.map(_.flatten)
|
||||||
|
.map(_.mkString)
|
||||||
|
.unsafeRunSync()
|
||||||
|
|
||||||
|
assertEquals(output, expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
private def loadFileToString(name: String): String =
|
||||||
|
Source.fromResource(name).mkString
|
||||||
|
|
||||||
|
private def loadFileToStream(name: String): InputStream =
|
||||||
|
getClass().getClassLoader().getResourceAsStream(name)
|
||||||
|
|
||||||
|
object CharacterReaderTests:
|
||||||
|
|
||||||
|
object Files:
|
||||||
|
val TestSource1: String = "test-source-1.ava"
|
Loading…
Add table
Reference in a new issue