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
|
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Main (main) where
import Data.Text (Text)
import qualified Data.Text.Normalize as T
import Data.Text.Normalize (NormalizationMode)
import QuickCheckUtils ()
import Test.Hspec.QuickCheck (modifyMaxSuccess, prop)
import Test.Hspec as H
import Test.QuickCheck (NonNegative(..))
import Unicode.Internal.Division (quotRem21, quotRem28)
#ifdef HAS_ICU
import Data.Text (pack)
#if MIN_VERSION_text_icu(0,8,0)
import qualified Data.Text.ICU.Normalize2 as ICU
#else
import qualified Data.Text.ICU.Normalize as ICU
#endif
toICUMode :: NormalizationMode -> ICU.NormalizationMode
toICUMode mode =
case mode of
T.NFD -> ICU.NFD
T.NFKD -> ICU.NFKD
T.NFC -> ICU.NFC
T.NFKC -> ICU.NFKC
t_normalizeCompareICU :: NormalizationMode -> Text -> Bool
t_normalizeCompareICU mode t =
T.normalize mode t == ICU.normalize (toICUMode mode) t
#else
import qualified Data.Text as T
-- WARNING! These tests do not check the correctness of the output they
-- only check whether a non empty output is produced.
t_nonEmpty :: (Text -> Text) -> Text -> Bool
t_nonEmpty f t
| T.null t = T.null ft
| otherwise = T.length ft > 0
where ft = f t
-- Normalization
t_normalize :: NormalizationMode -> Text -> Bool
t_normalize mode = t_nonEmpty $ T.normalize mode
#endif
main :: IO ()
main =
hspec
$ H.parallel
$ modifyMaxSuccess (const 10000)
$ do
prop "quotRem28" $ \(NonNegative n) -> n `quotRem` 28 == quotRem28 n
prop "quotRem28 maxBound" $ \(NonNegative n) ->
let n1 = maxBound - n
in n1 `quotRem` 28 == quotRem28 n1
prop "quotRem21" $ \(NonNegative n) -> n `quotRem` 21 == quotRem21 n
prop "quotRem21 maxBound" $ \(NonNegative n) ->
let n1 = maxBound - n
in n1 `quotRem` 21 == quotRem21 n1
#ifdef HAS_ICU
it "Compare \127340 with ICU" $
t_normalizeCompareICU T.NFKD (pack "\127340") `H.shouldBe` True
prop "Comparing random strings with ICU..." t_normalizeCompareICU
#else
prop "Checking non-empty results for random strings..." t_normalize
#endif
|