= input def write(message: String) = copy(output = output :+ message) def testInterpret: ConsoleA ~> ([A] =>> State[TestConsoleState, A]) = new (ConsoleA ~> ([A] =>> State[TestConsoleState, A])): def apply[A](fa: ConsoleA[A]): State[TestConsoleState, A] = fa match case ReadLine(prompt) => for s <- State.get _ <- State.set(s.write(prompt)) yield s.read case PrintLine(message) => State.modify(_.write(s"$message\n")) test("Hello World") { val testState = TestConsoleState("World", Nil) val result = program.foldMap(testInterpret).run(testState).value assert(result === (TestConsoleState("World", List("Enter your name: ", "Hello World\n")), ())) }