@@ -51,6 +51,10 @@ boxGen = do PgPoint x1 y1 <- pointGen
51
51
pure (PgBox (PgPoint (min x1 x2) (min y1 y2))
52
52
(PgPoint (max x1 x2) (max y1 y2)))
53
53
54
+ arrayGen :: Hedgehog. Gen a -> Hedgehog. Gen (Vector. Vector a )
55
+ arrayGen = fmap Vector. fromList
56
+ . Gen. list (Range. linear 0 5 ) -- small arrays == quick tests
57
+
54
58
boxCmp :: PgBox -> PgBox -> Bool
55
59
boxCmp (PgBox a1 b1) (PgBox a2 b2) =
56
60
(a1 `ptCmp` a2 && b1 `ptCmp` b2) ||
@@ -90,13 +94,27 @@ tests postgresConn =
90
94
, marshalTest (Gen. maybe (Gen. integral (Range. constantBounded @ Word64 ))) postgresConn
91
95
, marshalTest (Gen. maybe textGen) postgresConn
92
96
, marshalTest (Gen. maybe uuidGen) postgresConn
93
- , marshalTest692 postgresConn
94
97
95
98
, marshalTest' (\ a b -> Hedgehog. assert (liftEq ptCmp a b)) (Gen. maybe pointGen) postgresConn
96
99
, marshalTest' (\ a b -> Hedgehog. assert (liftEq boxCmp a b)) (Gen. maybe boxGen) postgresConn
97
100
98
- -- , marshalTest (Gen.double (Range.exponentialFloat 0 1e40)) postgresConn
99
- -- , marshalTest (Gen.integral (Range.constantBounded @Word)) postgresConn
101
+ -- Arrays
102
+ --
103
+ -- Testing lots of element types for arrays is important, because
104
+ -- the mapping between array Oid and element Oid is not type
105
+ -- safe, and hence error-prone.
106
+ , marshalTest (arrayGen textGen) postgresConn
107
+ , marshalTest (arrayGen (Gen. double (Range. exponentialFloat 0 1e40 ))) postgresConn
108
+ , marshalTest (arrayGen ((Gen. integral (Range. constantBounded @ Int16 )))) postgresConn
109
+ , marshalTest (arrayGen ((Gen. integral (Range. constantBounded @ Int32 )))) postgresConn
110
+ , marshalTest (arrayGen ((Gen. integral (Range. constantBounded @ Int64 )))) postgresConn
111
+ , marshalTest (Gen. maybe (arrayGen textGen)) postgresConn
112
+ , marshalTest (Gen. maybe (arrayGen (Gen. double (Range. exponentialFloat 0 1e40 )))) postgresConn
113
+ , marshalTest (Gen. maybe (arrayGen ((Gen. integral (Range. constantBounded @ Int16 ))))) postgresConn
114
+ , marshalTest (Gen. maybe (arrayGen ((Gen. integral (Range. constantBounded @ Int32 ))))) postgresConn
115
+ , marshalTest (Gen. maybe (arrayGen ((Gen. integral (Range. constantBounded @ Int64 ))))) postgresConn
116
+
117
+ , marshalTest (Gen. double (Range. exponentialFloat 0 1e40 )) postgresConn
100
118
-- , marshalTest (Gen.integral (Range.constantBounded @Int)) postgresConn
101
119
102
120
-- , marshalTest @Int8 postgresConn
@@ -164,70 +182,3 @@ marshalTest' cmp gen postgresConn =
164
182
v' `cmp` a
165
183
166
184
assertBool " Hedgehog test failed" passes
167
-
168
-
169
- -- Ensure that both `Vector Text` and `Maybe (Vector Text)` can be
170
- -- marshalled correctly (see issue 692).
171
- --
172
- -- At this time, the postgres migration backend can't create columns of arrays,
173
- -- and hence this test does not use `marshalTest`.
174
- marshalTest692 :: IO ByteString -> TestTree
175
- marshalTest692 postgresConn =
176
- testCase " Can marshal Vector Text and Maybe (Vector Text) (#692)" $
177
- withTestPostgres (" db_marshal_maybe_vector_text_issue_692" ) postgresConn $ \ conn -> do
178
- liftIO $ execute_ conn $ " CREATE TABLE mytable (\n myid SERIAL PRIMARY KEY, mycolumn text[], mynullablecolumn text[]\n );"
179
-
180
- passes <- Hedgehog. check . Hedgehog. property $ do
181
- nullable <- Hedgehog. forAll (Gen. maybe (Vector. fromList <$> (Gen. list (Range. linear 0 10 ) textGen)))
182
- nonnull <- Hedgehog. forAll (Vector. fromList <$> (Gen. list (Range. linear 0 10 ) textGen))
183
-
184
- [MkTbl692 rowId v vnull] <-
185
- liftIO . runBeamPostgres conn
186
- $ runInsertReturningList
187
- $ insert (_myTable myDB)
188
- $ insertExpressions [ MkTbl692 default_ (val_ nonnull) (val_ nullable) ]
189
-
190
- v === nonnull
191
- vnull === nullable
192
-
193
- Just (MkTbl692 _ v' vnull') <-
194
- liftIO . runBeamPostgres conn
195
- $ runSelectReturningOne (lookup_ (_myTable myDB) (Tbl692Key rowId))
196
- v' === nonnull
197
- vnull' === nullable
198
-
199
- assertBool " Hedgehog test failed" passes
200
- where
201
- myDB :: DatabaseSettings Postgres MyDB692
202
- myDB = defaultDbSettings `withDbModification`
203
- MkMyDB692 {
204
- _myTable =
205
- setEntityName " mytable" <>
206
- modifyTableFields
207
- tableModification {
208
- myid = fieldNamed " myid" ,
209
- mycolumn = fieldNamed " mycolumn" ,
210
- mynullablecolumn = fieldNamed " mynullablecolumn"
211
- }
212
- }
213
-
214
- data Tbl692 f
215
- = MkTbl692
216
- { myid :: C f (SqlSerial Int32 )
217
- , mycolumn :: C f (Vector. Vector T. Text )
218
- , mynullablecolumn :: C f (Maybe (Vector. Vector T. Text ))
219
- }
220
- deriving (Generic , Beamable )
221
-
222
- deriving instance Show (Tbl692 Identity )
223
- deriving instance Eq (Tbl692 Identity )
224
-
225
- instance Table Tbl692 where
226
- data PrimaryKey Tbl692 f = Tbl692Key (C f (SqlSerial Int32 ))
227
- deriving (Generic , Beamable )
228
- primaryKey = Tbl692Key <$> myid
229
- data MyDB692 entity
230
- = MkMyDB692
231
- { _myTable :: entity (TableEntity Tbl692 )
232
- } deriving (Generic )
233
- instance Database Postgres MyDB692
0 commit comments