Skip to content

Commit e92cad4

Browse files
authored
Merge pull request #17 from asvyazin/master
fixes for purescript 0.9.1
2 parents 644d0a2 + 0c92879 commit e92cad4

File tree

4 files changed

+60
-55
lines changed

4 files changed

+60
-55
lines changed

bower.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-console": "^0.1.1",
21-
"purescript-exceptions": "^0.3.0",
22-
"purescript-lists": "^0.7.4",
23-
"purescript-profunctor": "^0.3.1",
24-
"purescript-strings": "^0.7.0",
25-
"purescript-transformers": "^0.8.1"
20+
"purescript-console": "^1.0.0",
21+
"purescript-exceptions": "^1.0.0",
22+
"purescript-lists": "^1.0.0",
23+
"purescript-profunctor": "^1.0.0",
24+
"purescript-strings": "^1.0.0",
25+
"purescript-transformers": "^1.0.0",
26+
"purescript-partial": "^1.1.2"
2627
}
2728
}

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"private": true,
33
"scripts": {
4-
"postinstall": "pulp dep install",
4+
"postinstall": "bower install",
55
"clean": "rimraf output && rimraf .pulp-cache",
66
"build": "pulp build",
77
"test": "pulp test"
88
},
99
"devDependencies": {
10-
"pulp": "^7.0.0",
11-
"purescript": "^0.7.6",
12-
"rimraf": "^2.5.0"
10+
"pulp": "^9.0.1",
11+
"purescript": "^0.9.1",
12+
"rimraf": "^2.5.2",
13+
"bower": "^1.7.9"
1314
}
1415
}

src/Data/Path/Pathy.purs

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ module Data.Path.Pathy
1616
, RelPath()
1717
, Sandboxed()
1818
, Unsandboxed()
19+
, appendPath
1920
, (</>)
21+
, setExtension
2022
, (<.>)
23+
, parentAppend
2124
, (<..>)
2225
, runDirName
2326
, runFileName
@@ -66,7 +69,7 @@ module Data.Path.Pathy
6669
where
6770

6871
import Prelude
69-
import qualified Data.String as S
72+
import Data.String as S
7073
import Data.Foldable(foldl)
7174
import Data.Array((!!), filter, length, zipWith, range)
7275
import Data.Tuple(Tuple(..), fst, snd)
@@ -196,7 +199,7 @@ module Data.Path.Pathy
196199
changeExtension f nm @ (FileName n) =
197200
let
198201
ext = f $ extension nm
199-
in (\(FileName n) -> if ext == "" then FileName n else FileName $ n ++ "." ++ ext) (dropExtension nm)
202+
in (\(FileName n) -> if ext == "" then FileName n else FileName $ n <> "." <> ext) (dropExtension nm)
200203

201204
-- | Creates a path which points to a relative directory of the specified name.
202205
dir :: forall s. String -> Path Rel Dir s
@@ -216,41 +219,41 @@ module Data.Path.Pathy
216219
pathName :: forall b s. AnyPath b s -> Either (Maybe DirName) FileName
217220
pathName = bimap dirName fileName
218221

