Skip to content

Commit

Permalink
test for generically
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Díaz committed Apr 27, 2024
1 parent a841df9 commit 807be26
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Data/RBR/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,8 +1356,8 @@ class ToRecord (r :: Type) where

instance (
G.Generic r,
ToRecordHelper E (G.Rep r),
RecordCode r ~ RecordCode' E (G.Rep r)) =>
ToRecordHelper E (G.Rep r)
) =>
ToRecord (Generically (r :: Type)) where
type RecordCode (Generically (r :: Type)) = RecordCode' E (G.Rep r)
toRecord (Generically r) = toRecord' unit (G.from r)
Expand Down
12 changes: 12 additions & 0 deletions red-black-record.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ test-suite tests
red-black-record,
red-black-record:demoted
default-language: Haskell2010

test-suite tests-generically
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: tests-generically.hs
build-depends:
base >= 4.10.0.0 && < 5,
sop-core >= 0.4.0.0 && < 0.6,
tasty >= 0.10.1.1,
tasty-hunit >= 0.9.2,
red-black-record,
default-language: Haskell2010
42 changes: 42 additions & 0 deletions tests/tests-generically.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{-# LANGUAGE DataKinds,
TypeOperators,
TypeFamilies,
TypeApplications,
DeriveGeneric,
StandaloneDeriving,
DerivingStrategies,
UndecidableInstances,
KindSignatures,
PartialTypeSignatures,
FlexibleContexts,
ScopedTypeVariables
#-}
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}
module Main where

import Data.RBR

import GHC.Generics (Generic, Generically(..))

import Test.Tasty
import Test.Tasty.HUnit (testCase,Assertion,assertEqual,assertBool)

main :: IO ()
main = defaultMain tests

data Person = Person { personName :: String, address :: Address }
deriving stock (Show, Generic)

data Address = Address { street :: String, number :: Int, other :: Int }
deriving stock (Show, Generic)

tests :: TestTree
tests = testGroup "Tests" [ testCase "generically" testGenerically
]

testGenerically :: Assertion
testGenerically = do
let r = Person "Foo" (Address "Somestreet" 1 2)
a = Data.RBR.getFieldI @"address" (Data.RBR.toRecord (Generically r))
n = Data.RBR.getFieldI @"number" (Data.RBR.toRecord (Generically a))
assertEqual "number" n 1

0 comments on commit 807be26

Please sign in to comment.