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.Internal.Memory.ArrayStream as AS
17import qualified Streamly.Prelude as S
18import qualified Streamly.Data.String as SS
20-- Coverage build takes too long with default number of tests
30-- Use quickcheck-unicode instead?
31genUnicode :: Gen String
32genUnicode = listOf arbitraryUnicodeChar
34genWord8 :: Gen [Word8]
35genWord8 = listOf arbitrary
37propDecodeEncodeId :: Property
39 forAll genUnicode $ \list ->
41 let wrds = SS.encodeUtf8 $ S.fromList list
42 chrs <- S.toList $ SS.decodeUtf8 wrds
45-- XXX need to use invalid characters
46propDecodeEncodeIdLenient :: Property
47propDecodeEncodeIdLenient =
48 forAll genUnicode $ \list ->
50 let wrds = SS.encodeUtf8 $ S.fromList list
51 chrs <- S.toList $ SS.decodeUtf8Lenient wrds
54propDecodeEncodeIdArrays :: Property
55propDecodeEncodeIdArrays =
56 forAll genUnicode $ \list ->
58 let wrds = SS.encodeUtf8 $ S.fromList list
59 chrs <- S.toList $ SS.decodeUtf8ArraysLenient
65 forAll genUnicode $ \list ->
71 assert (xs == lines list)
73testLinesArray :: Property
75 forAll genWord8 $ \list ->
80 $ S.yield (A.fromList list)
81 assert (xs == map (map (fromIntegral . ord))
82 (lines (map (chr . fromIntegral) list)))
86 forAll genUnicode $ \list ->
92 assert (xs == words list)
94testUnlines :: Property
96 forAll genUnicode $ \list ->
102 assert (xs == unlines (lines list))
104testUnwords :: Property
106 forAll genUnicode $ \list ->
113 assert (xs == unwords (words list))
118 $ modifyMaxSuccess (const 1000)
120 describe "UTF8 - Encoding / Decoding" $ do
121 prop "decodeUtf8 . encodeUtf8 == id" $ propDecodeEncodeId
122 prop "decodeUtf8Lenient . encodeUtf8 == id" $ propDecodeEncodeIdLenient
123 prop "decodeUtf8ArraysLenient . encodeUtf8 == id"
124 $ propDecodeEncodeIdArrays
125 prop "Streamly.Data.String.lines == Prelude.lines" $ testLines
126 prop "Arrays Streamly.Data.String.lines == Prelude.lines" $ testLinesArray
127 prop "Streamly.Data.String.words == Prelude.words" $ testWords
129 "Streamly.Data.String.unlines . Streamly.Data.String.lines == unlines . lines"
132 "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