-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.hs
93 lines (81 loc) · 3.35 KB
/
Test.hs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
-- Copyright 2015 Alvaro J. Genial (http://alva.ro) -- see LICENSE.md for more.
{-# LANGUAGE TypeFamilies #-}
import Codec.Binary.Base91 (decode, encode)
import Data.Word (Word8)
import Test.QuickCheck (quickCheck)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
main :: IO ()
main = do
testString
testByteString
testByteStringLazy
testText
testTextLazy
testByteString_Text
testByteStringLazy_TextLazy
where
-- Note that the reverse identities, e.g. encode (decode cs) == cs, aren't true because not every
-- arbitrary character sequence is valid Base91, even if each character is constrained to the
-- Base91 alphabet.
testString = do
quickCheck $ prop_identity
quickCheck $ example empty
quickCheck $ example helloWorld
where
prop_identity :: [Word8] -> Bool
prop_identity ws = decode (encode ws :: [Char]) == ws
example (ws, cs) = (encode ws :: [Char]) == cs && decode cs == ws
testByteString = do
quickCheck $ prop_identity
quickCheck $ example empty
quickCheck $ example helloWorld
where
prop_identity :: [Word8] -> Bool
prop_identity ws = decode (encode bs :: [Char]) == bs where bs = BS.pack ws
example (ws, cs) = (encode bs :: [Char]) == cs && decode cs == bs where bs = BS.pack ws
testByteStringLazy = do
quickCheck $ prop_identity
quickCheck $ example empty
quickCheck $ example helloWorld
where
prop_identity :: [Word8] -> Bool
prop_identity ws = decode (encode bs :: [Char]) == bs where bs = BSL.pack ws
example (ws, cs) = (encode bs :: [Char]) == cs && decode cs == bs where bs = BSL.pack ws
testText = do
quickCheck $ prop_identity
quickCheck $ example empty
quickCheck $ example helloWorld
where
prop_identity :: [Word8] -> Bool
prop_identity ws = decode (encode ws :: T.Text) == ws
example (ws, cs) = (encode ws :: T.Text) == t && decode t == ws where t = T.pack cs
testTextLazy = do
quickCheck $ prop_identity
quickCheck $ example empty
quickCheck $ example helloWorld
where
prop_identity :: [Word8] -> Bool
prop_identity ws = decode (encode ws :: TL.Text) == ws
example (ws, cs) = (encode ws :: TL.Text) == t && decode t == ws where t = TL.pack cs
testByteString_Text = do
quickCheck $ prop_identity
quickCheck $ example empty
quickCheck $ example helloWorld
where
prop_identity :: [Word8] -> Bool
prop_identity ws = decode (encode bs :: T.Text) == bs where bs = BS.pack ws
example (ws, cs) = (encode bs :: T.Text) == t && decode t == bs where (bs, t) = (BS.pack ws, T.pack cs)
testByteStringLazy_TextLazy = do
quickCheck $ prop_identity
quickCheck $ example empty
quickCheck $ example helloWorld
where
prop_identity :: [Word8] -> Bool
prop_identity ws = decode (encode bs :: TL.Text) == bs where bs = BSL.pack ws
example (ws, cs) = (encode bs :: TL.Text) == t && decode t == bs where (bs, t) = (BSL.pack ws, TL.pack cs)
empty, helloWorld :: ([Word8], [Char])
empty = ([], "")
helloWorld = ([72,101,108,108,111,44,32,119,111,114,108,100,33,10], ">OwJh>}A\"=r@@Y?FF") -- "Hello, World!\n"