Skip to content

Commit

Permalink
Merge ../safecopy.derive
Browse files Browse the repository at this point in the history
  • Loading branch information
ddssff committed Dec 2, 2024
2 parents 1e8257b + 0fcfb75 commit 888f013
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 21 deletions.
4 changes: 3 additions & 1 deletion safecopy.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ Test-suite instances
Main-is: instances.hs
Hs-Source-Dirs: test/
GHC-Options: -Wall -threaded -rtsopts -with-rtsopts=-N
Build-depends: base, cereal, template-haskell, safecopy,
Build-depends: base, bytestring, cereal, template-haskell, safecopy,
containers, time, array, vector, lens >= 4.7 && < 6,
lens-action
, syb
, tasty
, tasty-hunit
, tasty-quickcheck
, quickcheck-instances
, QuickCheck >= 2.8.2 && < 3
, th-orphans
Other-Modules: Types

Test-suite generic
Default-language: Haskell2010
Expand Down
48 changes: 33 additions & 15 deletions src/Data/SafeCopy/Derive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import Language.Haskell.TH hiding (Kind)
import Control.Monad
import Data.Data (Data)
import Data.Generics (everywhere, mkT)
import Data.List (nub)
import Data.Maybe (fromMaybe)
#ifdef __HADDOCK__
import Data.Word (Word8) -- Haddock
#endif
import Debug.Trace (traceShowId)
import Debug.Trace

Check warning on line 17 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

The import of ‘Debug.Trace’ is redundant

Check warning on line 17 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

The import of ‘Debug.Trace’ is redundant

Check warning on line 17 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

The import of ‘Debug.Trace’ is redundant

Check warning on line 17 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

The import of ‘Debug.Trace’ is redundant
import Language.Haskell.TH.PprLib (Doc, to_HPJ_Doc)
import Language.Haskell.TH.Syntax
import qualified Text.PrettyPrint as HPJ
Expand Down Expand Up @@ -262,13 +263,16 @@ tyVarName (KindedTV n _) = n
class ExtraContext a where
extraContext :: a -> Q Cxt

instance (ExtraContext a, ExtraContext b) => ExtraContext (a, b) where
extraContext (a, b) = (<>) <$> extraContext a <*> extraContext b

-- | Generate SafeCopy constraints for a list of type variables
instance ExtraContext Cxt where
extraContext context = pure context

instance ExtraContext [TyVarBndr] where

Check failure on line 273 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 9.8 ubuntu-latest

• Expecting one more argument to ‘TyVarBndr’

Check failure on line 273 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 9.0 ubuntu-latest

• Expecting one more argument to ‘TyVarBndr’

Check failure on line 273 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 9.2 ubuntu-latest

• Expecting one more argument to ‘TyVarBndr’

Check failure on line 273 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 9.4 ubuntu-latest

• Expecting one more argument to ‘TyVarBndr’

Check failure on line 273 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 9.8 macos-latest

• Expecting one more argument to ‘TyVarBndr’

Check failure on line 273 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 9.6 ubuntu-latest

• Expecting one more argument to ‘TyVarBndr’

Check failure on line 273 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 9.8 windows-latest

