Skip to content

Commit

Permalink
Merge pull request #2865 from armanbilge/fix/js-path-endswith
Browse files Browse the repository at this point in the history
Fix JS `Path#names` bug
  • Loading branch information
mpilquist authored Apr 1, 2022
2 parents 881d22d + 5a1de34 commit 66e3ced
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion io/js/src/main/scala/fs2/io/file/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final case class Path private (override val toString: String) extends PathApi {
@tailrec
def go(path: Path, acc: List[Path]): List[Path] =
path.parent match {
case None => acc
case None => path :: acc
case Some(parent) => go(parent, path.fileName :: acc)
}

Expand Down
9 changes: 9 additions & 0 deletions io/shared/src/test/scala/fs2/io/file/PathSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ class PathSuite extends Fs2Suite {
)
}

test("names") {
assertEquals(Path("foo").names, List(Path("foo")))
assertEquals(Path("foo/bar").names, List(Path("foo"), Path("bar")))
}

test("extName") {
assertEquals(Path("index.html").extName, ".html")
assertEquals(Path("index.coffee.md").extName, ".md")
Expand All @@ -98,6 +103,10 @@ class PathSuite extends Fs2Suite {
assertEquals(Path(".index.md").extName, ".md")
}

test("endsWith") {
assert(!Path("foo").endsWith(".xml"))
}

test("startsWith/endsWith") {
forAll { (start: Path, end: Path) =>
if (start.toString.nonEmpty && end.toString.nonEmpty) {
Expand Down

0 comments on commit 66e3ced

Please sign in to comment.