1 {-# LANGUAGE OverloadedStrings #-}
3 -- to suppress WARNING in "Distribution.Compat.Prelude.Internal"
4 {-# OPTIONS_GHC -fno-warn-deprecations #-}
6 module UnitTests
.Distribution
.Utils
.Generic
( tests
) where
9 import Distribution
.Compat
.Prelude
.Internal
11 import Distribution
.Utils
.Generic
13 import qualified Data
.ByteString
.Char8
as BS
14 import qualified Data
.Text
as T
15 import qualified Data
.Text
.Encoding
as T
18 import Test
.Tasty
.HUnit
19 import Test
.Tasty
.QuickCheck
23 [ -- fromUTF8BS / toUTF8BS
24 testCase
"fromUTF8BS mempty" testFromUTF8BSEmpty
25 , testCase
"toUTF8BS mempty" testToUTF8BSEmpty
26 , testCase
"toUTF8BS [U+D800..U+DFFF]" testToUTF8BSSurr
27 , testCase
"toUTF8BS [U+0000..U+7F]" testToUTF8BSAscii
28 , testCase
"toUTF8BS [U+0000..U+10FFFF]" testToUTF8BSText
29 , testCase
"fromUTF8BS.toUTF8BS [U+0000..U+10FFFF]" testToFromUTF8BS
31 , testProperty
"fromUTF8BS.toUTF8BS == id" prop_toFromUTF8BS
32 , testProperty
"toUTF8BS == encodeUtf8" prop_toUTF8BS
34 , testProperty
"Nothing = validateUtf8 (encodeUtf8 x)" prop_validateUtf8
37 testFromUTF8BSEmpty
:: Assertion
38 testFromUTF8BSEmpty
= mempty
@=? fromUTF8BS mempty
40 testToUTF8BSEmpty
:: Assertion
41 testToUTF8BSEmpty
= mempty
@=? toUTF8BS mempty
43 testToUTF8BSSurr
:: Assertion
44 testToUTF8BSSurr
= BS
.concat (replicate 2048 u_fffd
) @=? toUTF8BS surrogates
46 surrogates
= ['\xD800
'..'\xDFFF
']
47 u_fffd
= "\xEF\xBF\xBD"
49 testToUTF8BSText
:: Assertion
50 testToUTF8BSText
= T
.encodeUtf8
(T
.pack txt
) @=? toUTF8BS txt
52 txt
= ['\x00'..'\x10FFFF
']
54 testToUTF8BSAscii
:: Assertion
55 testToUTF8BSAscii
= BS
.pack txt
@=? toUTF8BS txt
57 txt
= ['\x00'..'\x7F']
59 testToFromUTF8BS
:: Assertion
60 testToFromUTF8BS
= txt
@=?
(fromUTF8BS
. toUTF8BS
) txt
62 txt
= ['\x0000
'..'\xD7FF
'] ++ ['\xE000
'..'\x10FFFF
']
64 prop_toFromUTF8BS
:: [Char] -> Property
65 prop_toFromUTF8BS txt
= txt
=== (fromUTF8BS
. toUTF8BS
) txt
67 prop_toUTF8BS
:: [Char] -> Property
68 prop_toUTF8BS txt
= T
.encodeUtf8
(T
.pack txt
) === toUTF8BS txt
70 prop_validateUtf8
:: [Char] -> Property
71 prop_validateUtf8 txt
= Nothing
=== validateUTF8
(toUTF8BS txt
)