219-
infixl 6 </>
220-
221222
-- | Given a directory path, appends either a file or directory to the path.
222-
(</>) :: forall a b s. Path a Dir s -> Path Rel b s -> Path a b s
223-
(</>) (Current ) (Current ) = Current
224-
(</>) (Root ) (Current ) = Root
225-
(</>) (ParentIn p1 ) (Current ) = ParentIn (p1 </> Current)
226-
(</>) (FileIn p1 f1) (Current ) = FileIn (p1 </> Current) f1
227-
(</>) (DirIn p1 d1) (Current ) = DirIn (p1 </> Current) d1
228-
(</>) (Current ) (Root ) = Current -- doesn't make sense but cannot exist
229-
(</>) (Root ) (Root ) = Root -- doesn't make sense but cannot exist
230-
(</>) (ParentIn p1 ) (Root ) = ParentIn (p1 </> Current) -- doesn't make sense but cannot exist
231-
(</>) (FileIn p1 f1) (Root ) = FileIn (p1 </> Current) f1 -- doesn't make sense but cannot exist
232-
(</>) (DirIn p1 d1) (Root ) = DirIn (p1 </> Current) d1 -- doesn't make sense but cannot exist
233-
(</>) (p1 ) (ParentIn p2 ) = ParentIn (p1 </> p2 )
234-
(</>) (p1 ) (FileIn p2 f2) = FileIn (p1 </> p2 ) f2
235-
(</>) (p1 ) (DirIn p2 d2) = DirIn (p1 </> p2 ) d2
236-
237-
infixl 6 <.>
223+
appendPath :: forall a b s. Path a Dir s -> Path Rel b s -> Path a b s
224+
appendPath (Current ) (Current ) = Current
225+
appendPath (Root ) (Current ) = Root
226+
appendPath (ParentIn p1 ) (Current ) = ParentIn (p1 </> Current)
227+
appendPath (FileIn p1 f1) (Current ) = FileIn (p1 </> Current) f1
228+
appendPath (DirIn p1 d1) (Current ) = DirIn (p1 </> Current) d1
229+
appendPath (Current ) (Root ) = Current -- doesn't make sense but cannot exist
230+
appendPath (Root ) (Root ) = Root -- doesn't make sense but cannot exist
231+
appendPath (ParentIn p1 ) (Root ) = ParentIn (p1 </> Current) -- doesn't make sense but cannot exist
232+
appendPath (FileIn p1 f1) (Root ) = FileIn (p1 </> Current) f1 -- doesn't make sense but cannot exist
233+
appendPath (DirIn p1 d1) (Root ) = DirIn (p1 </> Current) d1 -- doesn't make sense but cannot exist
234+
appendPath (p1 ) (ParentIn p2 ) = ParentIn (p1 </> p2 )
235+
appendPath (p1 ) (FileIn p2 f2) = FileIn (p1 </> p2 ) f2
236+
appendPath (p1 ) (DirIn p2 d2) = DirIn (p1 </> p2 ) d2
237+
238+
infixl 6 appendPath as </>
238239

239240
-- | Sets the extension of the file to the specified extension.
240241
-- |
241242
-- | ```purescript
242243
-- | file "image" <.> "png"
243244
-- | ```
244-
(<.>) :: forall a s. Path a File s -> String -> Path a File s
245-
(<.>) p ext = renameFile (changeExtension $ const ext) p
245+
setExtension :: forall a s. Path a File s -> String -> Path a File s
246+
setExtension p ext = renameFile (changeExtension $ const ext) p
246247

247-
infixl 6 <..>
248+
infixl 6 setExtension as <.>
248249

