Skip to content

Commit

Permalink
Fix bug where FileSystem.Path.join didn't respect root of first path.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinheghan committed Feb 10, 2025
1 parent 0bf6451 commit 7d50834
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/FileSystem/Path.gren
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,9 @@ prepend left right =
-}
join : Array Path -> Path
join paths =
Array.foldl append (fromPosixString ".") paths
when Array.popFirst paths is
Just { first, rest } ->
Array.foldl append first rest

Nothing ->
empty
18 changes: 17 additions & 1 deletion tests/src/Test/FileSystemPath.gren
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,14 @@ tests =
|> Path.append (Path.fromPosixString "/with/more")
|> Path.toPosixString
|> Expect.equal "/some/longer/file.md/with/more"
, test "Preserves root" <|
\{} ->
Path.fromPosixString "/some/path"
|> Path.append (Path.fromPosixString "nested/file.md")
|> Path.toPosixString
|> Expect.equal "/some/path/nested/file.md"
]
, describe "concat"
, describe "join"
[ test "Easier way to join many paths" <|
\{} ->
Expect.equal
Expand All @@ -160,5 +166,15 @@ tests =
, Path.fromPosixString "/file.md"
]
)
, test "Preserves root" <|
\{} ->
Expect.equal
(Path.fromPosixString "/my/long/path/to/file.md")
(Path.join
[ Path.fromPosixString "/my/long"
, Path.fromPosixString "path/to"
, Path.fromPosixString "file.md"
]
)
]
]

0 comments on commit 7d50834

Please sign in to comment.