File: Debug.hs

package info (click to toggle)
haskell-io-streams 1.5.2.2-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 480 kB
  • sloc: haskell: 4,470; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 1,966 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE OverloadedStrings #-}

module System.IO.Streams.Tests.Debug (tests) where

------------------------------------------------------------------------------
import qualified Data.ByteString.Char8          as S
import qualified System.IO.Streams              as Streams
import qualified System.IO.Streams.Debug        as Streams
import           Test.Framework
import           Test.Framework.Providers.HUnit
import           Test.HUnit                     hiding (Test)


------------------------------------------------------------------------------
tests :: [Test]
tests = [ testDebugInput
        , testDebugOutput
        ]


------------------------------------------------------------------------------
testDebugInput :: Test
testDebugInput = testCase "debug/input" $ do
    s  <- Streams.fromList [S.replicate 100 'a', "foo"]
    (ds, getDebugOutput) <- Streams.listOutputStream
    s' <- Streams.debugInputBS "foo" ds s
    Streams.unRead "blah" s'
    Streams.skipToEof s'

    l <- getDebugOutput

    assertEqual "debugInput" expected l
  where
    expected = [
        "foo: pushback: \"blah\"\n"
      , "foo: got chunk: \"blah\"\n"
      , "foo: got chunk: \"aaaaaaaaaaaaaa ... aaaaaaaaaaaaaa\" (100 bytes)\n"
      , "foo: got chunk: \"foo\"\n"
      , "foo: got EOF\n"
      ]


------------------------------------------------------------------------------
testDebugOutput :: Test
testDebugOutput = testCase "debug/output" $ do
    is <- Streams.fromList [S.replicate 100 'a', "foo"]
    o  <- Streams.makeOutputStream f
    (ds, getDebugOutput) <- Streams.listOutputStream
    o' <- Streams.debugOutputBS "foo" ds o
    Streams.connect is o'

    l <- getDebugOutput

    assertEqual "debugInput" expected l
  where
    f !_ = return ()

    expected = [
        "foo: got chunk: \"aaaaaaaaaaaaaa ... aaaaaaaaaaaaaa\" (100 bytes)\n"
      , "foo: got chunk: \"foo\"\n"
      , "foo: got EOF\n"
      ]