packages feed

cursor-dirforest-gen-0.0.0.0 / src / Cursor / DirForest / Gen.hs

{-# LANGUAGE RecordWildCards #-}{-# LANGUAGE ScopedTypeVariables #-}{-# OPTIONS_GHC -fno-warn-orphans #-}module Cursor.DirForest.Gen whereimport Cursor.DirForestimport Cursor.FileOrDir.Gen ()import Cursor.Forestimport Cursor.Forest.Gen ()import Cursor.List.NonEmptyimport Cursor.Treeimport Data.GenValidityimport Data.GenValidity.Containers ()import Data.GenValidity.DirForest ()import Data.Treeimport Test.QuickCheckinstance (GenValid a, GenValid b) => GenValid (DirForestCursor a b) where  shrinkValid = shrinkValidStructurally  genValid = DirForestCursor . ForestCursor <$> (NonEmptyCursor <$> genListOf goCTree <*> goTreeCursor <*> genListOf goCTree)    where      goForest :: Gen (Forest (FileOrDir b))      goForest = genListOf goTree      goTree :: Gen (Tree (FileOrDir b))      goTree = do        fod <- genValid        f <- case fod of          FodFile _ _ -> pure []          FodDir _ -> goForest        pure $ Node fod f      goCForest :: Gen (CForest (FileOrDir b))      goCForest =        oneof          [ pure EmptyCForest,            ClosedForest <$> genNonEmptyOf goTree,            OpenForest <$> genNonEmptyOf goCTree          ]      goCTree :: Gen (CTree (FileOrDir b))      goCTree = do        fod <- genValid        cf <- case fod of          FodFile _ _ -> pure EmptyCForest          FodDir _ -> goCForest        pure $ CNode fod cf      goTreeCursor :: Gen (TreeCursor (FileOrDirCursor a) (FileOrDir b))      goTreeCursor = sized $ \s -> do        (a, b, c) <- genSplit3 s        treeAbove <- resize a goMAbove        treeCurrent <- resize b genValid        treeBelow <- resize c $ case treeCurrent of          InProgress _ -> pure EmptyCForest          Existent (FodFile _ _) -> pure EmptyCForest          Existent (FodDir _) -> goCForest        pure TreeCursor {..}      goMAbove :: Gen (Maybe (TreeAbove (FileOrDir b)))      goMAbove = oneof [pure Nothing, Just <$> goAbove]      goAbove :: Gen (TreeAbove (FileOrDir b))      goAbove = sized $ \s -> do        (a, b, c, d) <- genSplit4 s        treeAboveLefts <- resize a $ genListOf goCTree        treeAboveAbove <- resize b goMAbove        treeAboveNode <- resize c $ FodDir <$> (genValid `suchThat` isTopLevel)        treeAboveRights <- resize d $ genListOf goCTree        pure TreeAbove {..}