Skip to content

Commit ec15d53

Browse files
committed
Test array encoding
1 parent 2141a13 commit ec15d53

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/Json.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ emptyObjectValue :: Value
127127
emptyObjectValue = Object ChunksNil
128128

129129
isSpace :: Word8 -> Prelude.Bool
130+
{-# inline isSpace #-}
130131
isSpace w =
131132
w == c2w ' '
132133
|| w == c2w '\t'
@@ -234,6 +235,7 @@ parser = \case
234235
_ -> P.fail InvalidLeader
235236

236237
objectTrailedByBrace :: Parser SyntaxException s Value
238+
{-# inline objectTrailedByBrace #-}
237239
objectTrailedByBrace = do
238240
P.skipWhile isSpace
239241
Latin.any IncompleteObject >>= \case
@@ -280,6 +282,7 @@ objectStep !b = do
280282
--
281283
-- This parser handles everything after the LBRACKET character.
282284
arrayTrailedByBracket :: Parser SyntaxException s Value
285+
{-# inline arrayTrailedByBracket #-}
283286
arrayTrailedByBracket = do
284287
P.skipWhile isSpace
285288
Latin.any IncompleteArray >>= \case

test/Main.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import Control.Monad (when)
55
import Data.ByteString.Short.Internal (ShortByteString(SBS))
66
import Data.Bytes (Bytes)
7+
import Data.Chunks (Chunks(ChunksCons,ChunksNil))
78
import Data.Primitive (ByteArray(ByteArray))
89
import Data.Scientific (Scientific,scientific)
910
import Data.Text.Short (ShortText)
@@ -62,6 +63,14 @@ tests = testGroup "Tests"
6263
, THU.testCase "H" $ case J.decode (shortTextToBytes " [] x") of
6364
Left _ -> pure ()
6465
Right _ -> fail "this was not supposed parse"
66+
, THU.testCase "I" $
67+
BChunks.concat (Builder.run 1 (J.encode (J.Array (ChunksCons mempty ChunksNil))))
68+
@=?
69+
Bytes.fromLatinString "[]"
70+
, THU.testCase "J" $
71+
BChunks.concat (Builder.run 1 (J.encode (J.Array ChunksNil)))
72+
@=?
73+
Bytes.fromLatinString "[]"
6574
, THU.testCase "Twitter100" $
6675
case J.decode (Bytes.fromByteArray encodedTwitter100) of
6776
Left _ -> fail "nope"

0 commit comments

Comments
 (0)