@@ -1,3 +1,5 @@
1+{-# LANGUAGE CPP #-}
2+
13module DataFamilies.Properties (tests) where
24
35import DataFamilies.Encoders
@@ -12,14 +14,13 @@ import Test.Framework.Providers.QuickCheck2 (testProperty)
1214
1315tests :: Test
1416tests = testGroup "data families" [
15− testGroup "template-haskell" [
17+ testGroup "template-haskell" [
1618 testGroup "toJSON" [
1719 testGroup "Nullary" [
1820 testProperty "string" (isString . thNullaryToJSONString)
1921 , testProperty "2ElemArray" (is2ElemArray . thNullaryToJSON2ElemArray)
2022 , testProperty "TaggedObject" (isNullaryTaggedObject . thNullaryToJSONTaggedObject)
2123 , testProperty "ObjectWithSingleField" (isObjectWithSingleField . thNullaryToJSONObjectWithSingleField)
22−
2324 , testGroup "roundTrip" [
2425 testProperty "string" (toParseJSON thNullaryParseJSONString thNullaryToJSONString)
2526 , testProperty "2ElemArray" (toParseJSON thNullaryParseJSON2ElemArray thNullaryToJSON2ElemArray)
@@ -36,21 +37,21 @@ tests = testGroup "data families" [
3637 , testProperty "TaggedObject" (toParseJSON thSomeTypeParseJSONTaggedObject thSomeTypeToJSONTaggedObject)
3738 , testProperty "ObjectWithSingleField" (toParseJSON thSomeTypeParseJSONObjectWithSingleField thSomeTypeToJSONObjectWithSingleField)
3839 ]
40+ ]
3941 , testGroup "Approx" [
40− testProperty "string" (isString . thApproxToJSONUnwrap)
41− , testProperty "ObjectWithSingleField" (isObjectWithSingleField . thApproxToJSONDefault)
42− , testGroup "roundTrip" [
43− testProperty "string" (toParseJSON thApproxParseJSONUnwrap thApproxToJSONUnwrap)
44− , testProperty "ObjectWithSingleField" (toParseJSON thApproxParseJSONDefault thApproxToJSONDefault)
45− ]
46− ]
42+ testProperty "string" (isString . thApproxToJSONUnwrap)
43+ , testProperty "ObjectWithSingleField" (isObjectWithSingleField . thApproxToJSONDefault)
44+ , testGroup "roundTrip" [
45+ testProperty "string" (toParseJSON thApproxParseJSONUnwrap thApproxToJSONUnwrap)
46+ , testProperty "ObjectWithSingleField" (toParseJSON thApproxParseJSONDefault thApproxToJSONDefault)
47+ ]
48+ ]
4749 , testGroup "GADT" [
4850 testProperty "string" (isString . thGADTToJSONUnwrap)
4951 , testProperty "ObjectWithSingleField" (isObjectWithSingleField . thGADTToJSONDefault)
5052 , testGroup "roundTrip" [
51− testProperty "string" (toParseJSON thGADTParseJSONUnwrap thGADTToJSONUnwrap)
52− , testProperty "ObjectWithSingleField" (toParseJSON thGADTParseJSONDefault thGADTToJSONDefault)
53− ]
53+ testProperty "string" (toParseJSON thGADTParseJSONUnwrap thGADTToJSONUnwrap)
54+ , testProperty "ObjectWithSingleField" (toParseJSON thGADTParseJSONDefault thGADTToJSONDefault)
5455 ]
5556 ]
5657 ]
@@ -77,4 +78,65 @@ tests = testGroup "data families" [
7778 thSomeTypeToEncodingObjectWithSingleField
7879 ]
7980 ]
81+
82+-- We only test generic instances for GHC 7.6 and higher because GHC 7.4 has
83+-- a bug concerning generics and data families
84+#if __GLASGOW_HASKELL__ >= 706
85+ , testGroup "generics" [
86+ testGroup "toJSON" [
87+ testGroup "Nullary" [
88+ testProperty "string" (isString . gNullaryToJSONString)
89+ , testProperty "2ElemArray" (is2ElemArray . gNullaryToJSON2ElemArray)
90+ , testProperty "TaggedObject" (isNullaryTaggedObject . gNullaryToJSONTaggedObject)
91+ , testProperty "ObjectWithSingleField" (isObjectWithSingleField . gNullaryToJSONObjectWithSingleField)
92+ , testGroup "roundTrip" [
93+ testProperty "string" (toParseJSON gNullaryParseJSONString gNullaryToJSONString)
94+ , testProperty "2ElemArray" (toParseJSON gNullaryParseJSON2ElemArray gNullaryToJSON2ElemArray)
95+ , testProperty "TaggedObject" (toParseJSON gNullaryParseJSONTaggedObject gNullaryToJSONTaggedObject)
96+ , testProperty "ObjectWithSingleField" (toParseJSON gNullaryParseJSONObjectWithSingleField gNullaryToJSONObjectWithSingleField)
97+ ]
98+ ]
99+ , testGroup "SomeType" [
100+ testProperty "2ElemArray" (is2ElemArray . gSomeTypeToJSON2ElemArray)
101+ , testProperty "TaggedObject" (isTaggedObject . gSomeTypeToJSONTaggedObject)
102+ , testProperty "ObjectWithSingleField" (isObjectWithSingleField . gSomeTypeToJSONObjectWithSingleField)
103+ , testGroup "roundTrip" [
104+ testProperty "2ElemArray" (toParseJSON gSomeTypeParseJSON2ElemArray gSomeTypeToJSON2ElemArray)
105+ , testProperty "TaggedObject" (toParseJSON gSomeTypeParseJSONTaggedObject gSomeTypeToJSONTaggedObject)
106+ , testProperty "ObjectWithSingleField" (toParseJSON gSomeTypeParseJSONObjectWithSingleField gSomeTypeToJSONObjectWithSingleField)
107+ ]
108+ ]
109+ , testGroup "Approx" [
110+ testProperty "string" (isString . gApproxToJSONUnwrap)
111+ , testProperty "ObjectWithSingleField" (isObjectWithSingleField . gApproxToJSONDefault)
112+ , testGroup "roundTrip" [
113+ testProperty "string" (toParseJSON gApproxParseJSONUnwrap gApproxToJSONUnwrap)
114+ , testProperty "ObjectWithSingleField" (toParseJSON gApproxParseJSONDefault gApproxToJSONDefault)
115+ ]
116+ ]
117+ ]
118+ , testGroup "toEncoding" [
119+ testProperty "NullaryString" $
120+ gNullaryToJSONString `sameAs` gNullaryToEncodingString
121+ , testProperty "Nullary2ElemArray" $
122+ gNullaryToJSON2ElemArray `sameAs` gNullaryToEncoding2ElemArray
123+ , testProperty "NullaryTaggedObject" $
124+ gNullaryToJSONTaggedObject `sameAs` gNullaryToEncodingTaggedObject
125+ , testProperty "NullaryObjectWithSingleField" $
126+ gNullaryToJSONObjectWithSingleField `sameAs`
127+ gNullaryToEncodingObjectWithSingleField
128+ , testProperty "ApproxUnwrap" $
129+ gApproxToJSONUnwrap `sameAs` gApproxToEncodingUnwrap
130+ , testProperty "ApproxDefault" $
131+ gApproxToJSONDefault `sameAs` gApproxToEncodingDefault
132+ , testProperty "SomeType2ElemArray" $
133+ gSomeTypeToJSON2ElemArray `sameAs` gSomeTypeToEncoding2ElemArray
134+ , testProperty "SomeTypeTaggedObject" $
135+ gSomeTypeToJSONTaggedObject `sameAs` gSomeTypeToEncodingTaggedObject
136+ , testProperty "SomeTypeObjectWithSingleField" $
137+ gSomeTypeToJSONObjectWithSingleField `sameAs`
138+ gSomeTypeToEncodingObjectWithSingleField
139+ ]
140+ ]
141+#endif
80142 ]