{-# LANGUAGE UndecidableInstances #-}
module LargeNumberTest where

import Data.Word

import Init

share [mkPersist sqlSettings { mpsGeneric = True },  mkMigrate "numberMigrate"] [persistLowerCase|
  Number
    intx Int
    int32 Int32
    word32 Word32
    int64 Int64
    word64 Word64
    deriving Show Eq
|]

cleanDB
    :: Runner backend m => ReaderT backend m ()
cleanDB :: ReaderT backend m ()
cleanDB = do
  [Filter (NumberGeneric backend)] -> ReaderT backend m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere ([] :: [Filter (NumberGeneric backend)])

specsWith :: Runner backend m => RunDb backend m -> Spec
specsWith :: RunDb backend m -> Spec
specsWith RunDb backend m
runDb = String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Large Numbers" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
  String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"preserves their values in the database" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ RunDb backend m
runDb RunDb backend m -> RunDb backend m
forall a b. (a -> b) -> a -> b
$ do
      let go :: a -> ReaderT backend m ()
go a
x = do
              Key a
xid <- a -> ReaderT backend m (Key a)
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend, SafeToInsert record) =>
record -> ReaderT backend m (Key record)
insert a
x
              Maybe a
x' <- Key a -> ReaderT backend m (Maybe a)
forall backend record (m :: * -> *).
(PersistStoreRead backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m (Maybe record)
get Key a
xid
              IO () -> ReaderT backend m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ReaderT backend m ()) -> IO () -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ Maybe a
x' Maybe a -> Maybe a -> IO ()
forall a. (HasCallStack, Eq a, Show a) => a -> a -> IO ()
@?= a -> Maybe a
forall a. a -> Maybe a
Just a
x

      NumberGeneric backend -> ReaderT backend m ()
forall (m :: * -> *) backend a.
(MonadIO m, PersistStoreWrite backend, PersistEntity a,
 SafeToInsert a, Show a, Eq a,
 PersistEntityBackend a ~ BaseBackend backend) =>
a -> ReaderT backend m ()
go (NumberGeneric backend -> ReaderT backend m ())
-> NumberGeneric backend -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
forall backend.
Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
Number Int
forall a. Bounded a => a
maxBound Int32
0 Word32
0 Int64
0 Word64
0
      NumberGeneric backend -> ReaderT backend m ()
forall (m :: * -> *) backend a.
(MonadIO m, PersistStoreWrite backend, PersistEntity a,
 SafeToInsert a, Show a, Eq a,
 PersistEntityBackend a ~ BaseBackend backend) =>
a -> ReaderT backend m ()
go (NumberGeneric backend -> ReaderT backend m ())
-> NumberGeneric backend -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
forall backend.
Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
Number Int
0 Int32
forall a. Bounded a => a
maxBound Word32
0 Int64
0 Word64
0
      NumberGeneric backend -> ReaderT backend m ()
forall (m :: * -> *) backend a.
(MonadIO m, PersistStoreWrite backend, PersistEntity a,
 SafeToInsert a, Show a, Eq a,
 PersistEntityBackend a ~ BaseBackend backend) =>
a -> ReaderT backend m ()
go (NumberGeneric backend -> ReaderT backend m ())
-> NumberGeneric backend -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
forall backend.
Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
Number Int
0 Int32
0 Word32
forall a. Bounded a => a
maxBound Int64
0 Word64
0
      NumberGeneric backend -> ReaderT backend m ()
forall (m :: * -> *) backend a.
(MonadIO m, PersistStoreWrite backend, PersistEntity a,
 SafeToInsert a, Show a, Eq a,
 PersistEntityBackend a ~ BaseBackend backend) =>
a -> ReaderT backend m ()
go (NumberGeneric backend -> ReaderT backend m ())
-> NumberGeneric backend -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
forall backend.
Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
Number Int
0 Int32
0 Word32
0 Int64
forall a. Bounded a => a
maxBound Word64
0
      NumberGeneric backend -> ReaderT backend m ()
forall (m :: * -> *) backend a.
(MonadIO m, PersistStoreWrite backend, PersistEntity a,
 SafeToInsert a, Show a, Eq a,
 PersistEntityBackend a ~ BaseBackend backend) =>
a -> ReaderT backend m ()
go (NumberGeneric backend -> ReaderT backend m ())
-> NumberGeneric backend -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
forall backend.
Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
Number Int
0 Int32
0 Word32
0 Int64
0 Word64
forall a. Bounded a => a
maxBound

      NumberGeneric backend -> ReaderT backend m ()
forall (m :: * -> *) backend a.
(MonadIO m, PersistStoreWrite backend, PersistEntity a,
 SafeToInsert a, Show a, Eq a,
 PersistEntityBackend a ~ BaseBackend backend) =>
a -> ReaderT backend m ()
go (NumberGeneric backend -> ReaderT backend m ())
-> NumberGeneric backend -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
forall backend.
Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
Number Int
forall a. Bounded a => a
minBound Int32
0 Word32
0 Int64
0 Word64
0
      NumberGeneric backend -> ReaderT backend m ()
forall (m :: * -> *) backend a.
(MonadIO m, PersistStoreWrite backend, PersistEntity a,
 SafeToInsert a, Show a, Eq a,
 PersistEntityBackend a ~ BaseBackend backend) =>
a -> ReaderT backend m ()
go (NumberGeneric backend -> ReaderT backend m ())
-> NumberGeneric backend -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
forall backend.
Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
Number Int
0 Int32
forall a. Bounded a => a
minBound Word32
0 Int64
0 Word64
0
      NumberGeneric backend -> ReaderT backend m ()
forall (m :: * -> *) backend a.
(MonadIO m, PersistStoreWrite backend, PersistEntity a,
 SafeToInsert a, Show a, Eq a,
 PersistEntityBackend a ~ BaseBackend backend) =>
a -> ReaderT backend m ()
go (NumberGeneric backend -> ReaderT backend m ())
-> NumberGeneric backend -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
forall backend.
Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
Number Int
0 Int32
0 Word32
forall a. Bounded a => a
minBound Int64
0 Word64
0
      NumberGeneric backend -> ReaderT backend m ()
forall (m :: * -> *) backend a.
(MonadIO m, PersistStoreWrite backend, PersistEntity a,
 SafeToInsert a, Show a, Eq a,
 PersistEntityBackend a ~ BaseBackend backend) =>
a -> ReaderT backend m ()
go (NumberGeneric backend -> ReaderT backend m ())
-> NumberGeneric backend -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
forall backend.
Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
Number Int
0 Int32
0 Word32
0 Int64
forall a. Bounded a => a
minBound Word64
0
      NumberGeneric backend -> ReaderT backend m ()
forall (m :: * -> *) backend a.
(MonadIO m, PersistStoreWrite backend, PersistEntity a,
 SafeToInsert a, Show a, Eq a,
 PersistEntityBackend a ~ BaseBackend backend) =>
a -> ReaderT backend m ()
go (NumberGeneric backend -> ReaderT backend m ())
-> NumberGeneric backend -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
forall backend.
Int -> Int32 -> Word32 -> Int64 -> Word64 -> NumberGeneric backend
Number Int
0 Int32
0 Word32
0 Int64
0 Word64
forall a. Bounded a => a
minBound