{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fno-warn-unused-top-binds #-}
module Main (main) where
import Composite
import Composite.Dhall ()
import Composite.TH
import Data.Functor.Contravariant
import Data.Text
import Dhall
import Test.Tasty
import Test.Tasty.HUnit
withLensesAndProxies
[d|
type A = "a" :-> Text
type B = "b" :-> Int
|]
type RecId = Record '[A, B]
type RecMaybe = Rec Maybe '[A, B]
newtype Template a = Template (Op Text a)
deriving newtype (FromDhall)
recId :: RecId
recId = "foo" :*: 5 :*: RNil
recMaybe :: RecMaybe
recMaybe = Just "foo" :^: Just 5 :^: RNil
newtype Templates = Templates {unTemplates :: Rec Template '[A, B]}
deriving (FromDhall) via (Rec (Op Text) '[A, B])
tests :: TestTree
tests =
testGroup
"Parsing Tests"
[ testCase "parses Record" $ do
x <- input auto "./test/data/A.dhall"
assertEqual "" recId x,
testCase "parses Maybe Rec" $ do
x <- input auto "./test/data/B.dhall"
assertEqual "" recMaybe x,
testCase "parses Contravariant" $ do
(_ :: Templates) <- input auto "./test/data/C.dhall"
pure ()
]
main :: IO ()
main = defaultMain tests