Skip to content

Commit 6347a16

Browse files
committed
resolve uses Effect, update tests for assertEqual
1 parent 71b255d commit 6347a16

File tree

3 files changed

+78
-21
lines changed

3 files changed

+78
-21
lines changed

src/Node/Path.js

Lines changed: 3 additions & 1 deletion
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,81 @@
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, 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
12+
{ actual: normalize "/foo/bar//baz/asdf/quux/.."
13+
, expected: normalize "/foo/bar/baz/asdf"
14+
}
15+
assertEqual
16+
{ actual: concat ["/foo", "bar"]
17+
, expected: normalize "/foo/bar"
18+
}
19+
assertEqual
20+
{ actual: relative "/data/orandea/test/aaa" "/data/orandea/impl/bbb"
21+
, expected: normalize "../../impl/bbb"
22+
}
23+
assertEqual
24+
{ actual: dirname "/foo/bar/baz/asdf/quux"
25+
, expected: normalize "/foo/bar/baz/asdf"
26+
}
27+
assertEqual
28+
{ actual: basename "/foo/bar/baz/asdf/quux.html"
29+
, expected: "quux.html"
30+
}
31+
assertEqual
32+
{ actual: basenameWithoutExt "/foo/bar/baz/asdf/quux.html" ".html"
33+
, expected: "quux"
34+
}
35+
assertEqual
36+
{ actual: basenameWithoutExt "/foo/bar/baz/asdf/quux.txt" ".html"
37+
, expected: "quux.txt"
38+
}
39+
assertEqual
40+
{ actual: extname "index.html"
41+
, expected: ".html"
42+
}
43+
assertEqual
44+
{ actual: extname "index.coffee.md"
45+
, expected: ".md"
46+
}
47+
assertEqual
48+
{ actual: extname "index."
49+
, expected: "."
50+
}
51+
assertEqual
52+
{ actual: extname "index"
53+
, expected: ""
54+
}
55+
assertEqual
56+
{ actual: sep
57+
, expected: normalize "/"
58+
}
2259
assert $ delimiter == ";" || delimiter == ":"
2360

2461
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"
62+
assertEqual
63+
{ actual: path.root
64+
, expected: "/"
65+
}
66+
assertEqual
67+
{ actual: path.dir
68+
, expected: "/home/user"
69+
}
70+
assertEqual
71+
{ actual: path.base
72+
, expected: "file.js"
73+
}
74+
assertEqual
75+
{ actual: path.ext
76+
, expected: ".js"
77+
}
78+
assertEqual
79+
{ actual: path.name
80+
, expected: "file"
81+
}

0 commit comments

Comments
 (0)