Implemented Unit Test Framework
darcs-hash:20071231114727-a4fee-7bb01bb4f8b044c8cf29a84cb0f64a392c7f0588
This commit is contained in:
parent
d1e1b3f5df
commit
82b0a26ec9
@ -114,7 +114,7 @@ data EncodeState
|
||||
data EncodingException
|
||||
= HasNoRepresentation Char -- ^ Thrown if a specific character
|
||||
-- is not representable in an encoding.
|
||||
deriving (Show,Typeable)
|
||||
deriving (Eq,Show,Typeable)
|
||||
|
||||
-- | This exception type is thrown whenever something went wrong during the
|
||||
-- decoding-process.
|
||||
|
||||
37
Test/Tester.hs
Normal file
37
Test/Tester.hs
Normal file
@ -0,0 +1,37 @@
|
||||
{-# LANGUAGE ExistentialQuantification #-}
|
||||
module Test.Tester where
|
||||
|
||||
import Data.Encoding
|
||||
import Test.HUnit
|
||||
import Data.Word
|
||||
import Data.ByteString (pack)
|
||||
import Control.Exception (catchDyn,evaluate)
|
||||
|
||||
data EncodingTest
|
||||
= forall enc. (Encoding enc,Show enc) =>
|
||||
EncodingTest enc String [Word8]
|
||||
| forall enc. (Encoding enc,Show enc) =>
|
||||
DecodingError enc [Word8] DecodingException
|
||||
|
||||
instance Testable EncodingTest where
|
||||
test (EncodingTest enc src trg) = TestList
|
||||
[TestLabel (show enc ++ " encodable")
|
||||
(TestCase $ (all (encodable enc) src) @=? True)
|
||||
,TestLabel (show enc ++ " encoding")
|
||||
(TestCase $ (encode enc src) @=? bstr)
|
||||
,TestLabel (show enc ++ " decodable")
|
||||
(TestCase $ (decodable enc bstr) @=? True)
|
||||
,TestLabel (show enc ++ " decoding")
|
||||
(TestCase $ (decode enc bstr) @=? src)
|
||||
]
|
||||
where
|
||||
bstr = pack trg
|
||||
test (DecodingError enc trg what) = TestList
|
||||
[TestLabel (show enc ++ " not decodable") $
|
||||
TestCase $ assert $ not $ decodable enc (pack trg)
|
||||
,TestLabel (show enc ++ " decoding error") $ TestCase $
|
||||
catchDyn (do
|
||||
evaluate (decode enc (pack trg) == "")
|
||||
return ())
|
||||
(\exc -> exc @=? what)
|
||||
]
|
||||
Loading…
Reference in New Issue
Block a user