2{-# LANGUAGE FlexibleContexts #-}
4module Main (main) where
6import Data.Char (ord, chr)
7import Data.Word (Word8)
8import Test.Hspec.QuickCheck
10 (Property, forAll, Gen, listOf, arbitraryUnicodeChar, arbitrary)
11import Test.QuickCheck.Monadic (run, monadicIO, assert)
15import qualified Streamly.Memory.Array as A
16import qualified Streamly.Prelude as S
17import qualified Streamly.Data.String as SS
19-- Coverage build takes too long with default number of tests
29-- Use quickcheck-unicode instead?
30genUnicode :: Gen String
31genUnicode = listOf arbitraryUnicodeChar
33genWord8 :: Gen [Word8]
34genWord8 = listOf arbitrary
36propDecodeEncodeId :: Property
38 forAll genUnicode $ \list ->
40 let wrds = SS.encodeUtf8 $ S.fromList list
41 chrs <- S.toList $ SS.decodeUtf8 wrds
44-- XXX need to use invalid characters
45propDecodeEncodeIdLenient :: Property
46propDecodeEncodeIdLenient =
47 forAll genUnicode $ \list ->
49 let wrds = SS.encodeUtf8 $ S.fromList list
50 chrs <- S.toList $ SS.decodeUtf8Lenient wrds
53propDecodeEncodeIdArrays :: Property
54propDecodeEncodeIdArrays =
55 forAll genUnicode $ \list ->
57 let wrds = SS.encodeUtf8 $ S.fromList list
58 chrs <- S.toList $ SS.decodeUtf8ArraysLenient
59 (S.runFold A.write wrds)
64 forAll genUnicode $ \list ->
70 assert (xs == lines list)
72testLinesArray :: Property
74 forAll genWord8 $ \list ->
79 $ S.yield (A.fromList list)
80 assert (xs == map (map (fromIntegral . ord))
81 (lines (map (chr . fromIntegral) list)))
85 forAll genUnicode $ \list ->
91 assert (xs == words list)
93testUnlines :: Property
95 forAll genUnicode $ \list ->
101 assert (xs == unlines (lines list))
103testUnwords :: Property
105 forAll genUnicode $ \list ->
112 assert (xs == unwords (words list))
117 $ modifyMaxSuccess (const 1000)
119 describe "UTF8 - Encoding / Decoding" $ do
120 prop "decodeUtf8 . encodeUtf8 == id" $ propDecodeEncodeId
121 prop "decodeUtf8Lenient . encodeUtf8 == id" $ propDecodeEncodeIdLenient
122 prop "decodeUtf8ArraysLenient . encodeUtf8 == id"
123 $ propDecodeEncodeIdArrays
124 prop "Streamly.Data.String.lines == Prelude.lines" $ testLines
125 prop "Arrays Streamly.Data.String.lines == Prelude.lines" $ testLinesArray
126 prop "Streamly.Data.String.words == Prelude.words" $ testWords
128 "Streamly.Data.String.unlines . Streamly.Data.String.lines == unlines . lines"
131 "Streamly.Data.String.unwords . Streamly.Data.String.words == unwords . words"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list