-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Data.Path.Pathy.Gen where | ||
|
||
import Prelude | ||
|
||
import Control.Monad.Gen (class MonadGen) | ||
import Control.Monad.Gen as Gen | ||
import Control.Monad.Rec.Class (class MonadRec) | ||
import Data.Either (Either(..)) | ||
import Data.Foldable (foldr) | ||
import Data.List as L | ||
import Data.NonEmpty ((:|)) | ||
import Data.Path.Pathy (AbsPath, AbsFile, AbsDir, RelDir, RelFile, RelPath, Sandboxed, (</>)) | ||
import Data.Path.Pathy as P | ||
|
||
genAbsDirPath :: forall m. MonadGen m => MonadRec m => m String -> m (AbsDir Sandboxed) | ||
genAbsDirPath genName = Gen.sized \size → do | ||
newSize ← Gen.chooseInt 0 size | ||
Gen.resize (const newSize) do | ||
parts ∷ L.List String ← Gen.unfoldable genName | ||
pure $ foldr (flip P.appendPath <<< P.dir) P.rootDir parts | ||
|
||
genAbsFilePath :: forall m. MonadGen m => MonadRec m => m String -> m (AbsFile Sandboxed) | ||
genAbsFilePath genName = do | ||
dir ← genAbsDirPath genName | ||
file ← genName | ||
pure $ dir </> P.file file | ||
|
||
genAbsAnyPath :: forall m. MonadGen m => MonadRec m => m String -> m (AbsPath Sandboxed) | ||
genAbsAnyPath genName = Gen.oneOf $ (Left <$> genAbsDirPath genName) :| [Right <$> genAbsFilePath genName] | ||
|
||
genRelDirPath :: forall m. MonadGen m => MonadRec m => m String -> m (RelDir Sandboxed) | ||
genRelDirPath genName = Gen.sized \size → do | ||
newSize ← Gen.chooseInt 0 size | ||
Gen.resize (const newSize) do | ||
parts ∷ L.List String ← Gen.unfoldable genName | ||
pure $ foldr (flip P.appendPath <<< P.dir) P.currentDir parts | ||
|
||
genRelFilePath :: forall m. MonadGen m => MonadRec m => m String -> m (RelFile Sandboxed) | ||
genRelFilePath genName = do | ||
dir ← genRelDirPath genName | ||
file ← genName | ||
pure $ dir </> P.file file | ||
|
||
genRelAnyPath :: forall m. MonadGen m => MonadRec m => m String -> m (RelPath Sandboxed) | ||
genRelAnyPath genName = Gen.oneOf $ (Left <$> genRelDirPath genName) :| [Right <$> genRelFilePath genName] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters