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.Unicode.Stream as SS
19import qualified Streamly.Internal.Data.Unicode.Stream as IUS
20import qualified Streamly.Internal.Memory.Unicode.Array as IUA
22-- Coverage build takes too long with default number of tests
32-- Use quickcheck-unicode instead?
33genUnicode :: Gen String
34genUnicode = listOf arbitraryUnicodeChar
36genWord8 :: Gen [Word8]
37genWord8 = listOf arbitrary
39propDecodeEncodeId :: Property
41 forAll genUnicode $ \list ->
43 let wrds = SS.encodeUtf8 $ S.fromList list
44 chrs <- S.toList $ SS.decodeUtf8 wrds
47-- XXX need to use invalid characters
48propDecodeEncodeIdLenient :: Property
49propDecodeEncodeIdLenient =
50 forAll genUnicode $ \list ->
52 let wrds = SS.encodeUtf8 $ S.fromList list
53 chrs <- S.toList $ SS.decodeUtf8Lax wrds
56propDecodeEncodeIdArrays :: Property
57propDecodeEncodeIdArrays =
58 forAll genUnicode $ \list ->
60 let wrds = SS.encodeUtf8 $ S.fromList list
61 chrs <- S.toList $ IUS.decodeUtf8ArraysLenient
67 forAll genUnicode $ \list ->
73 assert (xs == lines list)
75testLinesArray :: Property
77 forAll genWord8 $ \list ->
82 $ S.yield (A.fromList list)
83 assert (xs == map (map (fromIntegral . ord))
84 (lines (map (chr . fromIntegral) list)))
88 forAll genUnicode $ \list ->
94 assert (xs == words list)
96testUnlines :: Property
98 forAll genUnicode $ \list ->
104 assert (xs == unlines (lines list))
106testUnwords :: Property
108 forAll genUnicode $ \list ->
115 assert (xs == unwords (words list))
120 $ modifyMaxSuccess (const 1000)
122 describe "UTF8 - Encoding / Decoding" $ do
123 prop "decodeUtf8 . encodeUtf8 == id" $ propDecodeEncodeId
124 prop "decodeUtf8Lax . encodeUtf8 == id" $ propDecodeEncodeIdLenient
125 prop "decodeUtf8ArraysLenient . encodeUtf8 == id"
126 $ propDecodeEncodeIdArrays
127 prop "Streamly.Data.String.lines == Prelude.lines" $ testLines
128 prop "Arrays Streamly.Data.String.lines == Prelude.lines" $ testLinesArray
129 prop "Streamly.Data.String.words == Prelude.words" $ testWords
131 "Streamly.Data.String.unlines . Streamly.Data.String.lines == unlines . lines"
134 "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