cursor-dirforest-gen (empty) → 0.0.0.0
raw patch · 8 files changed · show whitespace changes · browse cursor-dirforest-gen-0.0.0.0
+384/−0 lines, 8 filesdep +QuickCheckdep +basedep +containerssetup-changed
Dependencies added: QuickCheck, base, containers, criterion, cursor, cursor-dirforest, cursor-dirforest-gen, cursor-gen, dirforest, genvalidity, genvalidity-containers, genvalidity-criterion, genvalidity-dirforest, genvalidity-hspec, hspec, path
Files
- Setup.hs +2/−0
- bench/Main.hs +18/−0 · folded
- cursor-dirforest-gen.cabal +78/−0
- src/Cursor/DirForest/Gen.hs +65/−0
- src/Cursor/FileOrDir/Gen.hs +28/−0
- test/Cursor/FileOrDirSpec.hs +34/−0 · folded
- test/Cursor/Simple/DirForestSpec.hs +158/−0 · folded
- test/Spec.hs +1/−0 · folded
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ bench/Main.hs view
@@ -0,0 +1,18 @@+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}++module Main where++import Criterion.Main as Criterion+import Cursor.DirForest+import Cursor.DirForest.Gen ()+import Data.GenValidity.Criterion++main :: IO ()+main =+ Criterion.defaultMain+ [ genValidBench @(FileOrDir Int),+ genValidBench @(FileOrDirCursor Int),+ genValidBench @(DirForestCursor Int Int)+ ]
+ cursor-dirforest-gen.cabal view
@@ -0,0 +1,78 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.38.3.+--+-- see: https://github.com/sol/hpack+--+-- hash: e378441308e75e4bc0e2b358258cb326f153f23cf5ecc4f2722cca016403b893++name: cursor-dirforest-gen+version: 0.0.0.0+synopsis: Generators for cursors for typed directory forests+homepage: https://github.com/NorfairKing/cursor-dirforest#readme+bug-reports: https://github.com/NorfairKing/cursor-dirforest/issues+license: MIT+build-type: Simple++source-repository head+ type: git+ location: https://github.com/NorfairKing/cursor-dirforest++library+ exposed-modules:+ Cursor.DirForest.Gen+ Cursor.FileOrDir.Gen+ other-modules:+ Paths_cursor_dirforest_gen+ hs-source-dirs:+ src+ build-depends:+ QuickCheck+ , base >=4.7 && <5+ , containers+ , cursor+ , cursor-dirforest+ , cursor-gen+ , genvalidity >=1.0.0.0+ , genvalidity-containers+ , genvalidity-dirforest+ default-language: Haskell2010++test-suite cursor-dirforest-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ Cursor.FileOrDirSpec+ Cursor.Simple.DirForestSpec+ Paths_cursor_dirforest_gen+ hs-source-dirs:+ test+ ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall+ build-depends:+ QuickCheck+ , base >=4.7 && <5+ , cursor+ , cursor-dirforest+ , cursor-dirforest-gen+ , dirforest+ , genvalidity-hspec+ , hspec+ , path+ default-language: Haskell2010++benchmark cursor-dirforest-bench+ type: exitcode-stdio-1.0+ main-is: Main.hs+ other-modules:+ Paths_cursor_dirforest_gen+ hs-source-dirs:+ bench/+ ghc-options: -Wall+ build-depends:+ QuickCheck+ , base >=4.7 && <5+ , criterion+ , cursor-dirforest+ , cursor-dirforest-gen+ , genvalidity-criterion+ default-language: Haskell2010
+ src/Cursor/DirForest/Gen.hs view
@@ -0,0 +1,65 @@+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Cursor.DirForest.Gen where++import Cursor.DirForest+import Cursor.FileOrDir.Gen ()+import Cursor.Forest+import Cursor.Forest.Gen ()+import Cursor.List.NonEmpty+import Cursor.Tree+import Data.GenValidity+import Data.GenValidity.Containers ()+import Data.GenValidity.DirForest ()+import Data.Tree+import Test.QuickCheck++instance (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 {..}
+ src/Cursor/FileOrDir/Gen.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE ScopedTypeVariables #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Cursor.FileOrDir.Gen where++import Cursor.FileOrDir+import Cursor.Forest.Gen ()+import Cursor.Text.Gen ()+import Data.GenValidity+import Data.GenValidity.Containers ()+import Data.GenValidity.DirForest ()+import Test.QuickCheck++instance (GenValid a) => GenValid (FileOrDirCursor a) where+ shrinkValid = shrinkValidStructurallyWithoutExtraFiltering+ genValid = genValidStructurallyWithoutExtraChecking++instance (GenValid a) => GenValid (FileOrDir a) where+ shrinkValid = shrinkValidStructurally+ genValid =+ oneof+ [ sized $ \s -> do+ (a, b) <- genSplit s+ rf <- resize a $ genValid `suchThat` isTopLevel+ v <- resize b genValid+ pure $ FodFile rf v,+ FodDir <$> (genValid `suchThat` isTopLevel)+ ]
+ test/Cursor/FileOrDirSpec.hs view
@@ -0,0 +1,34 @@+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}++module Cursor.FileOrDirSpec+ ( spec,+ )+where++import Cursor.FileOrDir+import Cursor.FileOrDir.Gen ()+import Data.Word+import Test.Hspec+import Test.Validity++spec :: Spec+spec = do+ genValidSpec @(FileOrDirCursor Word8)+ genValidSpec @(FileOrDir Word8)+ describe "makeFileOrDirCursor" $ it "produces valid cursors" $ producesValid (makeFileOrDirCursor @Word8)+ describe "rebuildFileOrDirCursor" $ do+ it "produces valid cursors" $+ producesValid+ (rebuildFileOrDirCursor @Word8)+ it "roundtrips with makeFileOrDirCursor" $ forAllValid $ \fod -> rebuildFileOrDirCursor (makeFileOrDirCursor @Word8 fod) `shouldBe` Just fod+ describe "fileOrDirCursorInsertChar" $ it "produces valid results" $ producesValid2 (fileOrDirCursorInsertChar @Word8)+ describe "fileOrDirCursorAppendChar" $ it "produces valid results" $ producesValid2 (fileOrDirCursorAppendChar @Word8)+ describe "fileOrDirCursorRemoveChar" $ it "produces valid results" $ producesValid (fileOrDirCursorRemoveChar @Word8)+ describe "fileOrDirCursorDeleteChar" $ it "produces valid results" $ producesValid (fileOrDirCursorDeleteChar @Word8)+ describe "fileOrDirCursorSelectPrevChar" $ it "produces valid results" $ producesValid (fileOrDirCursorSelectPrevChar @Word8)+ describe "fileOrDirCursorSelectNextChar" $ it "produces valid results" $ producesValid (fileOrDirCursorSelectNextChar @Word8)+ describe "fileOrDirCursorCompleteToDir" $ it "produces valid results" $ producesValid (fileOrDirCursorCompleteToDir @Word8)+ describe "completeTextCursorToFile" $ it "produces valid results" $ producesValid completeTextCursorToFile+ describe "completeTextCursorToDir" $ it "produces valid results" $ producesValid completeTextCursorToDir
+ test/Cursor/Simple/DirForestSpec.hs view
@@ -0,0 +1,158 @@+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}++module Cursor.Simple.DirForestSpec+ ( spec,+ )+where++import Cursor.DirForest.Gen ()+import Cursor.Simple.DirForest+import Cursor.Types+import qualified Data.DirForest as DF+import Data.Word+import Path+import Test.Hspec+import Test.Hspec.QuickCheck+import Test.QuickCheck+import Test.Validity++spec :: Spec+spec = modifyMaxShrinks (const 0) $ do+ -- No shrinking until I figure out what the problem is+ genValidSpec @(DirForestCursor Word8)+ describe "shrinkValid DirForestCursor" $ do+ it "does not shrink the singletonFile dirforest cursor to itself" $+ let df = makeDirForestCursor $ DF.singletonFile [relfile|a|] 'a'+ in shrinkValid df `shouldNotSatisfy` elem df+ it "does not shrink the singletonDir dirforest cursor to itself" $+ let df = makeDirForestCursor $ DF.singletonDir [reldir|a|] :: Maybe (DirForestCursor Char)+ in shrinkValid df `shouldNotSatisfy` elem df+ -- it "does not shrink a value to itself" $ do+ -- shrinkValidDoesNotShrinkToItselfWithLimit @(DirForestCursor Word8) 1+ -- shrinkValidSpecWithLimit @(DirForestCursor Word8) 1+ -- xdescribe "Does not hold because of extra validity constraints" $ lensSpecOnValid (dirForestCursorMapCursorL @Word8)+ describe "makeDirForestCursor" $ do+ it "works for an empty dirforest" $+ shouldBeValid $+ makeDirForestCursor (DF.empty @Word8)+ it "produces valid cursors" $ producesValid (makeDirForestCursor @Word8)+ describe "dirForestCursorPrepareForMovement" $ it "produces valid results" $ producesValid (dirForestCursorPrepareForMovement @Word8)+ describe "rebuildDirForestCursor" $ do+ it "produces valid dirforests" $ producesValid (rebuildDirForestCursor @Word8)+ it "is the inverse of 'makeDirForestCursor'" $+ forAllValid $ \df ->+ case makeDirForestCursor @Word8 df of+ Nothing -> pure ()+ Just dfc -> case rebuildDirForestCursor dfc of+ Updated df' -> df' `shouldBe` df+ Deleted -> expectationFailure "Should rountrip"+ describe "dirForestCursorSelectPrevTree" $ forestMovementMSpec dirForestCursorSelectPrevTree+ describe "dirForestCursorSelectNextTree" $ forestMovementMSpec dirForestCursorSelectNextTree+ xdescribe "is not true because of subselections" $+ describe "dirForestCursorSelectPrevTree and dirForestCursorSelectNextTree" $+ inverseMMovementsSpec dirForestCursorSelectPrevTree dirForestCursorSelectNextTree+ describe "dirForestCursorSelectFirstTree" $ forestMovementSpec dirForestCursorSelectFirstTree+ describe "dirForestCursorSelectLastTree" $ forestMovementSpec dirForestCursorSelectLastTree+ xdescribe "is not true because of subselections" $+ describe "dirForestCursorSelectFirstTree and dirForestCursorSelectLastTree" $+ inverseMovementsSpec dirForestCursorSelectFirstTree dirForestCursorSelectLastTree+ describe "dirForestCursorSelectPrevOnSameLevel" $ forestMovementMSpec dirForestCursorSelectPrevOnSameLevel+ describe "dirForestCursorSelectNextOnSameLevel" $ forestMovementMSpec dirForestCursorSelectNextOnSameLevel+ xdescribe "is not true because of ordering of files in the map" $+ describe "dirForestCursorSelectPrevOnSameLevel and dirForestCursorSelectNextOnSameLevel" $+ inverseMMovementsSpec dirForestCursorSelectPrevOnSameLevel dirForestCursorSelectNextOnSameLevel+ describe "dirForestCursorSelectFirstOnSameLevel" $ forestMovementSpec dirForestCursorSelectFirstOnSameLevel+ describe "dirForestCursorSelectLastOnSameLevel" $ forestMovementSpec dirForestCursorSelectLastOnSameLevel+ xdescribe "is not true because of ordering of files in the map" $+ describe "dirForestCursorSelectFirstOnSameLevel and dirForestCursorSelectLastOnSameLevel" $+ inverseMovementsSpec dirForestCursorSelectFirstOnSameLevel dirForestCursorSelectLastOnSameLevel+ describe "dirForestCursorSelectPrev" $ forestMovementMSpec dirForestCursorSelectPrev+ describe "dirForestCursorSelectNext" $ forestMovementMSpec dirForestCursorSelectNext+ describe "dirForestCursorSelectFirst" $ forestMovementSpec dirForestCursorSelectFirst+ describe "dirForestCursorSelectLast" $ forestMovementSpec dirForestCursorSelectLast+ describe "dirForestCursorSelectFirstChild" $ forestMovementMSpec dirForestCursorSelectFirstChild+ describe "dirForestCursorSelectLastChild" $ forestMovementMSpec dirForestCursorSelectLastChild+ describe "dirForestCursorSelectParent" $ do+ it "produces valid cursors" $ producesValid (dirForestCursorSelectParent @Word8)+ xdescribe "This does not hold, because in-progress file or directories will be deleted before moving" $ do+ it "is the inverse of dirForestCursorSelectFirstChild" $+ inverseMProp dirForestCursorSelectFirstChild dirForestCursorSelectParent+ it "is the inverse of dirForestCursorSelectLastChild" $+ inverseMProp dirForestCursorSelectLastChild dirForestCursorSelectParent+ describe "dirForestCursorDeleteCurrent" $ it "produces valid results" $ producesValid (dirForestCursorDeleteCurrent @Word8)+ describe "dirForestCursorStartNew" $ it "produces valid results" $ producesValid (dirForestCursorStartNew @Word8)+ describe "dirForestCursorStartNewBelowAtStart" $ it "produces valid results" $ producesValid (dirForestCursorStartNewBelowAtStart @Word8)+ describe "dirForestCursorStartNewBelowAtEnd" $ it "produces valid results" $ producesValid (dirForestCursorStartNewBelowAtEnd @Word8)+ describe "dirForestCursorStopNew" $ it "produces valid results" $ producesValid (dirForestCursorStopNew @Word8)+ describe "dirForestCursorInsertChar" $ it "produces valid results" $ producesValid2 (dirForestCursorInsertChar @Word8 @Word8)+ describe "dirForestCursorAppendChar" $ it "produces valid results" $ producesValid2 (dirForestCursorAppendChar @Word8 @Word8)+ describe "dirForestCursorRemoveChar" $ it "produces valid results" $ producesValid (dirForestCursorRemoveChar @Word8)+ describe "dirForestCursorDeleteChar" $ it "produces valid results" $ producesValid (dirForestCursorDeleteChar @Word8)+ describe "dirForestCursorSelectPrevChar" $ it "produces valid results" $ producesValid (dirForestCursorSelectPrevChar @Word8 @Word8)+ describe "dirForestCursorSelectNextChar" $ it "produces valid results" $ producesValid (dirForestCursorSelectNextChar @Word8 @Word8)+ describe "dirForestCursorCompleteToDir" $ it "produces valid results" $ producesValid (dirForestCursorCompleteToDir @Word8 @Word8)+ describe "dirForestCursorCompleteToFile" $ it "produces valid results" $ producesValid2 (dirForestCursorCompleteToFile @Word8 @Word8)++inverseMovementsSpec ::+ (forall a. (Show a, Eq a, GenValid a) => DirForestCursor a -> DeleteOrUpdate (DirForestCursor a)) ->+ (forall a. (Show a, Eq a, GenValid a) => DirForestCursor a -> DeleteOrUpdate (DirForestCursor a)) ->+ Spec+inverseMovementsSpec f1 f2 = do+ it "are inverses starting with the First" $+ inverseProp f1 f2+ it "are inverses starting with the Second" $+ inverseProp f2 f1++inverseProp ::+ (forall a. (Show a, Eq a, GenValid a) => DirForestCursor a -> DeleteOrUpdate (DirForestCursor a)) ->+ (forall a. (Show a, Eq a, GenValid a) => DirForestCursor a -> DeleteOrUpdate (DirForestCursor a)) ->+ Property+inverseProp f g = forAllValid $ \dfc -> case f @Word8 dfc of+ Deleted -> pure () -- Fine+ Updated dfc' -> case g @Word8 dfc' of+ Deleted -> pure () -- Fine+ Updated dfc'' -> dfc'' `shouldBe` dfc++inverseMMovementsSpec ::+ (forall a. (Show a, Eq a, GenValid a) => DirForestCursor a -> DeleteOrUpdate (Maybe (DirForestCursor a))) ->+ (forall a. (Show a, Eq a, GenValid a) => DirForestCursor a -> DeleteOrUpdate (Maybe (DirForestCursor a))) ->+ Spec+inverseMMovementsSpec f1 f2 = do+ it "are inverses starting with the First" $+ inverseMProp f1 f2+ it "are inverses starting with the Second" $+ inverseMProp f2 f1++inverseMProp ::+ (forall a. (Show a, Eq a, GenValid a) => DirForestCursor a -> DeleteOrUpdate (Maybe (DirForestCursor a))) ->+ (forall a. (Show a, Eq a, GenValid a) => DirForestCursor a -> DeleteOrUpdate (Maybe (DirForestCursor a))) ->+ Property+inverseMProp f g = forAllValid $ \dfc -> case f @Word8 dfc of+ Deleted -> pure () -- Fine+ Updated Nothing -> pure () -- Fine+ Updated (Just dfc') -> case g @Word8 dfc' of+ Deleted -> pure () -- Fine+ Updated Nothing -> expectationFailure "The second movement must not be a failure."+ Updated (Just dfc'') -> dfc'' `shouldBe` dfc++forestMovementMSpec :: (forall a. (Show a, Eq a, GenValid a) => DirForestCursor a -> DeleteOrUpdate (Maybe (DirForestCursor a))) -> Spec+forestMovementMSpec func = do+ it "produces valid results" $ producesValid (func @Word8)+ it "is a movement" $+ forAllValid $ \dfc ->+ case func @Word8 dfc of+ Deleted -> pure () -- Fine+ Updated Nothing -> pure () -- Fine+ Updated (Just dfc') -> rebuildDirForestCursor dfc' `shouldBe` rebuildDirForestCursor dfc++forestMovementSpec :: (forall a. (Show a, Eq a, GenValid a) => DirForestCursor a -> DeleteOrUpdate (DirForestCursor a)) -> Spec+forestMovementSpec func = do+ it "produces valid results" $ producesValid (func @Word8)+ it "is a movement" $+ forAllValid $ \dfc ->+ case func @Word8 dfc of+ Deleted -> pure () -- Fine+ Updated dfc' -> rebuildDirForestCursor dfc' `shouldBe` rebuildDirForestCursor dfc
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}