1{-# LANGUAGE OverloadedStrings #-}
3{-# OPTIONS_GHC -fno-warn-deprecations #-}
5module UnitTests.NullaryConstructors
13import Data.Aeson (decode, eitherDecode, fromEncoding, Value)
14import Data.Aeson.Internal (IResult (..), iparse)
15import Data.Aeson.Types (Parser)
16import Data.ByteString.Builder (toLazyByteString)
17import Data.Maybe (fromJust)
19import Test.HUnit ((@=?), Assertion)
21import qualified Data.ByteString.Lazy.Char8 as L
23nullaryConstructors :: [Assertion]
25 [ dec "\"C1\"" @=? thNullaryToJSONString C1
26 , dec "\"C1\"" @=? gNullaryToJSONString C1
27 , dec "{\"c1\":[]}" @=? thNullaryToJSONObjectWithSingleField C1
28 , dec "{\"c1\":[]}" @=? gNullaryToJSONObjectWithSingleField C1
29 , dec "[\"c1\",[]]" @=? gNullaryToJSON2ElemArray C1
30 , dec "[\"c1\",[]]" @=? thNullaryToJSON2ElemArray C1
31 , dec "{\"tag\":\"c1\"}" @=? thNullaryToJSONTaggedObject C1
32 , dec "{\"tag\":\"c1\"}" @=? gNullaryToJSONTaggedObject C1
34 , decE "\"C1\"" @=? enc (gNullaryToEncodingString C1)
35 , decE "\"C1\"" @=? enc (thNullaryToEncodingString C1)
36 , decE "[\"c1\",[]]" @=? enc (gNullaryToEncoding2ElemArray C1)
37 , decE "[\"c1\",[]]" @=? enc (thNullaryToEncoding2ElemArray C1)
38 , decE "{\"c1\":[]}" @=? enc (thNullaryToEncodingObjectWithSingleField C1)
39 , decE "{\"c1\":[]}" @=? enc (gNullaryToEncodingObjectWithSingleField C1)
40 , decE "{\"tag\":\"c1\"}" @=? enc (thNullaryToEncodingTaggedObject C1)
41 , decE "{\"tag\":\"c1\"}" @=? enc (gNullaryToEncodingTaggedObject C1)
43 , ISuccess C1 @=? parse thNullaryParseJSONTaggedObject (dec "{\"tag\":\"c1\"}")
44 , ISuccess C1 @=? parse gNullaryParseJSONTaggedObject (dec "{\"tag\":\"c1\"}")
46 , ISuccess C1 @=? parse thNullaryParseJSONString (dec "\"C1\"")
47 , ISuccess C1 @=? parse gNullaryParseJSONString (dec "\"C1\"")
48 , ISuccess C1 @=? parse thNullaryParseJSON2ElemArray (dec "[\"c1\",[]]")
49 , ISuccess C1 @=? parse gNullaryParseJSON2ElemArray (dec "[\"c1\",[]]")
50 , ISuccess C1 @=? parse thNullaryParseJSONObjectWithSingleField (dec "{\"c1\":[]}")
51 , ISuccess C1 @=? parse gNullaryParseJSONObjectWithSingleField (dec "{\"c1\":[]}")
52 -- Make sure that the old `"contents" : []' is still allowed
53 , ISuccess C1 @=? parse thNullaryParseJSONTaggedObject (dec "{\"tag\":\"c1\",\"contents\":[]}")
54 , ISuccess C1 @=? parse gNullaryParseJSONTaggedObject (dec "{\"tag\":\"c1\",\"contents\":[]}")
57 enc = eitherDecode . toLazyByteString . fromEncoding
58 dec :: L.ByteString -> Value
59 dec = fromJust . decode
60 decE :: L.ByteString -> Either String Value
62 parse :: (a -> Parser b) -> a -> IResult b
63 parse parsejson v = iparse parsejson v
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