@@ -24,9 +24,13 @@ import Test.Tasty.Golden.Advanced (goldenTest)
24import qualified Data.ByteString.Lazy.Char8 as L
24import qualified Data.ByteString.Lazy.Char8 as L
25import qualified Data.HashMap.Strict as HM
25import qualified Data.HashMap.Strict as HM
27tests :: [TestTree]
30tests :: [TestTree]
29 [ aesonGoldenTest "simple" "tests/golden/simple.expected" output
32 [ aesonGoldenTest "simple" "tests/golden/simple.expected" output
33+ , aesonGoldenTest "generic" "tests/golden/generic.expected" (outputGeneric G)
32output :: Output
36output :: Output
@@ -70,6 +74,85 @@ output = concat
79+outputGeneric :: Choice -> Output
80+outputGeneric choice = concat
81+ [ testWith "OneConstructor"
83+ thOneConstructorParseJSONDefault
84+ gOneConstructorParseJSONDefault)
91+ thNullaryParseJSONString
92+ gNullaryParseJSONString)
97+ , testWithSomeType "SomeType (tagged)"
99+ thSomeTypeParseJSONTaggedObject
100+ gSomeTypeParseJSONTaggedObject)
101+ [ "{\"tag\": \"unary\", \"contents\": true}"
102+ , "{\"tag\": \"unary\"}"
103+ , "{\"tag\": \"record\"}"
104+ , "{\"tag\": \"record\", \"testone\": true, \"testtwo\": null, \"testthree\": null}"
105+ , "{\"tag\": \"X\"}"
110+ , testWithSomeType "SomeType (single-field)"
112+ thSomeTypeParseJSONObjectWithSingleField
113+ gSomeTypeParseJSONObjectWithSingleField)
117+ , "{\"record\": {}, \"W\":{}}"
122+ , testWithSomeType "SomeType (two-element array)"
124+ thSomeTypeParseJSON2ElemArray
125+ gSomeTypeParseJSON2ElemArray)
126+ [ "[\"unary\", true]"
127+ , "[\"record\", null]"
134+ , testWith "EitherTextInt"
136+ thEitherTextIntParseJSONUntaggedValue
137+ gEitherTextIntParseJSONUntaggedValue)
142+ , testWith "Product2 Int Bool"
152+ select a b = case choice of
73-- Test infrastructure
156-- Test infrastructure
75type Output = [String]
158type Output = [String]
@@ -105,3 +188,6 @@ testWith name parser ts =
105testFor :: forall a proxy. (FromJSON a, Show a)
188testFor :: forall a proxy. (FromJSON a, Show a)
106 => String -> proxy a -> [L.ByteString] -> Output
189 => String -> proxy a -> [L.ByteString] -> Output
107testFor name _ = testWith name (parseJSON :: Value -> Parser a)
190testFor name _ = testWith name (parseJSON :: Value -> Parser a)
192+testWithSomeType :: String -> (Value -> Parser (SomeType Int)) -> [L.ByteString] -> Output
193+testWithSomeType = testWith