diff options
author | Andrew Cady <d@jerkface.net> | 2016-04-26 08:56:21 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2016-04-26 08:57:11 -0400 |
commit | f5fb4f27b4e9cecdc3afc2facc8e39717ea20524 (patch) | |
tree | c0ba039c0fb8eadfb4c22d9b370df997ff81aa19 /test-src |
This is just dataenc-0.14.0.7 from hackage with the upper bound on
'base' changed in dataenc.cabal.
I couldn't find a git repo to fork, so I used 'stack unpack'
Diffstat (limited to 'test-src')
-rw-r--r-- | test-src/DataencQC.hs | 137 | ||||
-rw-r--r-- | test-src/DataencUT.hs | 225 | ||||
-rw-r--r-- | test-src/Test.hs | 16 |
3 files changed, 378 insertions, 0 deletions
diff --git a/test-src/DataencQC.hs b/test-src/DataencQC.hs new file mode 100644 index 0000000..d35c09c --- /dev/null +++ b/test-src/DataencQC.hs | |||
@@ -0,0 +1,137 @@ | |||
1 | {-# OPTIONS_GHC -XTemplateHaskell #-} | ||
2 | |||
3 | {- | ||
4 | - Copyright : (c) 2007 Magnus Therning | ||
5 | - License : BSD3 | ||
6 | -} | ||
7 | |||
8 | module DataencQC | ||
9 | where | ||
10 | |||
11 | import Test.Framework.TH | ||
12 | |||
13 | import Data.Maybe | ||
14 | import Data.Word | ||
15 | import Test.QuickCheck | ||
16 | import Test.Framework.Providers.QuickCheck2 | ||
17 | |||
18 | import qualified Codec.Binary.Uu as Uu | ||
19 | import qualified Codec.Binary.Uu as Xx | ||
20 | import qualified Codec.Binary.Base85 as Base85 | ||
21 | import qualified Codec.Binary.Base64 as Base64 | ||
22 | import qualified Codec.Binary.Base64Url as Base64Url | ||
23 | import qualified Codec.Binary.Base32 as Base32 | ||
24 | import qualified Codec.Binary.Base32Hex as Base32Hex | ||
25 | import qualified Codec.Binary.Base16 as Base16 | ||
26 | import qualified Codec.Binary.Yenc as Yenc | ||
27 | import qualified Codec.Binary.QuotedPrintable as QP | ||
28 | import qualified Codec.Binary.PythonString as Py | ||
29 | import qualified Codec.Binary.Url as Url | ||
30 | |||
31 | -- {{{1 uuencode properties | ||
32 | prop_uuEncode ws = ws == (fromJust . Uu.decode . Uu.encode) ws | ||
33 | where types = ws::[Word8] | ||
34 | |||
35 | prop_uuChop n ws = s == (Uu.unchop . Uu.chop n) s | ||
36 | where | ||
37 | types = (n :: Int, ws::[Word8]) | ||
38 | s = Uu.encode ws | ||
39 | |||
40 | prop_uuCombined n ws = ws == fromJust (Uu.decode $ Uu.unchop $ Uu.chop n $ Uu.encode ws) | ||
41 | where types = (n::Int, ws::[Word8]) | ||
42 | |||
43 | -- {{{1 xxencode properties | ||
44 | prop_xxEncode ws = ws == (fromJust . Xx.decode . Xx.encode) ws | ||
45 | where types = ws::[Word8] | ||
46 | |||
47 | prop_xxChop n ws = s == (Xx.unchop . Xx.chop n) s | ||
48 | where | ||
49 | types = (n:: Int, ws::[Word8]) | ||
50 | s = Xx.encode ws | ||
51 | |||
52 | prop_xxCombined n ws = ws == fromJust (Xx.decode $ Xx.unchop $ Xx.chop n $ Xx.encode ws) | ||
53 | where types = (n::Int, ws::[Word8]) | ||
54 | |||
55 | -- {{{1 base85 properties | ||
56 | prop_base85Encode ws = ws == fromJust (Base85.decode $ Base85.encode ws) | ||
57 | where types = ws::[Word8] | ||
58 | |||
59 | prop_base85Chop n s = s == Base85.unchop (Base85.chop n s) | ||
60 | where types = (n::Int, s::String) | ||
61 | |||
62 | -- {{{1 base64 properties | ||
63 | prop_base64Encode ws = ws == fromJust (Base64.decode $ Base64.encode ws) | ||
64 | where types = ws::[Word8] | ||
65 | |||
66 | prop_base64Chop n s = s == Base64.unchop (Base64.chop n s) | ||
67 | where types = (n::Int, s::String) | ||
68 | |||
69 | -- {{{1 base64url properties | ||
70 | prop_base64UrlEncode ws = ws == fromJust (Base64Url.decode $ Base64Url.encode ws) | ||
71 | where types = ws::[Word8] | ||
72 | |||
73 | prop_base64UrlChop n s = s == Base64Url.unchop (Base64Url.chop n s) | ||
74 | where types = (n::Int, s::String) | ||
75 | |||
76 | -- {{{1 base32 | ||
77 | prop_base32Encode ws = ws == fromJust (Base32.decode $ Base32.encode ws) | ||
78 | where types = ws::[Word8] | ||
79 | |||
80 | prop_base32Chop n s = s == Base32.unchop (Base32.chop n s) | ||
81 | where types = (n::Int, s::String) | ||
82 | |||
83 | -- {{{1 base32hex | ||
84 | prop_base32HexEncode ws = ws == fromJust (Base32Hex.decode $ Base32Hex.encode ws) | ||
85 | where types = ws::[Word8] | ||
86 | |||
87 | prop_base32HexChop n s = s == Base32Hex.unchop (Base32Hex.chop n s) | ||
88 | where types = (n::Int, s::String) | ||
89 | |||
90 | -- {{{1 base16 | ||
91 | prop_base16Encode ws = ws == fromJust (Base16.decode $ Base16.encode ws) | ||
92 | where types = ws::[Word8] | ||
93 | |||
94 | prop_base16Chop n s = s == Base16.unchop (Base16.chop n s) | ||
95 | where types = (n::Int, s::String) | ||
96 | |||
97 | -- {{{1 yEncoding | ||
98 | prop_yencEncode ws = ws == fromJust (Yenc.decode $ Yenc.encode ws) | ||
99 | where types = ws ::[Word8] | ||
100 | |||
101 | prop_yencChop n ws = ws == Yenc.unchop (Yenc.chop n ws) | ||
102 | where types = (n::Int, ws :: [Word8]) | ||
103 | |||
104 | -- {{{1 qp | ||
105 | prop_qpEncode ws = ws == fromJust (QP.decode $ QP.encode ws) | ||
106 | where types = ws :: [Word8] | ||
107 | |||
108 | prop_qpChop n ws = s == (QP.unchop . QP.chop n) s | ||
109 | where | ||
110 | types = (n::Int, ws::[Word8]) | ||
111 | s = QP.encode ws | ||
112 | |||
113 | prop_qpCombined n ws = ws == fromJust (QP.decode $ QP.unchop $ QP.chop n $ QP.encode ws) | ||
114 | where types = (n::Int, ws::[Word8]) | ||
115 | |||
116 | -- {{{1 py | ||
117 | prop_pyEncode ws = ws == fromJust (Py.decode $ Py.encode ws) | ||
118 | where types = ws :: [Word8] | ||
119 | |||
120 | prop_pyChop n s = s == Py.unchop (Py.chop n s) | ||
121 | where types = (n :: Int, s :: String) | ||
122 | |||
123 | prop_pyCombined n ws = ws == fromJust (runAll ws) | ||
124 | where runAll = Py.decode . Py.unchop . Py.chop n . Py.encode | ||
125 | |||
126 | -- {{{1 url | ||
127 | prop_urlEncode ws = ws == fromJust (Url.decode $ Url.encode ws) | ||
128 | where types = ws :: [Word8] | ||
129 | |||
130 | prop_urlChop n s = s == Url.unchop (Url.chop n s) | ||
131 | where types = (n :: Int, s :: String) | ||
132 | |||
133 | prop_urlCombined n ws = ws == fromJust (runAll ws) | ||
134 | where runAll = Url.decode . Url.unchop . Url.chop n . Url.encode | ||
135 | |||
136 | -- {{{1 all the tests | ||
137 | allTests = $(testGroupGenerator) | ||
diff --git a/test-src/DataencUT.hs b/test-src/DataencUT.hs new file mode 100644 index 0000000..af91a0f --- /dev/null +++ b/test-src/DataencUT.hs | |||
@@ -0,0 +1,225 @@ | |||
1 | {-# OPTIONS_GHC -XTemplateHaskell #-} | ||
2 | {- | ||
3 | - Copyright : (c) 2007 Magnus Therning | ||
4 | - License : BSD3 | ||
5 | -} | ||
6 | |||
7 | module DataencUT | ||
8 | where | ||
9 | |||
10 | import Test.HUnit | ||
11 | import Control.Monad | ||
12 | import System.Exit | ||
13 | import Data.Maybe | ||
14 | import qualified Test.Framework.Providers.API as TFAPI | ||
15 | import Test.Framework.TH | ||
16 | import Test.Framework.Providers.HUnit | ||
17 | |||
18 | import Codec.Binary.DataEncoding | ||
19 | import qualified Codec.Binary.Yenc as Yenc | ||
20 | |||
21 | -- {{{1 checkAssertions | ||
22 | checkAssertions (suite, desc, enc, dec, codec) = do | ||
23 | enc @=? encode codec dec | ||
24 | dec @=? fromJust (decode codec enc) | ||
25 | |||
26 | -- {{{1 uuencode tests | ||
27 | uuTestData = | ||
28 | [ ("uu", "empty", "", [], uu) | ||
29 | , ("uu", "\\0", "``", [0], uu) | ||
30 | , ("uu", "\\255", "_P", [255], uu) | ||
31 | , ("uu", "AA", "04$", [65, 65], uu) | ||
32 | , ("uu", "AAA", "04%!", [65, 65, 65], uu) | ||
33 | , ("uu", "AAAA", "04%!00", [65, 65, 65, 65], uu) | ||
34 | , ("uu", "Example", "17AA;7!L90", [69,120,97,109,112,108,101], uu) | ||
35 | ] | ||
36 | case_uuTests = mapM_ checkAssertions uuTestData | ||
37 | |||
38 | case_uuTests2 = do | ||
39 | "EI2" @=? unchop uu (chop uu 1 "EI2") | ||
40 | "EI3-" @=? unchop uu (chop uu 1 "EI3-") | ||
41 | "EI3-EE" @=? unchop uu (chop uu 1 "EI3-EE") | ||
42 | [0..255] @=? fromJust (decode uu $ unchop uu $ chop uu 1 $ encode uu [0..255]) | ||
43 | [0..255] @=? fromJust (decode uu $ unchop uu $ chop uu 61 $ encode uu [0..255]) | ||
44 | [0..255] @=? fromJust (decode uu $ unchop uu $ chop uu 100 $ encode uu [0..255]) | ||
45 | |||
46 | case_uuTestsFail = do | ||
47 | Nothing @=? decode uu "A" | ||
48 | Nothing @=? decode uu "aa" | ||
49 | |||
50 | -- {{{1 xxencode tests | ||
51 | xxTestData = | ||
52 | [ ("xx", "empty", "", [], xx) | ||
53 | , ("xx", "\\0", "++", [0], xx) | ||
54 | , ("xx", "\\255", "zk", [255], xx) | ||
55 | , ("xx", "AA", "EI2", [65, 65], xx) | ||
56 | , ("xx", "AAA", "EI3-", [65, 65, 65], xx) | ||
57 | , ("xx", "AAAA", "EI3-EE", [65, 65, 65, 65], xx) | ||
58 | , ("xx", "Example", "FLVVPL-gNE", [69,120,97,109,112,108,101], xx) | ||
59 | ] | ||
60 | case_xxTest = mapM_ checkAssertions xxTestData | ||
61 | |||
62 | case_xxTests2 = do | ||
63 | "EI2" @=? unchop xx (chop xx 1 "EI2") | ||
64 | "EI3-" @=? unchop xx (chop xx 1 "EI3-") | ||
65 | "EI3-EE" @=? unchop xx (chop xx 1 "EI3-EE") | ||
66 | [0..255] @=? fromJust (decode xx $ unchop xx $ chop xx 1 $ encode xx [0..255]) | ||
67 | [0..255] @=? fromJust (decode xx $ unchop xx $ chop xx 61 $ encode xx [0..255]) | ||
68 | [0..255] @=? fromJust (decode xx $ unchop xx $ chop xx 100 $ encode xx [0..255]) | ||
69 | |||
70 | case_xxTestsFail = do | ||
71 | Nothing @=? decode xx "A" | ||
72 | Nothing @=? decode xx "''" | ||
73 | |||
74 | -- {{{1 base85 tests | ||
75 | base85TestData = | ||
76 | [ ("base85", "empty", "", [], base85) | ||
77 | , ("base85", "f", "Ac", [102], base85) | ||
78 | , ("base85", "fo", "Ao@", [102,111], base85) | ||
79 | , ("base85", "foo", "AoDS", [102,111,111], base85) | ||
80 | , ("base85", "foob", "AoDTs", [102,111,111,98], base85) | ||
81 | , ("base85", "fooba", "AoDTs@/", [102,111,111,98,97], base85) | ||
82 | , ("base85", "foobar", "AoDTs@<)", [102,111,111,98,97,114], base85) | ||
83 | , ("base85", "\0", "!!", [0], base85) | ||
84 | , ("base85", "foob\0\0\0\0ar", "AoDTszEW", [102,111,111,98,0,0,0,0,114], base85) | ||
85 | , ("base85", "Example", "7<i6XE,9(", [69,120,97,109,112,108,101], base85) | ||
86 | , ("base85", "zeros", "z", [0, 0, 0, 0], base85) | ||
87 | , ("base85", "spaces", "y", [0x20, 0x20, 0x20, 0x20], base85) | ||
88 | ] | ||
89 | case_base85Tests = mapM_ checkAssertions base85TestData | ||
90 | |||
91 | case_base85TestsFail = do | ||
92 | Nothing @=? decode base85 "A" | ||
93 | Nothing @=? decode base85 "!z" | ||
94 | Nothing @=? decode base85 "!z!" | ||
95 | Nothing @=? decode base85 "!z!z" | ||
96 | |||
97 | -- {{{1 base64 tests | ||
98 | base64TestData = | ||
99 | [ ("base64", "empty", "", [], base64) | ||
100 | , ("base64", "f", "Zg==", [102], base64) | ||
101 | , ("base64", "fo", "Zm8=", [102,111], base64) | ||
102 | , ("base64", "foo", "Zm9v", [102,111,111], base64) | ||
103 | , ("base64", "foob", "Zm9vYg==", [102,111,111,98], base64) | ||
104 | , ("base64", "fooba", "Zm9vYmE=", [102,111,111,98,97], base64) | ||
105 | , ("base64", "foobar", "Zm9vYmFy", [102,111,111,98,97,114], base64) | ||
106 | , ("base64", "\0", "AA==", [0], base64) | ||
107 | , ("base64", "\255", "/w==", [255], base64) | ||
108 | , ("base64", "Example", "RXhhbXBsZQ==", [69,120,97,109,112,108,101], base64) | ||
109 | ] | ||
110 | case_base64Tests = mapM_ checkAssertions base64TestData | ||
111 | |||
112 | case_base64TestsFail = do | ||
113 | Nothing @=? decode base64 "A" | ||
114 | Nothing @=? decode base64 "!!" | ||
115 | |||
116 | -- {{{1 base64url tests | ||
117 | base64UrlTestData = | ||
118 | [ ("base64url", "empty", "", [], base64Url) | ||
119 | , ("base64url", "\0", "AA==", [0], base64Url) | ||
120 | , ("base64url", "\255", "_w==", [255], base64Url) | ||
121 | , ("base64url", "Example", "RXhhbXBsZQ==", [69,120,97,109,112,108,101], base64Url) | ||
122 | ] | ||
123 | case_base64UrlTests = mapM_ checkAssertions base64UrlTestData | ||
124 | |||
125 | -- {{{1 base32 tests | ||
126 | base32TestData = | ||
127 | [ ("base32", "empty", "", [], base32) | ||
128 | , ("base32", "f", "MY======", [102], base32) | ||
129 | , ("base32", "fo", "MZXQ====", [102,111], base32) | ||
130 | , ("base32", "foo", "MZXW6===", [102,111,111], base32) | ||
131 | , ("base32", "foob", "MZXW6YQ=", [102,111,111,98], base32) | ||
132 | , ("base32", "fooba", "MZXW6YTB", [102,111,111,98,97], base32) | ||
133 | , ("base32", "foobar", "MZXW6YTBOI======", [102,111,111,98,97,114], base32) | ||
134 | ] | ||
135 | case_base32Tests = mapM_ checkAssertions base32TestData | ||
136 | |||
137 | case_base32TestsFail = do | ||
138 | Nothing @=? decode base32 "A" | ||
139 | Nothing @=? decode base32 "gh" | ||
140 | |||
141 | -- {{{1 base32hex tests | ||
142 | base32HexTestData = | ||
143 | [ ("base32hex", "empty", "", [], base32Hex) | ||
144 | , ("base32hex", "f", "CO======", [102], base32Hex) | ||
145 | , ("base32hex", "fo", "CPNG====", [102,111], base32Hex) | ||
146 | , ("base32hex", "foo", "CPNMU===", [102,111,111], base32Hex) | ||
147 | , ("base32hex", "foob", "CPNMUOG=", [102,111,111,98], base32Hex) | ||
148 | , ("base32hex", "fooba", "CPNMUOJ1", [102,111,111,98,97], base32Hex) | ||
149 | , ("base32hex", "foobar", "CPNMUOJ1E8======", [102,111,111,98,97,114], base32Hex) | ||
150 | ] | ||
151 | case_base32HexTests = mapM_ checkAssertions base32HexTestData | ||
152 | |||
153 | case_base32HexTestsFail = do | ||
154 | Nothing @=? decode base32Hex "A" | ||
155 | Nothing @=? decode base32Hex "gh" | ||
156 | |||
157 | -- {{{1 base16 (hex) | ||
158 | base16TestData = | ||
159 | [ ("base16", "empty", "", [], base16) | ||
160 | , ("base16", "f", "66", [102], base16) | ||
161 | , ("base16", "fo", "666F", [102,111], base16) | ||
162 | , ("base16", "foo", "666F6F", [102,111,111], base16) | ||
163 | , ("base16", "foob", "666F6F62", [102,111,111,98], base16) | ||
164 | , ("base16", "fooba", "666F6F6261", [102,111,111,98,97], base16) | ||
165 | , ("base16", "foobar", "666F6F626172", [102,111,111,98,97,114], base16) | ||
166 | ] | ||
167 | case_base16Tests = mapM_ checkAssertions base16TestData | ||
168 | |||
169 | case_base16TestsFail = do | ||
170 | Nothing @=? decode base16 "A" | ||
171 | Nothing @=? decode base16 "GH" | ||
172 | |||
173 | -- {{{1 yEncoding | ||
174 | case_yencTests = do | ||
175 | [] @=? Yenc.encode [] | ||
176 | Just [] @=? Yenc.decode [] | ||
177 | [0x90] @=? Yenc.encode [0x66] | ||
178 | Just [0x66] @=? Yenc.decode [0x90] | ||
179 | [0x90, 0x99, 0x99, 0x8c, 0x8b, 0x9c] @=? Yenc.encode [0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72] | ||
180 | Just [0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72] @=? Yenc.decode [0x90, 0x99, 0x99, 0x8c, 0x8b, 0x9c] | ||
181 | [0x3d, 0x40, 0x01] @=? Yenc.encode [0xd6, 0xd7] | ||
182 | Just [0xd6, 0xd7] @=? Yenc.decode [0x3d, 0x40, 0x01] | ||
183 | [0x3d, 0x40, 0x3d, 0x4a, 0x3d, 0x4d, 0x3d, 0x7d] @=? Yenc.encode [0xd6, 0xe0, 0xe3, 0x13] | ||
184 | Just [0xd6, 0xe0, 0xe3, 0x13] @=? Yenc.decode [0x3d, 0x40, 0x3d, 0x4a, 0x3d, 0x4d, 0x3d, 0x7d] | ||
185 | [[0x3d, 0x40], [0x01, 0x3d, 0x4a]] @=? Yenc.chop 2 [0x3d, 0x40, 0x01, 0x3d, 0x4a] | ||
186 | |||
187 | -- {{{1 quoted-printable | ||
188 | qpTestData = | ||
189 | [ ("qp", "empty", "", [], qp) | ||
190 | , ("qp", "foo=bar", "foo=3Dbar", [102,111,111,61,98,97,114], qp) | ||
191 | ] | ||
192 | case_qpTests = mapM_ checkAssertions qpTestData | ||
193 | |||
194 | case_qpTestsSucc = do | ||
195 | ["foo=","=3D=","bar"] @=? chop qp 4 "foo=3Dbar" | ||
196 | |||
197 | case_qpTestsFail = do | ||
198 | Nothing @=? decode qp "=4" | ||
199 | Nothing @=? decode qp "=G" | ||
200 | |||
201 | -- {{{1 python string | ||
202 | pyTestData = | ||
203 | [ ("py", "empty", "", [], py) | ||
204 | , ("py", "<0x00><0x1f><0x20><0x7e><0x7f><0xff>", "\\x00\\x1F ~\\x7F\\xFF", [0x00, 0x1f, 0x20, 0x7e, 0x7f, 0xff], py) | ||
205 | , ("py", "\"\'\\", "\\\"\\'\\\\", [34, 39, 92], py) | ||
206 | ] | ||
207 | case_pyTests = mapM_ checkAssertions pyTestData | ||
208 | |||
209 | case_pyTestsFail = do | ||
210 | Nothing @=? decode py "\\z" | ||
211 | |||
212 | -- {{{1 url encoding | ||
213 | urlTestData = | ||
214 | [ ("url", "empty", "", [], url) | ||
215 | , ("url", "aA", "aA", [97, 65], url) | ||
216 | , ("url", "~ ", "~%20", [126, 0x20], url) | ||
217 | ] | ||
218 | case_urlTests = mapM_ checkAssertions urlTestData | ||
219 | |||
220 | case_urlTestsFail = do | ||
221 | Nothing @=? decode url "%ga" | ||
222 | Nothing @=? decode url "%%" | ||
223 | |||
224 | -- {{{1 all the tests | ||
225 | allTests = $(testGroupGenerator) | ||
diff --git a/test-src/Test.hs b/test-src/Test.hs new file mode 100644 index 0000000..2155bdf --- /dev/null +++ b/test-src/Test.hs | |||
@@ -0,0 +1,16 @@ | |||
1 | {- | ||
2 | - Copyright : (c) 2009 Magnus Therning | ||
3 | - License : BSD3 | ||
4 | -} | ||
5 | |||
6 | module Main | ||
7 | where | ||
8 | |||
9 | import Test.Framework | ||
10 | |||
11 | import qualified DataencQC as DQC | ||
12 | import qualified DataencUT as DUT | ||
13 | |||
14 | tests = [ DQC.allTests , DUT.allTests ] | ||
15 | |||
16 | main = defaultMain tests | ||