module Tests.AnimIdClash (test) where

import           Control.Monad.Unit (Unit(..))
import qualified GUI.Momentu.Align as Align
import qualified GUI.Momentu.View as View
import           Hyper
import qualified Lamdu.GUI.TypeView as TypeView
import qualified Lamdu.Name as Name
import qualified Lamdu.Sugar.Types as Sugar
import qualified Test.Lamdu.Env as Env
import           Test.Lamdu.Gui (verifyLayers)
import           Test.Lamdu.Instances ()

import           Test.Lamdu.Prelude

test :: Test
test =
    testGroup "animid-clash"
    [ testTypeView
    ]

testTypeView :: Test
testTypeView =
    do
        env <- Env.make
        TypeView.make typ env ^. Align.tValue . View.vAnimLayers
            & verifyLayers "" & either fail pure
    & testCase "typeview"
    where
        typ =
            recType "typ"
            [ (Sugar.Tag (Name.AutoGenerated "tag0") "tag0" "tag0", nullType "field0")
            , (Sugar.Tag (Name.AutoGenerated "tag1") "tag1" "tag1", nullType "field1")
            , (Sugar.Tag (Name.AutoGenerated "tag2") "tag2" "tag2", nullType "field2")
            ]
        nullType entityId = recType entityId []
        recType ::
            Sugar.EntityId ->
            [(Sugar.Tag Name.Name, Annotated Sugar.EntityId # Sugar.Type Name.Name Unit)] ->
            Annotated Sugar.EntityId # Sugar.Type Name.Name Unit
        recType entityId fields =
            Sugar.CompositeFields
            { Sugar._compositeFields = fields
            , Sugar._compositeExtension = Nothing
            }
            & Sugar.TRecord
            & Ann (Const entityId)
