add a tool for generating regression tests before you start hacking on the implementation of an encoding
Ignore-this: d1f08ea3737455b87aa9828b88763d1f darcs-hash:20121203233647-76d51-a289254906f15e21b147294bfa0d5b37efde2854
This commit is contained in:
parent
d8f94105ee
commit
7d2f55ce07
40
tests/GenerateRegressionTests.hs
Normal file
40
tests/GenerateRegressionTests.hs
Normal file
@ -0,0 +1,40 @@
|
||||
{-# LANGUAGE NoMonomorphismRestriction #-}
|
||||
import Control.Monad
|
||||
import Data.ByteString (pack)
|
||||
import Data.Encoding
|
||||
import System.Random
|
||||
|
||||
-- for example:
|
||||
import Data.Encoding.ISO2022JP
|
||||
main = generate ISO2022JP
|
||||
-- end example
|
||||
|
||||
randomRepeat f max = randomRIO (0, max) >>= flip replicateM f
|
||||
randomString = randomRepeat randomIO
|
||||
randomGoodString = randomRepeat . randomGoodChar
|
||||
randomGoodChar f = let
|
||||
good = filter f [minBound..maxBound]
|
||||
n = length good
|
||||
in do
|
||||
i <- randomRIO (0, n-1)
|
||||
return (good !! i)
|
||||
|
||||
generate enc = do
|
||||
let filename = show enc ++ ".regression"
|
||||
randomGood = randomGoodString (encodeable enc)
|
||||
shortMixedEnc <- replicateM 300 (randomString 10)
|
||||
shortGoodEnc <- replicateM 30 (randomGood 10)
|
||||
longMixedEnc <- replicateM 300 (randomString 1000)
|
||||
longGoodEnc <- replicateM 3000 (randomGood 1000)
|
||||
shortDec <- replicateM 300 (randomString 10)
|
||||
longDec <- replicateM 3000 (randomString 1000)
|
||||
writeFile filename (show
|
||||
[ (s, encodeStrictByteStringExplicit enc s)
|
||||
| ss <- [shortMixedEnc, shortGoodEnc, longMixedEnc, longGoodEnc]
|
||||
, s <- ss
|
||||
] ++ "\n")
|
||||
appendFile filename (show
|
||||
[ (bs, decodeStrictByteStringExplicit enc (pack bs))
|
||||
| bss <- [shortDec, longDec]
|
||||
, bs <- bss
|
||||
] ++ "\n")
|
||||
Loading…
Reference in New Issue
Block a user