249250
-- | Ascends into the parent of the specified directory, then descends into
250251
-- | the specified path. The result is always unsandboxed because it may escape
251252
-- | its previous sandbox.
252-
(<..>) :: forall a b s s'. Path a Dir s -> Path Rel b s' -> Path a b Unsandboxed
253-
(<..>) d p = (parentDir' d) </> unsandbox p
253+
parentAppend :: forall a b s s'. Path a Dir s -> Path Rel b s' -> Path a b Unsandboxed
254+
parentAppend d p = (parentDir' d) </> unsandbox p
255+
256+
infixl 6 parentAppend as <..>
254257

255258
-- | Determines if this path is absolutely located.
256259
isAbsolute :: forall a b s. Path a b s -> Boolean
@@ -385,11 +388,11 @@ module Data.Path.Pathy
385388
where
386389
go (Current) = "./"
387390
go (Root) = "/"
388-
go (ParentIn p) = go p ++ "../"
389-
go (DirIn p @ (FileIn _ _ ) (DirName d)) = go p ++ "/" ++ d ++ "/" -- dir inside a file
390-
go (DirIn p (DirName d)) = go p ++ d ++ "/" -- dir inside a dir
391-
go (FileIn p @ (FileIn _ _) (FileName f)) = go p ++ "/" ++ f -- file inside a file
392-
go (FileIn p (FileName f)) = go p ++ f
391+
go (ParentIn p) = go p <> "../"
392+
go (DirIn p @ (FileIn _ _ ) (DirName d)) = go p <> "/" <> d <> "/" -- dir inside a file
393+
go (DirIn p (DirName d)) = go p <> d <> "/" -- dir inside a dir
394+
go (FileIn p @ (FileIn _ _) (FileName f)) = go p <> "/" <> f -- file inside a file
395+
go (FileIn p (FileName f)) = go p <> f
393396

394397
unsafePrintPath :: forall a b s. Path a b s -> String
395398
unsafePrintPath = unsafePrintPath' posixEscaper
@@ -458,7 +461,7 @@ module Data.Path.Pathy
458461
segs = S.split "/" p
459462
last = length segs - 1
460463
isAbs = S.take 1 p == "/"
461-
isFile = maybe false (/= "") (segs !! last)
464+
isFile = maybe false (_ /= "") (segs !! last)
462465
tuples = zipWith Tuple segs (range 0 last)
463466

464467
folder :: forall a b s. Path a b s -> Tuple String Int -> Path a b s
@@ -495,15 +498,15 @@ module Data.Path.Pathy
495498
instance showPath :: Show (Path a b s) where
496499
show (Current ) = "currentDir"
497500
show (Root ) = "rootDir"
498-
show (ParentIn p ) = "(parentDir' " ++ show p ++ ")"
499-
show (FileIn p (FileName f)) = "(" ++ show p ++ " </> file " ++ show f ++ ")"
500-
show (DirIn p (DirName f)) = "(" ++ show p ++ " </> dir " ++ show f ++ ")"
501+
show (ParentIn p ) = "(parentDir' " <> show p <> ")"
502+
show (FileIn p (FileName f)) = "(" <> show p <> " </> file " <> show f <> ")"
503+
show (DirIn p (DirName f)) = "(" <> show p <> " </> dir " <> show f <> ")"
501504

502505
instance eqPath :: Eq (Path a b s) where
503506
eq p1 p2 = canonicalize p1 `identicalPath` canonicalize p2
504507

505508
instance showFileName :: Show FileName where
506-
show (FileName name) = "FileName " ++ show name
509+
show (FileName name) = "FileName " <> show name
507510

508511
instance eqFileName :: Eq FileName where
509512
eq (FileName n1) (FileName n2) = n1 == n2
@@ -512,7 +515,7 @@ module Data.Path.Pathy
512515
compare (FileName n1) (FileName n2) = compare n1 n2
513516

514517
instance showDirName :: Show DirName where
515-
show (DirName name) = "DirName " ++ show name
518+
show (DirName name) = "DirName " <> show name
516519

517520
instance eqDirName :: Eq DirName where
518521
eq (DirName n1) (DirName n2) = n1 == n2

test/Main.purs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
module Test.Main where
22

33
import Prelude
4-
import Control.Monad.Eff.Console
5-
import Control.Monad.Eff(Eff())
6-
import Data.Maybe(Maybe(..))
7-
import Data.Maybe.Unsafe(fromJust)
8-
import Data.Path.Pathy
4+
import Control.Monad.Eff.Console(CONSOLE, infoShow)
5+
import Control.Monad.Eff(Eff)
6+
import Data.Maybe(Maybe(..), fromJust)
7+
import Partial.Unsafe (unsafePartial)
8+
import Data.Path.Pathy(Path, dir, rootDir, parseAbsDir, parseRelDir, currentDir, file, parseAbsFile, parseRelFile, parentDir', depth, sandbox, dropExtension, renameFile, canonicalize, unsandbox, unsafePrintPath, (</>), (<..>), (<.>))
99

1010
test :: forall a. (Show a, Eq a) => String -> a -> a -> Eff (console :: CONSOLE) Unit
1111
test name actual expected= do
12-
print $ "Test: " ++ name
13-
if expected == actual then print $ "Passed: " ++ (show expected) else print $ "Failed: Expected " ++ (show expected) ++ " but found " ++ (show actual)
12+
infoShow $ "Test: " <> name
13+
if expected == actual then infoShow $ "Passed: " <> (show expected) else infoShow $ "Failed: Expected " <> (show expected) <> " but found " <> (show actual)
1414

1515
test' :: forall a b s. String -> Path a b s -> String -> Eff (console :: CONSOLE) Unit
1616
test' n p s = test n (unsafePrintPath p) s
1717

1818
main :: Eff (console :: CONSOLE) Unit
1919
main = do
20-
print "NEW TEST"
20+
infoShow "NEW TEST"
2121

2222
-- Should not compile:
2323
-- test "(</>) - file in dir" (printPath (file "image.png" </> dir "foo")) "./image.png/foo"
@@ -58,7 +58,7 @@ module Test.Main where
5858
test' "renameFile - single level deep" (renameFile dropExtension (file "image.png")) "./image"
5959

6060
test' "sandbox - sandbox absolute dir to one level higher"
61-
(fromJust $ sandbox (rootDir </> dir "foo") (rootDir </> dir "foo" </> dir "bar")) "./bar/"
61+
(unsafePartial $ fromJust $ sandbox (rootDir </> dir "foo") (rootDir </> dir "foo" </> dir "bar")) "./bar/"
6262

6363
test "depth - negative" (depth (parentDir' $ parentDir' $ parentDir' $ currentDir)) (-3)
6464

0 commit comments

Comments
 (0)