* Expecting one more argument to `TyVarBndr'
extraContext tyvars =
pure $ fmap (\var -> AppT (ConT ''SafeCopy) (VarT $ tyVarName var)) tyvars
sequence (fmap (\var -> [t|SafeCopy $(varT (tyVarName var))|]) tyvars)

instance ExtraContext Name where
extraContext tyName =
Expand All @@ -285,6 +289,19 @@ instance ExtraContext TypeQ where
ForallT _ context _ -> pure context
typ -> fail $ "Can't derive SafeCopy instance for: " ++ show typ

instance ExtraContext Con where
extraContext (NormalC name types) =

Check warning on line 293 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘name’

Check warning on line 293 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘name’

Check warning on line 293 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘name’

Check warning on line 293 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘name’
fmap mconcat (sequence <$> mapM extraContext (fmap snd types))
extraContext (RecC name types) =

Check warning on line 295 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘name’

Check warning on line 295 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘name’

Check warning on line 295 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘name’

Check warning on line 295 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘name’
fmap mconcat (sequence <$> mapM extraContext (fmap (\(_, _, typ) -> typ) types))
extraContext (InfixC type1 name type2) = extraContext (snd type1, snd type2)

Check warning on line 297 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘name’

Check warning on line 297 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘name’

Check warning on line 297 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘name’

Check warning on line 297 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘name’
extraContext (ForallC tyvars context con) = (<>) <$> pure context <*> extraContext con

Check warning on line 298 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘tyvars’

Check warning on line 298 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘tyvars’

Check warning on line 298 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘tyvars’

Check warning on line 298 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘tyvars’
extraContext (GadtC names types typ) = pure []

Check warning on line 299 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘names’

Check warning on line 299 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘types’

Check warning on line 299 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘typ’

Check warning on line 299 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘names’

Check warning on line 299 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘types’

Check warning on line 299 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘typ’

Check warning on line 299 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘names’

Check warning on line 299 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘types’

Check warning on line 299 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘typ’

Check warning on line 299 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘names’

Check warning on line 299 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘types’

Check warning on line 299 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘typ’
extraContext (RecGadtC names types typ) = pure []

Check warning on line 300 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘names’

Check warning on line 300 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘types’

Check warning on line 300 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘names’

Check warning on line 300 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.6 ubuntu-latest

Defined but not used: ‘types’

Check warning on line 300 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘names’

Check warning on line 300 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘types’

Check warning on line 300 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘names’

Check warning on line 300 in src/Data/SafeCopy/Derive.hs

View workflow job for this annotation

GitHub Actions / Stack 8.4 ubuntu-latest

Defined but not used: ‘types’

instance ExtraContext Type where
extraContext typ = sequence [ [t|SafeCopy $(pure typ)|] ]

internalDeriveSafeCopy :: ExtraContext t => DeriveType -> Version a -> Name -> t -> TypeQ -> Q [Dec]
internalDeriveSafeCopy deriveType versionId kindName t typq = do
typq >>= \case
Expand All @@ -302,13 +319,13 @@ doInfo deriveType versionId kindName t tyName info =
". The datatype must have less than 256 constructors."
| otherwise -> do
extra <- extraContext t
worker1 deriveType versionId kindName tyName (ConT tyName) (context ++ extra) tyvars (zip [0..] cons)
doCons deriveType versionId kindName tyName (ConT tyName) (context ++ extra) tyvars (zip [0..] cons)

TyConI (NewtypeD context _name tyvars _kind con _derivs) ->
worker1 deriveType versionId kindName tyName (ConT tyName) context tyvars [(0, con)]
doCons deriveType versionId kindName tyName (ConT tyName) context tyvars (zip [0..] [con])

FamilyI _ insts -> do
concat <$> (forM insts $ withInst (ConT tyName) (worker1 deriveType versionId kindName tyName))
concat <$> (forM insts $ withInst (ConT tyName) (doCons deriveType versionId kindName tyName))
_ -> fail $ "Can't derive SafeCopy instance for: " ++ show (tyName, info)

internalDeriveSafeCopyIndexedType :: DeriveType -> Version a -> Name -> TypeQ -> [Name] -> Q [Dec]
Expand All @@ -327,24 +344,25 @@ internalDeriveSafeCopyIndexedType deriveType versionId kindName typq tyIndex' =
renderDecs :: [Dec] -> String
renderDecs = renderTH (ppr . everywhere (mkT briefName))

worker1 :: DeriveType -> Version a -> Name -> Name -> Type -> Cxt -> [TyVarBndr] -> [(Integer, Con)] -> Q [Dec]
worker1 deriveType versionId kindName tyName tyBase context tyvars cons =
doCons :: DeriveType -> Version a -> Name -> Name -> Type -> Cxt -> [TyVarBndr] -> [(Integer, Con)] -> Q [Dec]
doCons deriveType versionId kindName tyName tyBase context tyvars cons = do
let ty = foldl AppT tyBase (fmap (\var -> VarT $ tyVarName var) tyvars)
in (:[]) <$> instanceD (cxt (fmap pure context))
(pure (ConT ''SafeCopy `AppT` ty))
[ mkPutCopy deriveType cons
, mkGetCopy deriveType (renderTH (ppr . everywhere (mkT cleanName)) (ConT tyName)) cons
, valD (varP 'version) (normalB $ litE $ integerL $ fromIntegral $ unVersion versionId) []
, valD (varP 'kind) (normalB (varE kindName)) []
, funD 'errorTypeName [clause [wildP] (normalB $ litE $ StringL (renderTH (ppr . everywhere (mkT cleanName)) (ConT tyName))) []] ]
extra <- concat <$> mapM extraContext (fmap snd cons)
(:[]) <$> instanceD (cxt (fmap pure (nub (context <> extra))))
(pure (ConT ''SafeCopy `AppT` ty))
[ mkPutCopy deriveType cons
, mkGetCopy deriveType (renderTH (ppr . everywhere (mkT cleanName)) (ConT tyName)) cons
, valD (varP 'version) (normalB $ litE $ integerL $ fromIntegral $ unVersion versionId) []
, valD (varP 'kind) (normalB (varE kindName)) []
, funD 'errorTypeName [clause [wildP] (normalB $ litE $ StringL (renderTH (ppr . everywhere (mkT cleanName)) (ConT tyName))) []] ]

worker2 :: DeriveType -> Version a -> Name -> [Name] -> Type -> Type -> Cxt -> [TyVarBndr] -> [(Integer, Con)] -> Q [Dec]
worker2 _ _ _ _ itype tyBase _ _ _ | itype /= tyBase =
fail $ "Expected " <> show itype <> ", but found " <> show tyBase
worker2 deriveType versionId kindName tyIndex' _ tyBase context tyvars cons = do
let ty = foldl AppT tyBase (fmap (\var -> VarT $ tyVarName var) tyvars)
typeNameStr = unwords (renderTH (ppr . everywhere (mkT cleanName)) ty : map show tyIndex')
(:[]) <$> instanceD (cxt (fmap pure context))
(:[]) <$> instanceD (cxt (fmap pure (nub context)))
(pure (ConT ''SafeCopy `AppT` ty))
[ mkPutCopy deriveType cons
, mkGetCopy deriveType typeNameStr cons
Expand Down
79 changes: 79 additions & 0 deletions test/Types.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{-# LANGUAGE DataKinds, DeriveDataTypeable, FlexibleInstances, KindSignatures #-}

module Types where

import Control.Monad (MonadPlus, msum)
import Data.ByteString (ByteString)
import Data.Data (Data)
import Data.Generics (listify)
import Data.Set (Set)
import Data.Typeable (Typeable)
import Language.Haskell.TH.Instances ()
import Language.Haskell.TH.Syntax

newtype ClientView db = ClientView {unClientView :: ViewModifiers db (PKey Client)} deriving (Eq, Ord, Show)
data Client
= Client
{ _clientName :: PersonName
, _clientTitle :: RenderedUnicode
, _clientCompany :: RenderedUnicode
, _clientAddress :: RenderedUnicode
, _clientAddress2 :: RenderedUnicode
, _clientCity :: RenderedUnicode
, _clientState :: RenderedUnicode
, _clientPostal :: RenderedUnicode
, _clientGreeting :: RenderedUnicode
, _clientPhone :: RenderedUnicode
, _clientEmail :: RenderedUnicode
, _clientPreferredContactMethods :: Set ContactMethod
, _clientNotes :: RenderedHtml
, _clientUserId :: Maybe UserId
-- ^ Does this client have have an AppraisalScribe account? I hope so!
} deriving (Show, Eq, Ord, Typeable, Data)
type PersonName = String
type RenderedUnicode = String
type RenderedHtml = String
type ContactMethod = Char
newtype UserId = UserId Integer deriving (Eq, Ord, Show, Data)
data ViewModifiers db col = ViewModifiers {_mods :: Set (ViewModifier db)} deriving (Show, Eq, Ord)
data ViewModifier db =
Effective UserId -- ^ Use this user's data
| Matching SearchTerm -- ^ Filter out object that do not match this search term
| PagerView PagerStyle
| MemberAny [PKey db]
| ViewNotes [String]
| InvertMod (ViewModifier db) -- invert the sense of a test
| TestKeys [ByteString] -- ^ Test whether the key argument matches any encoded key
deriving (Eq, Ord, Show)
data SearchTerm =
SearchTerm {_searchWords :: [CI Text]}
| NoTerm
deriving (Read, Show, Eq, Ord, Data, Typeable)
type Text = String
type PagerStyle = String
type CI a = a
data OpticTag = F | G | I | L | P | S | T | U deriving (Eq, Show, Typeable)
newtype Path (o :: OpticTag) s = Path UPath deriving (Typeable, Eq, Ord, Data, Show)
type UPath = [UHop Int]
data UHop pos
= IxPathU ByteString -- ^ 'Control.Lens.ix' path
| AtPathU ByteString -- ^ 'Control.Lens.at' path
| NonPathU ByteString -- ^ 'Control.Lens.non' path
| FieldU pos pos -- ^ Path from a record to one of its fields
| CtorU pos -- ^ Path from a record to a tuple containing the fields of one of its constructors
| NewtypePathU -- ^ A path that unwraps a newtype
| OrderedPathU -- ^ A path to a 'Order'.
| ViewPathU -- ^ A path corresponding to the 'Control.Lens.Path._View' iso
| FoldPathU -- ^ A path to an instance of FoldableWithIndex
| SingularPathU [UHop pos] -- ^ 'Control.Lens.singular' path
| UnsafeSingularPathU [UHop pos] -- ^ 'Control.Lens.unsafeSingular' path
deriving (Eq, Ord, Data, Typeable, Show)
newtype PKey s = PKey {unPKey :: Path 'U s} deriving (Typeable, Eq, Ord, Data, Show)


data N a = N a
instance Show (N Name) where
show (N (Name o f)) = "(Name (" <> show o <> ") (" <> show f <> "))"

gFind :: (MonadPlus m, Data a, Typeable b) => a -> m b
gFind = msum . map return . listify (const True)
40 changes: 35 additions & 5 deletions test/instances.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import Control.Lens.Traversal (Traversal')
import Control.Lens.Action ((^!!), act)
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.ByteString (ByteString)
import Data.Data (Data)
import Data.Data.Lens (template)
import Data.Fixed (Fixed, E1)
import Data.List
import Data.SafeCopy
import Data.SafeCopy.Internal (renderTH, renderDecs)
import Data.Serialize (runPut, runGet)
import Data.Serialize (runPut, runGet, Serialize)
import Data.Set (Set)
import Data.Time (UniversalTime(..), ZonedTime(..))
import Data.Tree (Tree)
import Data.Typeable (Typeable)
Expand All @@ -27,6 +30,7 @@ import Language.Haskell.TH.Syntax
import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.QuickCheck hiding (Fixed, (===))
import Types
import qualified Data.Vector as V
import qualified Data.Vector.Primitive as VP
import qualified Data.Vector.Storable as VS
Expand Down Expand Up @@ -116,8 +120,12 @@ do let a = conT ''Int
main :: IO ()
main = defaultMain $ testGroup "SafeCopy instances"
[ testGroup "decode is the inverse of encode" inversions
, testGroup "deriveSafeCopy'"
[ testCase "deriveSafeCopy 0 'base ''(,,,,,,,)" $ do
, deriveTests ]


deriveTests =
testGroup "deriveSafeCopy'"
[ testCase "deriveSafeCopy 0 'base ''(,,,,,,,)" $ do
let decs = $(lift =<< deriveSafeCopy 0 'base ''(,,,,,,,))
renderDecs decs @?= intercalate "\n"
["instance (SafeCopy a, SafeCopy b, SafeCopy c, SafeCopy d, SafeCopy e, SafeCopy f, SafeCopy g, SafeCopy h) => SafeCopy ((,,,,,,,) a b c d e f g h)",
Expand All @@ -127,13 +135,35 @@ main = defaultMain $ testGroup "SafeCopy instances"
" kind = base",
" errorTypeName _ = \"GHC.Tuple.(,,,,,,,)\""]
, testCase "deriveSafeCopy' 0 'base [t(,,,,,,,)|]" $ do
let decs = $(lift =<< deriveSafeCopy' 0 'base [t|forall a b c d e f g h. (Show a, Typeable a, SafeCopy a, SafeCopy b, SafeCopy c, SafeCopy d, SafeCopy e, SafeCopy f, SafeCopy g, SafeCopy h) => (a,b,c,d,e,f,g,h)|])
let decs = $(lift =<< deriveSafeCopy' 0 'base [t|forall a b c d e f g h. (Show a, Typeable a) => (a,b,c,d,e,f,g,h)|])
renderDecs decs @?= intercalate "\n"
["instance (Show a, Typeable a, SafeCopy a, SafeCopy b, SafeCopy c, SafeCopy d, SafeCopy e, SafeCopy f, SafeCopy g, SafeCopy h) => SafeCopy ((,,,,,,,) a b c d e f g h)",
" where putCopy ((,,,,,,,) a1 a2 a3 a4 a5 a6 a7 a8) = contain (do {safePut_a <- getSafePut; safePut_b <- getSafePut; safePut_c <- getSafePut; safePut_d <- getSafePut; safePut_e <- getSafePut; safePut_f <- getSafePut; safePut_g <- getSafePut; safePut_h <- getSafePut; safePut_a a1; safePut_b a2; safePut_c a3; safePut_d a4; safePut_e a5; safePut_f a6; safePut_g a7; safePut_h a8; return ()})",
" getCopy = contain (label \"GHC.Tuple.(,,,,,,,):\" (do {safeGet_a <- getSafeGet; safeGet_b <- getSafeGet; safeGet_c <- getSafeGet; safeGet_d <- getSafeGet; safeGet_e <- getSafeGet; safeGet_f <- getSafeGet; safeGet_g <- getSafeGet; safeGet_h <- getSafeGet; (((((((return (,,,,,,,) <*> safeGet_a) <*> safeGet_b) <*> safeGet_c) <*> safeGet_d) <*> safeGet_e) <*> safeGet_f) <*> safeGet_g) <*> safeGet_h}))",
" version = 0",
" kind = base",
" errorTypeName _ = \"GHC.Tuple.(,,,,,,,)\""]
]
, testCase "deriveSafeCopy' 0 'base (ClientView db)" $ do
let decs = $(lift =<< deriveSafeCopy' 0 'base [t|forall db. ClientView db|])
renderDecs decs @?= intercalate "\n"
["instance SafeCopy (ViewModifiers db (PKey Client)) => SafeCopy (ClientView db)",
" where putCopy (ClientView a1) = contain (do {safePut_ViewModifiersdbPKeyClient <- getSafePut; safePut_ViewModifiersdbPKeyClient a1; return ()})",
" getCopy = contain (label \"Types.ClientView:\" (do {safeGet_ViewModifiersdbPKeyClient <- getSafeGet; return ClientView <*> safeGet_ViewModifiersdbPKeyClient}))",
" version = 0",
" kind = base",
" errorTypeName _ = \"Types.ClientView\""]
, testCase "deriveSafeCopy' 0 'base SearchTerm" $ do
let decs = $(lift =<< deriveSafeCopy' 0 'base [t|SearchTerm|])
renderDecs decs @?= intercalate "\n"
["instance SafeCopy ([CI Text]) => SafeCopy SearchTerm",
" where putCopy (SearchTerm a1) = contain (do {putWord8 0; safePut_ListaListChar <- getSafePut; safePut_ListaListChar a1; return ()})",
" putCopy (NoTerm) = contain (do {putWord8 1; return ()})",
" getCopy = contain (label \"Types.SearchTerm:\" (do {tag <- getWord8;",
" case tag of",
" 0 -> do {safeGet_ListaListChar <- getSafeGet; return SearchTerm <*> safeGet_ListaListChar}",
" 1 -> do return NoTerm",
" _ -> fail (\"Could not identify tag \\\"\" ++ (show tag ++ \"\\\" for type \\\"Types.SearchTerm\\\" that has only 2 constructors. Maybe your data is corrupted?\"))}))",
" version = 0",
" kind = base",
" errorTypeName _ = \"Types.SearchTerm\""]
]

0 comments on commit 888f013

Please sign in to comment.