Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/waddlaw/testable-io


https://github.com/waddlaw/testable-io

haskell

Last synced: 1 day ago
JSON representation

Awesome Lists containing this project

README

        

[![Build Status](https://travis-ci.org/waddlaw/testable-io.svg?branch=master)](https://travis-ci.org/waddlaw/testable-io)

# testable-io

Inspired: [imperative-edsl](https://hackage.haskell.org/package/imperative-edsl)

## Example

```haskell
module Main (main) where

import Test.FakeIO
import Test.Hspec

main :: IO ()
main = hspec $ do
describe "execFakeIO" $
it "use getChar" $ do
execFakeIO act "Haskell" `shouldReturn` "'H'\n"
execFakeIO act "GHC" `shouldReturn` "'G'\n"
execFakeIO act "guchi" `shouldReturn` "'g'\n"
execFakeIO act "BIGMOON" `shouldReturn` "'B'\n"
describe "evalFakeIO" $
it "use getChar" $ do
evalFakeIO act "Haskell" `shouldReturn` ('H', 's')
evalFakeIO act "GHC" `shouldReturn` ('G','C')
evalFakeIO act "guchi" `shouldReturn` ('g','c')
evalFakeIO act "BIGMOON" `shouldReturn` ('B','G')
describe "runFakeIO" $
it "use getChar" $ do
runFakeIO act "Haskell" `shouldReturn` (('H', 's'), "'H'\n")
runFakeIO act "GHC" `shouldReturn` (('G','C'), "'G'\n")
runFakeIO act "guchi" `shouldReturn` (('g','c'), "'g'\n")
runFakeIO act "BIGMOON" `shouldReturn` (('B','G'), "'B'\n")

act :: IO (Char, Char)
act = do
x <- getChar
print x
_ <- getChar
y <- getChar
return (x, y)
```

## Restriction

This library is only work on [hspec](http://hspec.github.io/).