Skip to content

Commit e3a704d

Browse files
authored
Merge pull request #14 from purescript-node/resolve-is-impure
`resolve` is impure
2 parents 71b255d + bf6dc34 commit e3a704d

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

bower.json

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"gulpfile.js",
2020
"package.json"
2121
],
22+
"dependencies": {
23+
"purescript-effect": "^2.0.0"
24+
},
2225
"devDependencies": {
2326
"purescript-assert": "^4.0.0",
2427
"purescript-console": "^4.1.0"

src/Node/Path.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ exports.concat = function (segments) {
1010

1111
exports.resolve = function (from) {
1212
return function (to) {
13-
return path.resolve.apply(this, from.concat([to]));
13+
return function () {
14+
return path.resolve.apply(this, from.concat([to]));
15+
};
1416
};
1517
};
1618

src/Node/Path.purs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module Node.Path where
22

3+
-- | Type for strings representing file paths.
4+
import Effect (Effect)
5+
36
-- | Type for strings representing file paths.
47
type FilePath = String
58

@@ -12,7 +15,7 @@ foreign import normalize :: FilePath -> FilePath
1215
foreign import concat :: Array FilePath -> FilePath
1316

1417
-- | Resolves `to` to an absolute path ([from...], to).
15-
foreign import resolve :: Array FilePath -> FilePath -> FilePath
18+
foreign import resolve :: Array FilePath -> FilePath -> Effect FilePath
1619

1720
-- | Solve the relative path from `from` to `to`.
1821
foreign import relative :: FilePath -> FilePath -> FilePath

test/Test/Main.purs

+24-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
module Test.Main where
22

33
import Prelude
4+
45
import Effect (Effect)
5-
import Node.Path (parse, delimiter, normalize, sep, extname, basenameWithoutExt, basename, dirname, relative, concat)
6-
import Test.Assert (assert)
6+
import Node.Path (basename, basenameWithoutExt, concat, delimiter, dirname, extname, normalize, parse, relative, resolve, sep)
7+
import Test.Assert (assert, assertEqual)
78

89
main :: Effect Unit
910
main = do
10-
assert $ normalize "/foo/bar//baz/asdf/quux/.." == normalize "/foo/bar/baz/asdf"
11-
assert $ concat ["/foo", "bar"] == normalize "/foo/bar"
12-
assert $ relative "/data/orandea/test/aaa" "/data/orandea/impl/bbb" == normalize "../../impl/bbb"
13-
assert $ dirname "/foo/bar/baz/asdf/quux" == normalize "/foo/bar/baz/asdf"
14-
assert $ basename "/foo/bar/baz/asdf/quux.html" == "quux.html"
15-
assert $ basenameWithoutExt "/foo/bar/baz/asdf/quux.html" ".html" == "quux"
16-
assert $ basenameWithoutExt "/foo/bar/baz/asdf/quux.txt" ".html" == "quux.txt"
17-
assert $ extname "index.html" == ".html"
18-
assert $ extname "index.coffee.md" == ".md"
19-
assert $ extname "index." == "."
20-
assert $ extname "index" == ""
21-
assert $ sep == normalize "/"
11+
assertEqual { actual: normalize "/foo/bar//baz/asdf/quux/..", expected: normalize "/foo/bar/baz/asdf" }
12+
assertEqual { actual: concat ["/foo", "bar"], expected: normalize "/foo/bar" }
13+
assertEqual { actual: relative "/data/orandea/test/aaa" "/data/orandea/impl/bbb", expected: normalize "../../impl/bbb" }
14+
assertEqual { actual: dirname "/foo/bar/baz/asdf/quux", expected: normalize "/foo/bar/baz/asdf" }
15+
assertEqual { actual: basename "/foo/bar/baz/asdf/quux.html", expected: "quux.html" }
16+
assertEqual { actual: basenameWithoutExt "/foo/bar/baz/asdf/quux.html" ".html", expected: "quux" }
17+
assertEqual { actual: basenameWithoutExt "/foo/bar/baz/asdf/quux.txt" ".html", expected: "quux.txt" }
18+
assertEqual { actual: extname "index.html", expected: ".html" }
19+
assertEqual { actual: extname "index.coffee.md", expected: ".md" }
20+
assertEqual { actual: extname "index.", expected: "." }
21+
assertEqual { actual: extname "index", expected: "" }
22+
assertEqual { actual: sep, expected: normalize "/" }
2223
assert $ delimiter == ";" || delimiter == ":"
2324

2425
let path = parse "/home/user/file.js"
25-
assert $ path.root == "/"
26-
assert $ path.dir == "/home/user"
27-
assert $ path.base == "file.js"
28-
assert $ path.ext == ".js"
29-
assert $ path.name == "file"
26+
assertEqual { actual: path.root, expected: "/" }
27+
assertEqual { actual: path.dir, expected: "/home/user" }
28+
assertEqual { actual: path.base, expected: "file.js" }
29+
assertEqual { actual: path.ext, expected: ".js" }
30+
assertEqual { actual: path.name, expected: "file" }
31+
32+
path1 <- resolve ["a"] ""
33+
path2 <- resolve ["a"] "."
34+
assertEqual { actual: path1, expected: path2 }

0 commit comments

Comments
 (0)