on master help sign in
Expose doctest setup stanza in docs for FileSystem/Unicode (#2493)
e301ee3Ranjeet Ranjan
core/src/DocTestFileSystemHandle.hsnew file+15
@@ -0,0 +1,15 @@
1+{- $setup
2+>>> :m
3+>>> import qualified Streamly.Data.Array as Array
4+>>> import qualified Streamly.FileSystem.Handle as Handle hiding (readChunks)
5+>>> import qualified Streamly.Data.Fold as Fold
6+>>> import qualified Streamly.Data.Stream as Stream
7+>>> import qualified Streamly.Data.Unfold as Unfold
8+
9+For APIs that have not been released yet.
10+
11+>>> import qualified Streamly.Internal.Data.Array.Type as Array (writeNUnsafe)
12+>>> import qualified Streamly.Internal.Data.Unfold as Unfold (first)
13+>>> import qualified Streamly.Internal.FileSystem.Handle as Handle
14+>>> import qualified Streamly.Internal.System.IO as IO (defaultChunkSize)
15+-}
core/src/DocTestUnicodeParser.hsnew file+9
@@ -0,0 +1,9 @@
1+{- $setup
2+>>> :m
3+>>> import qualified Streamly.Data.Stream as Stream
4+>>> import qualified Streamly.Unicode.Parser as Unicode
5+
6+For APIs that have not been released yet.
7+
8+>>> import qualified Streamly.Internal.Unicode.Parser as Unicode (number, mkDouble)
9+-}
core/src/DocTestUnicodeStream.hsnew file+12
@@ -0,0 +1,12 @@
1+{- $setup
2+>>> :m
3+
4+>>> import qualified Streamly.Data.Fold as Fold
5+>>> import qualified Streamly.Data.Stream as Stream
6+>>> import qualified Streamly.Unicode.Stream as Unicode
7+
8+For APIs that have not been released yet.
9+
10+>>> :set -XMagicHash
11+>>> import qualified Streamly.Internal.Unicode.Stream as Unicode
12+-}
core/src/DocTestUnicodeString.hsnew file+5
@@ -0,0 +1,5 @@
1+{- $setup
2+>>> :m
3+>>> :set -XQuasiQuotes
4+>>> import Streamly.Internal.Unicode.String
5+-}
core/src/Streamly/FileSystem/Handle.hs+9
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1#include "inline.hs"
2#include "inline.hs"
2
3
3-- |
4-- |
@@ -40,6 +41,12 @@
40--
41--
41module Streamly.FileSystem.Handle
42module Streamly.FileSystem.Handle
42 (
43 (
44+ -- * Setup
45+ -- | To execute the code examples provided in this module in ghci, please
46+ -- run the following commands first.
47+ --
48+ -- $setup
49+
43 -- * Singleton IO
50 -- * Singleton IO
44 -- | Read or write a single buffer.
51 -- | Read or write a single buffer.
45 getChunk
52 getChunk
@@ -116,6 +123,8 @@ import System.IO (Handle)
116import Streamly.Internal.FileSystem.Handle hiding (read, readChunks)
123import Streamly.Internal.FileSystem.Handle hiding (read, readChunks)
117import Prelude hiding (read)
124import Prelude hiding (read)
118
125
126+#include "DocTestFileSystemHandle.hs"
127+
119-- | Same as 'reader'
128-- | Same as 'reader'
120--
129--
121{-# DEPRECATED read "Please use 'reader' instead" #-}
130{-# DEPRECATED read "Please use 'reader' instead" #-}
core/src/Streamly/Internal/FileSystem/Handle.hs+10−12
@@ -1,3 +1,5 @@
1+{-# LANGUAGE CPP #-}
2+
1#include "inline.hs"
3#include "inline.hs"
2
4
3-- |
5-- |
@@ -25,6 +27,12 @@
25--
27--
26module Streamly.Internal.FileSystem.Handle
28module Streamly.Internal.FileSystem.Handle
27 (
29 (
30+ -- * Setup
31+ -- | To execute the code examples provided in this module in ghci, please
32+ -- run the following commands first.
33+ --
34+ -- $setup
35+
28 -- * Singleton APIs
36 -- * Singleton APIs
29 getChunk
37 getChunk
30 , getChunkOf
38 , getChunkOf
@@ -142,17 +150,7 @@ import qualified Streamly.Internal.Data.Stream as D
142import qualified Streamly.Internal.Data.Unfold as UF
150import qualified Streamly.Internal.Data.Unfold as UF
143import qualified Streamly.Internal.Data.Stream.StreamK.Type as K (mkStream)
151import qualified Streamly.Internal.Data.Stream.StreamK.Type as K (mkStream)
144
152
145−-- $setup
153+#include "DocTestFileSystemHandle.hs"
146−-- >>> import qualified Streamly.Data.Array as Array
147−-- >>> import qualified Streamly.Data.Fold as Fold
148−-- >>> import qualified Streamly.Data.Unfold as Unfold
149−-- >>> import qualified Streamly.Data.Stream as Stream
150−--
151−-- >>> import qualified Streamly.Internal.Data.Array.Type as Array (writeNUnsafe)
152−-- >>> import qualified Streamly.Internal.Data.Stream as Stream
153−-- >>> import qualified Streamly.Internal.Data.Unfold as Unfold (first)
154−-- >>> import qualified Streamly.Internal.FileSystem.Handle as Handle
155−-- >>> import qualified Streamly.Internal.System.IO as IO (defaultChunkSize)
156
154
157-------------------------------------------------------------------------------
155-------------------------------------------------------------------------------
158-- References
156-- References
@@ -358,7 +356,7 @@ readWith size h = concatChunks $ readChunksWith size h
358-- performed in sizes of
356-- performed in sizes of
359-- 'Streamly.Internal.Data.Array.Type.defaultChunkSize'.
357-- 'Streamly.Internal.Data.Array.Type.defaultChunkSize'.
360--
358--
361−-- >>> reader = Unfold.many Array.reader chunkReader
359+-- >>> reader = Unfold.many Array.reader Handle.chunkReader
362--
360--
363{-# INLINE reader #-}
361{-# INLINE reader #-}
364reader :: MonadIO m => Unfold m Handle Word8
362reader :: MonadIO m => Unfold m Handle Word8
core/src/Streamly/Internal/Unicode/Array.hs+6
@@ -14,6 +14,12 @@
14--
14--
15module Streamly.Internal.Unicode.Array
15module Streamly.Internal.Unicode.Array
16 (
16 (
17+ -- * Setup
18+ -- | To execute the code examples provided in this module in ghci, please
19+ -- run the following commands first.
20+ --
21+ -- $setup
22+
17 -- * Streams of Strings
23 -- * Streams of Strings
18 lines
24 lines
19 , words
25 , words
core/src/Streamly/Internal/Unicode/Parser.hs+9−4
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1-- |
2-- |
2-- Module : Streamly.Internal.Unicode.Parser
3-- Module : Streamly.Internal.Unicode.Parser
3-- Copyright : (c) 2021 Composewell Technologies
4-- Copyright : (c) 2021 Composewell Technologies
@@ -12,6 +13,12 @@
12
13
13module Streamly.Internal.Unicode.Parser
14module Streamly.Internal.Unicode.Parser
14 (
15 (
16+ -- * Setup
17+ -- | To execute the code examples provided in this module in ghci, please
18+ -- run the following commands first.
19+ --
20+ -- $setup
21+
15 -- * Generic
22 -- * Generic
16 char
23 char
17 , charIgnoreCase
24 , charIgnoreCase
@@ -76,6 +83,8 @@ import qualified Streamly.Internal.Data.Parser as Parser
76 , dropWhile
83 , dropWhile
77 )
84 )
78
85
86+#include "DocTestUnicodeParser.hs"
87+
79--------------------------------------------------------------------------------
88--------------------------------------------------------------------------------
80-- Character classification
89-- Character classification
81--------------------------------------------------------------------------------
90--------------------------------------------------------------------------------
@@ -571,10 +580,6 @@ mkDouble mantissa power =
571-- This function does not accept \"NaN\" or \"Infinity\" string representations
580-- This function does not accept \"NaN\" or \"Infinity\" string representations
572-- of double values.
581-- of double values.
573--
582--
574−-- >>> import qualified Streamly.Data.Stream as Stream
575−-- >>> import qualified Streamly.Unicode.Parser as Unicode
576−-- >>> import qualified Streamly.Internal.Unicode.Parser as Unicode (number, mkDouble)
577−--
578-- Definition:
583-- Definition:
579--
584--
580-- >>> double = uncurry Unicode.mkDouble <$> Unicode.number
585-- >>> double = uncurry Unicode.mkDouble <$> Unicode.number
core/src/Streamly/Internal/Unicode/Stream.hs+10−10
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1-- |
2-- |
2-- Module : Streamly.Internal.Unicode.Stream
3-- Module : Streamly.Internal.Unicode.Stream
3-- Copyright : (c) 2018 Composewell Technologies
4-- Copyright : (c) 2018 Composewell Technologies
@@ -11,6 +12,12 @@
11
12
12module Streamly.Internal.Unicode.Stream
13module Streamly.Internal.Unicode.Stream
13 (
14 (
15+ -- * Setup
16+ -- | To execute the code examples provided in this module in ghci, please
17+ -- run the following commands first.
18+ --
19+ -- $setup
20+
14 -- * Construction (Decoding)
21 -- * Construction (Decoding)
15 decodeLatin1
22 decodeLatin1
16
23
@@ -122,14 +129,7 @@ import qualified Streamly.Internal.Data.Stream as D
122
129
123import Prelude hiding (lines, words, unlines, unwords)
130import Prelude hiding (lines, words, unlines, unwords)
124
131
125−-- $setup
132+#include "DocTestUnicodeStream.hs"
126−-- >>> :m
127−-- >>> :set -XMagicHash
128−-- >>> import Prelude hiding (lines, words, unlines, unwords)
129−-- >>> import qualified Streamly.Data.Stream as Stream
130−-- >>> import qualified Streamly.Data.Fold as Fold
131−-- >>> import qualified Streamly.Internal.Unicode.Stream as Unicode
132−-- >>> import Streamly.Internal.Unicode.Stream
133
133
134-------------------------------------------------------------------------------
134-------------------------------------------------------------------------------
135-- Latin1 decoding
135-- Latin1 decoding
@@ -1026,7 +1026,7 @@ stripHead = Stream.dropWhile isSpace
1026-- | Fold each line of the stream using the supplied 'Fold'
1026-- | Fold each line of the stream using the supplied 'Fold'
1027-- and stream the result.
1027-- and stream the result.
1028--
1028--
1029−-- >>> Stream.fold Fold.toList $ lines Fold.toList (Stream.fromList "lines\nthis\nstring\n\n\n")
1029+-- >>> Stream.fold Fold.toList $ Unicode.lines Fold.toList (Stream.fromList "lines\nthis\nstring\n\n\n")
1030-- ["lines","this","string","",""]
1030-- ["lines","this","string","",""]
1031--
1031--
1032-- > lines = Stream.splitOnSuffix (== '\n')
1032-- > lines = Stream.splitOnSuffix (== '\n')
@@ -1057,7 +1057,7 @@ isSpace c
1057-- | Fold each word of the stream using the supplied 'Fold'
1057-- | Fold each word of the stream using the supplied 'Fold'
1058-- and stream the result.
1058-- and stream the result.
1059--
1059--
1060−-- >>> Stream.fold Fold.toList $ words Fold.toList (Stream.fromList "fold these words")
1060+-- >>> Stream.fold Fold.toList $ Unicode.words Fold.toList (Stream.fromList "fold these words")
1061-- ["fold","these","words"]
1061-- ["fold","these","words"]
1062--
1062--
1063-- > words = Stream.wordsBy isSpace
1063-- > words = Stream.wordsBy isSpace
core/src/Streamly/Internal/Unicode/String.hs+11−6
@@ -1,4 +1,5 @@
1{-# LANGUAGE TemplateHaskell #-}
1{-# LANGUAGE TemplateHaskell #-}
2+{-# LANGUAGE CPP #-}
2-- |
3-- |
3-- Module : Streamly.Internal.Unicode.String
4-- Module : Streamly.Internal.Unicode.String
4-- Copyright : (c) 2022 Composewell Technologies
5-- Copyright : (c) 2022 Composewell Technologies
@@ -31,7 +32,14 @@
31-- using Haskell functions.
32-- using Haskell functions.
32
33
33module Streamly.Internal.Unicode.String
34module Streamly.Internal.Unicode.String
35+ (
36+ -- * Setup
37+ -- | To execute the code examples provided in this module in ghci, please
38+ -- run the following commands first.
39+ --
40+ -- $setup
41+
34− ( str
42+ str
35 ) where
43 ) where
36
44
37
45
@@ -49,11 +57,8 @@ import qualified Streamly.Internal.Data.Parser as Parser
49import qualified Streamly.Data.Stream as Stream (fromList, parse)
57import qualified Streamly.Data.Stream as Stream (fromList, parse)
50import qualified Streamly.Internal.Unicode.Parser as Parser
58import qualified Streamly.Internal.Unicode.Parser as Parser
51
59
52−-- $setup
60+#include "DocTestUnicodeString.hs"
53−-- >>> :m
61+
54−-- >>> :set -XQuasiQuotes
55−-- >>> import Streamly.Internal.Unicode.String
56−--
57--------------------------------------------------------------------------------
62--------------------------------------------------------------------------------
58-- Parsing
63-- Parsing
59--------------------------------------------------------------------------------
64--------------------------------------------------------------------------------
core/src/Streamly/Unicode/Parser.hs+11−2
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1-- |
2-- |
2-- Module : Streamly.Unicode.Parser
3-- Module : Streamly.Unicode.Parser
3-- Copyright : (c) 2021 Composewell Technologies
4-- Copyright : (c) 2021 Composewell Technologies
@@ -12,9 +13,15 @@
12
13
13module Streamly.Unicode.Parser
14module Streamly.Unicode.Parser
14 (
15 (
15− -- * Single Chars
16+ -- * Setup
17+ -- | To execute the code examples provided in this module in ghci, please
18+ -- run the following commands first.
19+ --
20+ -- $setup
16
21
22+ -- * Single Chars
23+
17− -- Any char
24+ -- Any char
18 char
25 char
19 , charIgnoreCase
26 , charIgnoreCase
20
27
@@ -58,3 +65,5 @@ module Streamly.Unicode.Parser
58where
65where
59
66
60import Streamly.Internal.Unicode.Parser
67import Streamly.Internal.Unicode.Parser
68+
69+#include "DocTestUnicodeParser.hs"
core/src/Streamly/Unicode/Stream.hs+9
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1-- |
2-- |
2-- Module : Streamly.Unicode.Stream
3-- Module : Streamly.Unicode.Stream
3-- Copyright : (c) 2020 Composewell Technologies
4-- Copyright : (c) 2020 Composewell Technologies
@@ -69,6 +70,12 @@
69--
70--
70module Streamly.Unicode.Stream
71module Streamly.Unicode.Stream
71 (
72 (
73+ -- * Setup
74+ -- | To execute the code examples provided in this module in ghci, please
75+ -- run the following commands first.
76+ --
77+ -- $setup
78+
72 -- * Construction (Decoding)
79 -- * Construction (Decoding)
73 decodeLatin1
80 decodeLatin1
74 , decodeUtf8
81 , decodeUtf8
@@ -99,3 +106,5 @@ where
99
106
100import Streamly.Internal.Unicode.Stream
107import Streamly.Internal.Unicode.Stream
101import Prelude hiding (lines, words, unlines, unwords)
108import Prelude hiding (lines, words, unlines, unwords)
109+
110+#include "DocTestUnicodeStream.hs"
core/src/Streamly/Unicode/String.hs+11−1
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1-- |
2-- |
2-- Module : Streamly.Unicode.String
3-- Module : Streamly.Unicode.String
3-- Copyright : (c) 2022 Composewell Technologies
4-- Copyright : (c) 2022 Composewell Technologies
@@ -13,8 +14,17 @@
13-- resulting string to collapse it into a single line.
14-- resulting string to collapse it into a single line.
14
15
15module Streamly.Unicode.String
16module Streamly.Unicode.String
17+ (
18+ -- * Setup
19+ -- | To execute the code examples provided in this module in ghci, please
20+ -- run the following commands first.
21+ --
22+ -- $setup
23+
16− ( str
24+ str
17 )
25 )
18where
26where
19
27
20import Streamly.Internal.Unicode.String
28import Streamly.Internal.Unicode.String
29+
30+#include "DocTestUnicodeString.hs"
core/streamly-core.cabal+4
@@ -51,6 +51,10 @@ extra-source-files:
51 src/DocTestDataStream.hs
51 src/DocTestDataStream.hs
52 src/DocTestDataStreamK.hs
52 src/DocTestDataStreamK.hs
53 src/DocTestDataUnfold.hs
53 src/DocTestDataUnfold.hs
54+ src/DocTestUnicodeParser.hs
55+ src/DocTestUnicodeStream.hs
56+ src/DocTestUnicodeString.hs
57+ src/DocTestFileSystemHandle.hs
54
58
55 -- This is duplicated
59 -- This is duplicated
56 src/Streamly/Internal/Data/Array/ArrayMacros.h
60 src/Streamly/Internal/Data/Array/ArrayMacros.h