Skip to content

resolve is impure #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"gulpfile.js",
"package.json"
],
"dependencies": {
"purescript-effect": "^2.0.0"
},
"devDependencies": {
"purescript-assert": "^4.0.0",
"purescript-console": "^4.1.0"
Expand Down
4 changes: 3 additions & 1 deletion src/Node/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ exports.concat = function (segments) {

exports.resolve = function (from) {
return function (to) {
return path.resolve.apply(this, from.concat([to]));
return function () {
return path.resolve.apply(this, from.concat([to]));
};
};
};

Expand Down
5 changes: 4 additions & 1 deletion src/Node/Path.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module Node.Path where

-- | Type for strings representing file paths.
import Effect (Effect)

-- | Type for strings representing file paths.
type FilePath = String

Expand All @@ -12,7 +15,7 @@ foreign import normalize :: FilePath -> FilePath
foreign import concat :: Array FilePath -> FilePath

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

-- | Solve the relative path from `from` to `to`.
foreign import relative :: FilePath -> FilePath -> FilePath
Expand Down
43 changes: 24 additions & 19 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
module Test.Main where

import Prelude

import Effect (Effect)
import Node.Path (parse, delimiter, normalize, sep, extname, basenameWithoutExt, basename, dirname, relative, concat)
import Test.Assert (assert)
import Node.Path (basename, basenameWithoutExt, concat, delimiter, dirname, extname, normalize, parse, relative, resolve, sep)
import Test.Assert (assert, assertEqual)

main :: Effect Unit
main = do
assert $ normalize "/foo/bar//baz/asdf/quux/.." == normalize "/foo/bar/baz/asdf"
assert $ concat ["/foo", "bar"] == normalize "/foo/bar"
assert $ relative "/data/orandea/test/aaa" "/data/orandea/impl/bbb" == normalize "../../impl/bbb"
assert $ dirname "/foo/bar/baz/asdf/quux" == normalize "/foo/bar/baz/asdf"
assert $ basename "/foo/bar/baz/asdf/quux.html" == "quux.html"
assert $ basenameWithoutExt "/foo/bar/baz/asdf/quux.html" ".html" == "quux"
assert $ basenameWithoutExt "/foo/bar/baz/asdf/quux.txt" ".html" == "quux.txt"
assert $ extname "index.html" == ".html"
assert $ extname "index.coffee.md" == ".md"
assert $ extname "index." == "."
assert $ extname "index" == ""
assert $ sep == normalize "/"
assertEqual { actual: normalize "/foo/bar//baz/asdf/quux/..", expected: normalize "/foo/bar/baz/asdf" }
assertEqual { actual: concat ["/foo", "bar"], expected: normalize "/foo/bar" }
assertEqual { actual: relative "/data/orandea/test/aaa" "/data/orandea/impl/bbb", expected: normalize "../../impl/bbb" }
assertEqual { actual: dirname "/foo/bar/baz/asdf/quux", expected: normalize "/foo/bar/baz/asdf" }
assertEqual { actual: basename "/foo/bar/baz/asdf/quux.html", expected: "quux.html" }
assertEqual { actual: basenameWithoutExt "/foo/bar/baz/asdf/quux.html" ".html", expected: "quux" }
assertEqual { actual: basenameWithoutExt "/foo/bar/baz/asdf/quux.txt" ".html", expected: "quux.txt" }
assertEqual { actual: extname "index.html", expected: ".html" }
assertEqual { actual: extname "index.coffee.md", expected: ".md" }
assertEqual { actual: extname "index.", expected: "." }
assertEqual { actual: extname "index", expected: "" }
assertEqual { actual: sep, expected: normalize "/" }
assert $ delimiter == ";" || delimiter == ":"

let path = parse "/home/user/file.js"
assert $ path.root == "/"
assert $ path.dir == "/home/user"
assert $ path.base == "file.js"
assert $ path.ext == ".js"
assert $ path.name == "file"
assertEqual { actual: path.root, expected: "/" }
assertEqual { actual: path.dir, expected: "/home/user" }
assertEqual { actual: path.base, expected: "file.js" }
assertEqual { actual: path.ext, expected: ".js" }
assertEqual { actual: path.name, expected: "file" }

path1 <- resolve ["a"] ""
path2 <- resolve ["a"] "."
assertEqual { actual: path1, expected: path2 }