Skip to content

Commit 032bf07

Browse files
committed
add in'
1 parent b3f7359 commit 032bf07

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/Pathy.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Pathy
77
, module Pathy.Sandboxed
88
) where
99

10-
import Pathy.Path (AbsDir, AbsFile, AbsPath, AnyPath, AnyDir, AnyFile, Path, RelDir, RelFile, RelPath, appendPath, currentDir, dir, dir', extendPath, file, file', fileName, foldPath, name, parentAppend, parentOf, peel, peelFile, refine, relativeTo, rename, renameTraverse, rootDir, setExtension, (<..>), (<.>), (</>))
10+
import Pathy.Path (AbsDir, AbsFile, AbsPath, AnyPath, AnyDir, AnyFile, Path, RelDir, RelFile, RelPath, appendPath, currentDir, dir, dir', extendPath, file, file', in', fileName, foldPath, name, parentAppend, parentOf, peel, peelFile, refine, relativeTo, rename, renameTraverse, rootDir, setExtension, (<..>), (<.>), (</>))
1111
import Pathy.Name (Name(..), joinName, splitName, alterExtension, extension)
1212
import Pathy.Printer (Escaper(..), Printer, debugPrintPath, posixPrinter, printPath, unsafePrintPath, windowsPrinter)
1313
import Pathy.Parser (Parser(..), parseAbsDir, parseAbsFile, parsePath, parseRelDir, parseRelFile, posixParser)

src/Pathy/Path.purs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Pathy.Path
1515
, dir'
1616
, file
1717
, file'
18+
, in'
1819
, parentOf
1920
, extendPath
2021
, appendPath, (</>)
@@ -118,7 +119,7 @@ file = file' <<< reflectName
118119

119120
-- | Creates a path which points to a relative file of the specified name.
120121
file' :: Name File -> Path Rel File
121-
file' = In currentDir
122+
file' = in'
122123

123124
-- | Creates a path which points to a relative directory of the specified name.
124125
-- |
@@ -129,7 +130,18 @@ dir = dir' <<< reflectName
129130

130131
-- | Creates a path which points to a relative directory of the specified name.
131132
dir' :: Name Dir -> Path Rel Dir
132-
dir' = In currentDir
133+
dir' = in'
134+
135+
-- | Creates a path which points to a relative directory or file of the specified name.
136+
-- | In most cases [`dir'`](#v:dir') or [`file'`](#v:file') should be used instead,
137+
-- | but it's still there in case the segment type is going to be determined based
138+
-- | on some type variable.
139+
-- |
140+
-- | ``` purescript
141+
-- | p == maybe p (\(Tuple r n) -> r </> in' n) (peel p)
142+
-- | ```
143+
in' :: forall a. Name a -> Path Rel a
144+
in' = In currentDir
133145

134146
-- | Creates a path that points to the parent directory of the specified path.
135147
-- |

test/Main.purs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import Prelude
55
import Control.Monad.Eff (Eff)
66
import Control.Monad.Eff.Console (CONSOLE, info)
77
import Control.Monad.Eff.Exception (EXCEPTION, throw)
8-
import Data.Maybe (Maybe(..))
8+
import Data.Maybe (Maybe(..), maybe)
99
import Data.Newtype (un)
1010
import Data.NonEmpty ((:|))
1111
import Data.String as Str
1212
import Data.String.NonEmpty (NonEmptyString)
1313
import Data.String.NonEmpty as NES
1414
import Data.Symbol (SProxy(..))
15-
import Pathy (class IsDirOrFile, class IsRelOrAbs, Abs, Dir, Name(..), Path, Rel, alterExtension, currentDir, debugPrintPath, dir, extension, file, joinName, parentOf, parseAbsDir, parseAbsFile, parseRelDir, parseRelFile, posixParser, posixPrinter, printPath, relativeTo, rename, rootDir, sandbox, sandboxAny, splitName, unsandbox, windowsPrinter, (<..>), (<.>), (</>))
15+
import Data.Tuple (Tuple(..))
16+
import Pathy (class IsDirOrFile, class IsRelOrAbs, Abs, Dir, Name(..), Path, Rel, alterExtension, currentDir, debugPrintPath, dir, extension, file, in', joinName, parentOf, parseAbsDir, parseAbsFile, parseRelDir, parseRelFile, peel, posixParser, posixPrinter, printPath, relativeTo, rename, rootDir, sandbox, sandboxAny, splitName, unsandbox, windowsPrinter, (<..>), (<.>), (</>))
1617
import Pathy.Gen as PG
1718
import Pathy.Name (reflectName)
1819
import Test.QuickCheck ((===))
@@ -95,6 +96,11 @@ checkJoinSplitNameId = do
9596
n <- genAmbigiousName
9697
pure $ joinName (splitName n) === id n
9798

99+
checkPeelIn :: forall b. IsDirOrFile b => Gen.Gen (Path Abs b) -> Gen.Gen QC.Result
100+
checkPeelIn gen = do
101+
p <- gen
102+
pure $ p === maybe p (\(Tuple r n) -> r </> in' n) (peel p)
103+
98104
checkRelative :: forall b. IsDirOrFile b => Gen.Gen (Path Abs b) -> Gen.Gen QC.Result
99105
checkRelative gen = do
100106
p1 <- gen
@@ -120,6 +126,8 @@ main = do
120126
info "checking `parse <<< print` for `RelFile`" *> QC.quickCheck parsePrintRelFilePath
121127
info "checking `relativeTo` for `AbsDir`" *> QC.quickCheck (checkRelative PG.genAbsDirPath)
122128
info "checking `relativeTo` for `AbsFile`" *> QC.quickCheck (checkRelative PG.genAbsFilePath)
129+
info "checking `p === maybe p (\\(Tuple r n) -> r </> in' n) (peel p)` for `AbsDir`" *> QC.quickCheck (checkPeelIn PG.genAbsDirPath)
130+
info "checking `p === maybe p (\\(Tuple r n) -> r </> in' n) (peel p)` for `AbsFile`" *> QC.quickCheck (checkPeelIn PG.genAbsFilePath)
123131
info "checking `joinName <<< splitName === id`" *> QC.quickCheck checkJoinSplitNameId
124132
info "checking `alterExtension id === id`" *> QC.quickCheck checkAlterExtensionId
125133

0 commit comments

Comments
 (0)