packages feed

htree-0.1.1.0: test/Spec/HTree/Fixtures.hs

module Spec.HTree.Fixtures
  ( type ExL
  , exL
  , type Ex
  , ex
  , exShown
  , exC
  , type ExReal
  , exReal
  , type I
  , pattern I
  , unI
  , type K
  , pattern K
  , unK
  , type ExIntegral
  , exIntegral
  , type ExBfsDfs
  , exBfsDfs
  )
where

import Data.Functor.Const (Const (Const, getConst))
import Data.Functor.Identity (Identity (Identity, runIdentity))
import Data.HTree.Labeled (pattern HNodeL, type TyNodeL)
import Data.HTree.List (HList (HNil, HSing, (:::)))
import Data.HTree.Tree (HTree (HLeaf, HNode), TyTree (TyNode))
import Data.Tree (Tree (Node))

type K = Const

pattern K :: forall a b. a -> K a b
pattern K a = Const a

unK :: forall a b. K a b -> a
unK = getConst

type I = Identity

pattern I :: forall a. a -> I a
pattern I a = Identity a

unI :: forall a. I a -> a
unI = runIdentity

type ExL =
  TyNodeL
    "top"
    Int
    [ TyNodeL
        "b"
        Int
        [ TyNodeL "c" Int '[]
        , TyNodeL "d" Bool '[]
        , TyNodeL
            "e"
            String
            '[ TyNodeL "bla" Int '[]
             ]
        ]
    , TyNodeL "a" Int '[]
    ]

exL :: HTree Identity ExL
exL =
  HNodeL 5 do
    HNodeL 12 do
      HNodeL 13 HNil
        ::: HNodeL (I False) HNil
        ::: HNodeL "test" (HNodeL 9 HNil ::: HNil)
        ::: HNil
      ::: HNodeL 42 HNil
      ::: HNil

type Ex =
  TyNode
    Int
    [ TyNode
        Int
        [ TyNode Int '[]
        , TyNode Bool '[]
        , TyNode String '[ 'TyNode Int '[]]
        ]
    , 'TyNode Int '[]
    ]

ex :: HTree Identity Ex
ex =
  HNode 5 do
    HNode 12 do
      HNode 13 HNil
        ::: HNode (I False) HNil
        ::: HNode "test" (HNode 9 HNil ::: HNil)
        ::: HNil
      ::: HNode 43 HNil
      ::: HNil

exShown :: Tree String
exShown =
  Node
    "5"
    [ Node
        "12"
        [Node "13" [], Node "False" [], Node "\"test\"" [Node "9" []]]
    , Node "43" []
    ]

exC :: HTree (K Int) Ex
exC =
  HNode 5 do
    HNode 12 do
      HNode 13 HNil
        ::: HNode 13 HNil
        ::: HNode 5 (HNode 9 HNil ::: HNil)
        ::: HNil
      ::: HNode 43 HNil
      ::: HNil

type ExReal =
  'TyNode
    Int
    '[ 'TyNode
        Float
        '[ 'TyNode Double '[]
         , 'TyNode Float '[]
         , 'TyNode
            Integer
            '[ 'TyNode Float '[]]
         ]
     , 'TyNode
        Int
        '[ 'TyNode Float '[]]
     ]

exReal :: HTree I ExReal
exReal =
  HNode 42 do
    HNode 2.7 do
      HLeaf 13.7
        ::: HLeaf 12.2
        ::: HSing do
          HNode 14 do
            HSing (HLeaf (I 12.7))
      ::: HNode 12 do HSing (HLeaf 3.14)
      ::: HNil

type ExIntegral =
  'TyNode
    Int
    [ TyNode
        Integer
        '[ TyNode Int '[]
         , TyNode Integer '[]
         , TyNode
            Integer
            '[TyNode Int '[]]
         ]
    , TyNode
        Int
        '[TyNode Int '[]]
    ]

exIntegral :: HTree I ExIntegral
exIntegral = HNode 42 do
  HNode 7 do
    HLeaf 13 ::: HLeaf 122 ::: HSing do
      HNode 14 (HSing (HLeaf 127))
    ::: HNode 12 (HSing (HLeaf 31))
    ::: HNil

type ExBfsDfs =
  TyNodeL
    "top"
    Int
    [ TyNodeL
        "inter"
        Int
        '[ TyNodeL "foo" Int '[]
         ]
    , TyNodeL "foo" Int '[]
    ]

exBfsDfs :: HTree I ExBfsDfs
exBfsDfs = HNodeL 42 do
  HNodeL 4 (HSing (HNodeL 69 HNil))
    ::: HNodeL 67 HNil
    ::: HNil