on master help sign in
Expose doctest setup stanza in docs for FileSystem/Unicode (#2493)

Co-authored-by: Harendra Kumar <harendra@composewell.com>

commite301ee3e1e43315b783e8d118048b5da64913315 authorRanjeet Ranjan <ranjeetr@composewell.com> dateWed 9 Aug 2023, 23:09 (3 years ago) parentbe2b3d1
14 files changed+131−35
core/src/DocTestFileSystemHandle.hs+15 core/src/DocTestUnicodeParser.hs+9 core/src/DocTestUnicodeStream.hs+12 core/src/DocTestUnicodeString.hs+5 core/src/Streamly/FileSystem/Handle.hs+9 core/src/Streamly/Internal/FileSystem/Handle.hs+10−12 core/src/Streamly/Internal/Unicode/Array.hs+6 core/src/Streamly/Internal/Unicode/Parser.hs+9−4 core/src/Streamly/Internal/Unicode/Stream.hs+10−10 core/src/Streamly/Internal/Unicode/String.hs+11−6 core/src/Streamly/Unicode/Parser.hs+11−2 core/src/Streamly/Unicode/Stream.hs+9 core/src/Streamly/Unicode/String.hs+11−1 core/streamly-core.cabal+4
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 #-}
12#include "inline.hs"
23
34-- |
@@ -40,6 +41,12 @@
4041--
4142module Streamly.FileSystem.Handle
4243 (
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+
4350 -- * Singleton IO
4451 -- | Read or write a single buffer.
4552 getChunk
@@ -116,6 +123,8 @@ import System.IO (Handle)
116123import Streamly.Internal.FileSystem.Handle hiding (read, readChunks)
117124import Prelude hiding (read)
118125
126+#include "DocTestFileSystemHandle.hs"
127+
119128-- | Same as 'reader'
120129--
121130{-# DEPRECATED read "Please use 'reader' instead" #-}
core/src/Streamly/Internal/FileSystem/Handle.hs+10−12
@@ -1,3 +1,5 @@
1+{-# LANGUAGE CPP #-}
2+
13#include "inline.hs"
24
35-- |
@@ -25,6 +27,12 @@
2527--
2628module Streamly.Internal.FileSystem.Handle
2729 (
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+
2836 -- * Singleton APIs
2937 getChunk
3038 , getChunkOf
@@ -142,17 +150,7 @@ import qualified Streamly.Internal.Data.Stream as D
142150import qualified Streamly.Internal.Data.Unfold as UF
143151import qualified Streamly.Internal.Data.Stream.StreamK.Type as K (mkStream)
144152
145−-- $setup
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)
153+#include "DocTestFileSystemHandle.hs"
156154
157155-------------------------------------------------------------------------------
158156-- References
@@ -358,7 +356,7 @@ readWith size h = concatChunks $ readChunksWith size h
358356-- performed in sizes of
359357-- 'Streamly.Internal.Data.Array.Type.defaultChunkSize'.
360358--
361−-- >>> reader = Unfold.many Array.reader chunkReader
359+-- >>> reader = Unfold.many Array.reader Handle.chunkReader
362360--
363361{-# INLINE reader #-}
364362reader :: MonadIO m => Unfold m Handle Word8
core/src/Streamly/Internal/Unicode/Array.hs+6
@@ -14,6 +14,12 @@
1414--
1515module Streamly.Internal.Unicode.Array
1616 (
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+
1723 -- * Streams of Strings
1824 lines
1925 , words
core/src/Streamly/Internal/Unicode/Parser.hs+9−4
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12-- |
23-- Module : Streamly.Internal.Unicode.Parser
34-- Copyright : (c) 2021 Composewell Technologies
@@ -12,6 +13,12 @@
1213
1314module Streamly.Internal.Unicode.Parser
1415 (
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+
1522 -- * Generic
1623 char
1724 , charIgnoreCase
@@ -76,6 +83,8 @@ import qualified Streamly.Internal.Data.Parser as Parser
7683 , dropWhile
7784 )
7885
86+#include "DocTestUnicodeParser.hs"
87+
7988--------------------------------------------------------------------------------
8089-- Character classification
8190--------------------------------------------------------------------------------
@@ -571,10 +580,6 @@ mkDouble mantissa power =
571580-- This function does not accept \"NaN\" or \"Infinity\" string representations
572581-- of double values.
573582--
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−--
578583-- Definition:
579584--
580585-- >>> double = uncurry Unicode.mkDouble <$> Unicode.number
core/src/Streamly/Internal/Unicode/Stream.hs+10−10
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12-- |
23-- Module : Streamly.Internal.Unicode.Stream
34-- Copyright : (c) 2018 Composewell Technologies
@@ -11,6 +12,12 @@
1112
1213module Streamly.Internal.Unicode.Stream
1314 (
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+
1421 -- * Construction (Decoding)
1522 decodeLatin1
1623
@@ -122,14 +129,7 @@ import qualified Streamly.Internal.Data.Stream as D
122129
123130import Prelude hiding (lines, words, unlines, unwords)
124131
125−-- $setup
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
132+#include "DocTestUnicodeStream.hs"
133133
134134-------------------------------------------------------------------------------
135135-- Latin1 decoding
@@ -1026,7 +1026,7 @@ stripHead = Stream.dropWhile isSpace
10261026-- | Fold each line of the stream using the supplied 'Fold'
10271027-- and stream the result.
10281028--
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")
10301030-- ["lines","this","string","",""]
10311031--
10321032-- > lines = Stream.splitOnSuffix (== '\n')
@@ -1057,7 +1057,7 @@ isSpace c
10571057-- | Fold each word of the stream using the supplied 'Fold'
10581058-- and stream the result.
10591059--
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")
10611061-- ["fold","these","words"]
10621062--
10631063-- > words = Stream.wordsBy isSpace
core/src/Streamly/Internal/Unicode/String.hs+11−6
@@ -1,4 +1,5 @@
11{-# LANGUAGE TemplateHaskell #-}
2+{-# LANGUAGE CPP #-}
23-- |
34-- Module : Streamly.Internal.Unicode.String
45-- Copyright : (c) 2022 Composewell Technologies
@@ -31,7 +32,14 @@
3132-- using Haskell functions.
3233
3334module Streamly.Internal.Unicode.String
34− ( str
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+
42+ str
3543 ) where
3644
3745
@@ -49,11 +57,8 @@ import qualified Streamly.Internal.Data.Parser as Parser
4957import qualified Streamly.Data.Stream as Stream (fromList, parse)
5058import qualified Streamly.Internal.Unicode.Parser as Parser
5159
52−-- $setup
53−-- >>> :m
54−-- >>> :set -XQuasiQuotes
55−-- >>> import Streamly.Internal.Unicode.String
56−--
60+#include "DocTestUnicodeString.hs"
61+
5762--------------------------------------------------------------------------------
5863-- Parsing
5964--------------------------------------------------------------------------------
core/src/Streamly/Unicode/Parser.hs+11−2
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12-- |
23-- Module : Streamly.Unicode.Parser
34-- Copyright : (c) 2021 Composewell Technologies
@@ -12,9 +13,15 @@
1213
1314module Streamly.Unicode.Parser
1415 (
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
1621
17− -- Any char
22+ -- * Single Chars
23+
24+ -- Any char
1825 char
1926 , charIgnoreCase
2027
@@ -58,3 +65,5 @@ module Streamly.Unicode.Parser
5865where
5966
6067import Streamly.Internal.Unicode.Parser
68+
69+#include "DocTestUnicodeParser.hs"
core/src/Streamly/Unicode/Stream.hs+9
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12-- |
23-- Module : Streamly.Unicode.Stream
34-- Copyright : (c) 2020 Composewell Technologies
@@ -69,6 +70,12 @@
6970--
7071module Streamly.Unicode.Stream
7172 (
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+
7279 -- * Construction (Decoding)
7380 decodeLatin1
7481 , decodeUtf8
@@ -99,3 +106,5 @@ where
99106
100107import Streamly.Internal.Unicode.Stream
101108import 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 #-}
12-- |
23-- Module : Streamly.Unicode.String
34-- Copyright : (c) 2022 Composewell Technologies
@@ -13,8 +14,17 @@
1314-- resulting string to collapse it into a single line.
1415
1516module Streamly.Unicode.String
16− ( str
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+
24+ str
1725 )
1826where
1927
2028import Streamly.Internal.Unicode.String
29+
30+#include "DocTestUnicodeString.hs"
core/streamly-core.cabal+4
@@ -51,6 +51,10 @@ extra-source-files:
5151 src/DocTestDataStream.hs
5252 src/DocTestDataStreamK.hs
5353 src/DocTestDataUnfold.hs
54+ src/DocTestUnicodeParser.hs
55+ src/DocTestUnicodeStream.hs
56+ src/DocTestUnicodeString.hs
57+ src/DocTestFileSystemHandle.hs
5458
5559 -- This is duplicated
5660 src/Streamly/Internal/Data/Array/ArrayMacros.h