Skip to content

Commit 7629820

Browse files
committed
doc: additional docs and tests
1 parent 7c23771 commit 7629820

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

β€Žsrc/Flat/Decoder/Strict.hsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ dUTF16 :: Get T.Text
247247
dUTF16 = do
248248
_ <- dFiller
249249
#if MIN_VERSION_text(2,0,0)
250-
-- Checked decoding
250+
-- Checked decoding (from UTF-8)
251251
T.decodeUtf16LE <$> dByteString_
252252
#else
253-
-- Unchecked decoding
253+
-- Unchecked decoding (already UTF16)
254254
(ByteArray array, lengthInBytes) <- dByteArray_
255255
return (T.Text (TA.Array array) 0 (lengthInBytes `div` 2))
256256
#endif

β€Žsrc/Flat/Instances/Test.hsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Flat.Instances.Test (
1313
import Control.Monad ((>=>))
1414
import Data.Word
1515
import Flat.Bits (Bits, asBytes, bits,
16-
paddedBits, takeBits)
16+
paddedBits, takeBits,toBools)
1717
import Flat.Class (Flat (..))
1818
import Flat.Encoder.Prim (eFillerF)
1919
import Flat.Encoder.Strict (Encoding (Encoding),
@@ -24,7 +24,7 @@ import Text.PrettyPrint.HughesPJClass (prettyShow)
2424

2525
-- | Returns: result of flat/unflat test, encoding size in bits, byte encoding
2626
tst :: (Eq a, Flat a) => a -> (Bool, NumBits, [Word8])
27-
tst v = (unflat (flat v) == Right v, size v 0, showBytes v)
27+
tst v = (unflat (flat v) == Right v && size v 0 >= length (toBools (bits v)), size v 0, showBytes v)
2828

2929
-- | Returns: result of flat/unflat test, encoding size in bits, bits encoding
3030
tstBits :: (Eq a, Flat a) => a -> (Bool, NumBits, String)

β€Žsrc/Flat/Instances/Text.hsβ€Ž

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,26 @@ import Flat.Instances.Util
1818
-- >>> import qualified Data.Text as T
1919
-- >>> import qualified Data.Text.Lazy as TL
2020
-- >>> import Data.Word
21+
-- >>> tt t = let (ts,_,bs) = tst t in (ts,bs)
2122

22-
{-|
23+
{- |
2324
Text (and Data.Text.Lazy) is encoded as a byte aligned array of bytes corresponding to its UTF8 encoding.
2425
25-
>>> tst $ T.pack ""
26-
(True,16,[1,0])
26+
>>> tt $ T.pack ""
27+
(True,[1,0])
2728
28-
>>> tst $ T.pack "aaa"
29-
(True,120,[1,3,97,97,97,0])
29+
>>> tt $ T.pack "aaa"
30+
(True,[1,3,97,97,97,0])
3031
31-
>>> tst $ T.pack "Β’Β’Β’"
32-
(True,120,[1,6,194,162,194,162,194,162,0])
32+
>>> tt $ T.pack "Β’Β’Β’"
33+
(True,[1,6,194,162,194,162,194,162,0])
3334
34-
>>> tst $ T.pack "ζ—₯ζ—₯ζ—₯"
35-
(True,120,[1,9,230,151,165,230,151,165,230,151,165,0])
35+
>>> tt $ T.pack "ζ—₯ζ—₯ζ—₯"
36+
(True,[1,9,230,151,165,230,151,165,230,151,165,0])
3637
3738
#ifndef ETA
38-
>>> tst $ T.pack "𐍈𐍈𐍈"
39-
(True,120,[1,12,240,144,141,136,240,144,141,136,240,144,141,136,0])
39+
>>> tt $ T.pack "𐍈𐍈𐍈"
40+
(True,[1,12,240,144,141,136,240,144,141,136,240,144,141,136,0])
4041
#endif
4142
4243
Strict and Lazy Text have the same encoding:
@@ -62,7 +63,7 @@ The default encoding is UTF8:
6263
>>> tst (UTF8Text $ T.pack "ζ—₯ζ—₯ζ—₯") == tst (T.pack "ζ—₯ζ—₯ζ—₯")
6364
True
6465
-}
65-
-- |A wrapper to encode/decode Text as UTF8 (slower but more compact)
66+
-- |A wrapper to encode/decode Text as UTF8
6667
newtype UTF8Text = UTF8Text {unUTF8::T.Text} deriving (Eq,Ord,Show)
6768

6869
instance Flat UTF8Text where
@@ -72,11 +73,11 @@ instance Flat UTF8Text where
7273

7374
#if ! defined (ETA_VERSION) && ! defined (ETA)
7475
{-|
75-
>>> tst (UTF16Text $ T.pack "aaa")
76-
(True,72,[1,6,97,0,97,0,97,0,0])
76+
>>> tt (UTF16Text $ T.pack "aaa")
77+
(True,[1,6,97,0,97,0,97,0,0])
7778
78-
>>> tst (UTF16Text $ T.pack "𐍈𐍈𐍈")
79-
(True,120,[1,12,0,216,72,223,0,216,72,223,0,216,72,223,0])
79+
>>> tt (UTF16Text $ T.pack "𐍈𐍈𐍈")
80+
(True,[1,12,0,216,72,223,0,216,72,223,0,216,72,223,0])
8081
-}
8182

8283
-- |A wrapper to encode/decode Text as UTF16

0 commit comments

Comments
Β (0)