Skip to content

Commit f4176c5

Browse files
authored
Format with fourmolu (#1603)
* Format with fourmolu * ok with fourmolu 18
1 parent 44adecb commit f4176c5

File tree

154 files changed

+25458
-9099
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+25458
-9099
lines changed

persistent-mongoDB/test/EmbedTestMongo.hs

Lines changed: 367 additions & 266 deletions
Large diffs are not rendered by default.

persistent-mongoDB/test/EntityEmbedTestMongo.hs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DerivingStrategies #-}
13
{-# LANGUAGE EmptyDataDecls #-}
2-
{-# LANGUAGE DataKinds, ExistentialQuantification #-}
4+
{-# LANGUAGE ExistentialQuantification #-}
35
{-# LANGUAGE FlexibleContexts #-}
46
{-# LANGUAGE FlexibleInstances #-}
7+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
58
{-# LANGUAGE MultiParamTypeClasses #-}
69
{-# LANGUAGE QuasiQuotes #-}
10+
{-# LANGUAGE StandaloneDeriving #-}
711
{-# LANGUAGE TemplateHaskell #-}
812
{-# LANGUAGE TypeFamilies #-}
913
{-# LANGUAGE UndecidableInstances #-}
10-
{-# LANGUAGE DerivingStrategies #-}
11-
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
12-
{-# LANGUAGE StandaloneDeriving #-}
14+
1315
module EntityEmbedTestMongo where
1416

1517
-- because we are using a type alias we need to declare in a separate module
1618
-- this is used in EmbedTest
1719
import MongoInit
1820

19-
mkPersist persistSettings [persistUpperCase|
21+
mkPersist
22+
persistSettings
23+
[persistUpperCase|
2024
ARecord
2125
name Text
2226
deriving Show Eq Read Ord
Lines changed: 77 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
{-# LANGUAGE TemplateHaskell #-}
33
{-# OPTIONS_GHC -fno-warn-orphans #-}
4+
45
-- We create an orphan instance for GenerateKey here to avoid a circular
56
-- dependency between:
67
--
@@ -10,56 +11,79 @@
1011
--
1112
-- This kind of cycle is all kinds of bad news.
1213

13-
module MongoInit (
14-
BackendMonad
15-
, runConn
16-
, MonadIO
17-
, persistSettings
18-
, MkPersistSettings (..)
19-
, dbName
20-
, db'
21-
, setup
22-
, mkPersistSettings
23-
, Action
24-
, Context
25-
, BackendKey(MongoKey)
26-
27-
-- re-exports
28-
, module Database.Persist
29-
, module Database.Persist.Sql.Raw.QQ
30-
, module Test.Hspec
31-
, module Test.HUnit
32-
, liftIO
33-
, mkPersist, mkMigrate, share, sqlSettings, persistLowerCase, persistUpperCase
34-
, Int32, Int64
35-
, Text
36-
, module Control.Monad.Trans.Reader
37-
, module Control.Monad
38-
, PersistFieldSql(..)
39-
, BS.ByteString
40-
, SomeException
41-
, module Init
42-
) where
14+
module MongoInit
15+
( BackendMonad
16+
, runConn
17+
, MonadIO
18+
, persistSettings
19+
, MkPersistSettings (..)
20+
, dbName
21+
, db'
22+
, setup
23+
, mkPersistSettings
24+
, Action
25+
, Context
26+
, BackendKey (MongoKey)
27+
-- re-exports
28+
, module Database.Persist
29+
, module Database.Persist.Sql.Raw.QQ
30+
, module Test.Hspec
31+
, module Test.HUnit
32+
, liftIO
33+
, mkPersist
34+
, mkMigrate
35+
, share
36+
, sqlSettings
37+
, persistLowerCase
38+
, persistUpperCase
39+
, Int32
40+
, Int64
41+
, Text
42+
, module Control.Monad.Trans.Reader
43+
, module Control.Monad
44+
, PersistFieldSql (..)
45+
, BS.ByteString
46+
, SomeException
47+
, module Init
48+
) where
4349

4450
-- we have to be careful with this import becuase CPP is still a problem
4551
import Init
46-
( TestFn(..), truncateTimeOfDay, truncateUTCTime
47-
, truncateToMicro, arbText, liftA2, GenerateKey(..)
48-
, (@/=), (@==), (==@)
49-
, assertNotEqual, assertNotEmpty, assertEmpty, asIO
52+
( GenerateKey (..)
53+
, TestFn (..)
54+
, arbText
55+
, asIO
56+
, assertEmpty
57+
, assertNotEmpty
58+
, assertNotEqual
5059
, isTravis
60+
, liftA2
61+
, truncateTimeOfDay
62+
, truncateToMicro
63+
, truncateUTCTime
64+
, (==@)
65+
, (@/=)
66+
, (@==)
5167
)
5268

5369
-- re-exports
5470
import Control.Exception (SomeException)
55-
import Control.Monad (void, replicateM, liftM, when, forM_)
71+
import Control.Monad (forM_, liftM, replicateM, void, when)
5672
import Control.Monad.Trans.Reader
57-
import Database.Persist.TH (mkPersist, mkMigrate, share, sqlSettings, persistLowerCase, persistUpperCase, MkPersistSettings(..))
5873
import Database.Persist.Sql.Raw.QQ
74+
import Database.Persist.TH
75+
( MkPersistSettings (..)
76+
, mkMigrate
77+
, mkPersist
78+
, persistLowerCase
79+
, persistUpperCase
80+
, share
81+
, sqlSettings
82+
)
5983
import Test.Hspec
6084

6185
-- testing
62-
import Test.HUnit ((@?=),(@=?), Assertion, assertFailure, assertBool)
86+
import Test.HUnit (Assertion, assertBool, assertFailure, (@=?), (@?=))
6387

6488
import Control.Monad (unless, (>=>))
6589
import Control.Monad.IO.Class
@@ -68,11 +92,18 @@ import qualified Data.ByteString as BS
6892
import Data.Int (Int32, Int64)
6993
import Data.Text (Text)
7094
import qualified Database.MongoDB as MongoDB
71-
import Database.Persist.MongoDB (Action, withMongoPool, runMongoDBPool, defaultMongoConf, applyDockerEnv, BackendKey(..))
72-
import Language.Haskell.TH.Syntax (Type(..))
95+
import Database.Persist.MongoDB
96+
( Action
97+
, BackendKey (..)
98+
, applyDockerEnv
99+
, defaultMongoConf
100+
, runMongoDBPool
101+
, withMongoPool
102+
)
103+
import Language.Haskell.TH.Syntax (Type (..))
73104

74105
import Database.Persist
75-
import Database.Persist.Sql (PersistFieldSql(..))
106+
import Database.Persist.Sql (PersistFieldSql (..))
76107
import Database.Persist.TH (mkPersistSettings)
77108

78109
setup :: Action IO ()
@@ -83,25 +114,25 @@ _debugOn :: Bool
83114
_debugOn = True
84115

85116
persistSettings :: MkPersistSettings
86-
persistSettings = (mkPersistSettings $ ConT ''Context) { mpsGeneric = True }
117+
persistSettings = (mkPersistSettings $ ConT ''Context){mpsGeneric = True}
87118

88119
dbName :: Text
89120
dbName = "persistent"
90121

91122
type BackendMonad = Context
92123

93-
runConn :: MonadUnliftIO m => Action m backend -> m ()
124+
runConn :: (MonadUnliftIO m) => Action m backend -> m ()
94125
runConn f = do
95-
conf <- liftIO $ applyDockerEnv $ defaultMongoConf dbName -- { mgRsPrimary = Just "replicaset" }
96-
void $ withMongoPool conf $ runMongoDBPool MongoDB.master f
126+
conf <- liftIO $ applyDockerEnv $ defaultMongoConf dbName -- { mgRsPrimary = Just "replicaset" }
127+
void $ withMongoPool conf $ runMongoDBPool MongoDB.master f
97128

98129
setupMongo :: Action IO ()
99130
setupMongo = void $ MongoDB.dropDatabase dbName
100131

101132
db' :: Action IO () -> Action IO () -> Assertion
102133
db' actions cleanDB = do
103-
r <- runConn (actions >> cleanDB)
104-
return r
134+
r <- runConn (actions >> cleanDB)
135+
return r
105136

106137
instance GenerateKey MongoDB.MongoContext where
107138
generateKey = MongoKey `liftM` MongoDB.genObjectId
Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
11
{-# LANGUAGE OverloadedStrings #-}
2+
23
module RawMongoHelpers where
34

45
import qualified Database.MongoDB as MongoDB
5-
import Database.Persist.MongoDB (toInsertDoc, docToEntityThrow, collectionName, recordToDocument)
6+
import Database.Persist.MongoDB
7+
( collectionName
8+
, docToEntityThrow
9+
, recordToDocument
10+
, toInsertDoc
11+
)
612

713
import MongoInit
814
import PersistentTest (cleanDB)
915
import PersistentTestModels
1016

11-
1217
db :: ReaderT MongoDB.MongoContext IO () -> IO ()
1318
db = db' cleanDB
1419

1520
specs :: Spec
1621
specs = do
17-
describe "raw MongoDB helpers" $ do
18-
it "collectionName" $ do
19-
collectionName (Person "Duder" 0 Nothing) @?= "Person"
22+
describe "raw MongoDB helpers" $ do
23+
it "collectionName" $ do
24+
collectionName (Person "Duder" 0 Nothing) @?= "Person"
2025

21-
it "toInsertFields, entityFields, & docToEntityThrow" $ db $ do
22-
let p1 = Person "Duder" 0 Nothing
23-
let doc = toInsertDoc p1
24-
MongoDB.ObjId _id <- MongoDB.insert "Person" $ doc
25-
let idSelector = "_id" MongoDB.=: _id
26-
Entity _ ent1 <- docToEntityThrow $ idSelector:doc
27-
liftIO $ p1 @?= ent1
26+
it "toInsertFields, entityFields, & docToEntityThrow" $ db $ do
27+
let
28+
p1 = Person "Duder" 0 Nothing
29+
let
30+
doc = toInsertDoc p1
31+
MongoDB.ObjId _id <- MongoDB.insert "Person" $ doc
32+
let
33+
idSelector = "_id" MongoDB.=: _id
34+
Entity _ ent1 <- docToEntityThrow $ idSelector : doc
35+
liftIO $ p1 @?= ent1
2836

29-
let p2 = p1 {personColor = Just "blue"}
30-
let doc2 = idSelector:recordToDocument p2
31-
MongoDB.save "Person" doc2
32-
Entity _ ent2 <- docToEntityThrow doc2
33-
liftIO $ p2 @?= ent2
37+
let
38+
p2 = p1{personColor = Just "blue"}
39+
let
40+
doc2 = idSelector : recordToDocument p2
41+
MongoDB.save "Person" doc2
42+
Entity _ ent2 <- docToEntityThrow doc2
43+
liftIO $ p2 @?= ent2

0 commit comments

Comments
 (0)