--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
module Test.Support
  ( withTestDatabase
  ) where
--------------------------------------------------------------------------------
import Test.Prelude
--------------------------------------------------------------------------------
import GramDB
--------------------------------------------------------------------------------

-- | Helper for creating unique test ids
testState :: MVar Int
{-# NOINLINE testState #-}
testState = unsafePerformIO $ newMVar 0

-- | Create a unique ident for the test
newTestState :: MonadIO m => m Int
newTestState = liftIO $ modifyMVar testState (\x -> pure (succ x, x))

-- | Create a database name for the test
mkTestDatabase :: Int -> String
mkTestDatabase state = "testDatabase" <> show state <> ".db"

-- | Create a database from a 'FilePath'
initDatabase :: FilePath -> IO ()
initDatabase = undefined

-- | Run a test with its own DB!
withTestDatabase
  :: GramM a -> IO a
withTestDatabase = undefined

{'avg_line_length': 33.45454545454545, 'max_line_length': 80, 'alphanum_fraction': 0.45018115942028986, 'licenses': ['MIT'], 'repository_name': 'Camsbury/gramdb', 'path': 'test/Test/Support.hs', 'size': 1104, 'lang': 'Haskell'}