Skip to content

Commit e7b3c67

Browse files
committed
Fix issue with package-internal function that needed to be tested but
caused circular imports.
1 parent 280e887 commit e7b3c67

File tree

3 files changed

+13
-30
lines changed

3 files changed

+13
-30
lines changed

examples/end-to-end/script/src/FileTests.elm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ runTests =
8686
, test "absolute detection handles POSIX, UNC, and Windows" <|
8787
\() ->
8888
Expect.all
89-
[ \_ -> Expect.equal True (FilePath.fromString "/foo" |> FilePath.Internal.isAbsolute)
90-
, \_ -> Expect.equal True (FilePath.fromString "//server/share" |> FilePath.Internal.isAbsolute)
91-
, \_ -> Expect.equal True (FilePath.fromString "C:/foo" |> FilePath.Internal.isAbsolute)
92-
, \_ -> Expect.equal False (FilePath.fromString "C:foo" |> FilePath.Internal.isAbsolute)
93-
, \_ -> Expect.equal False (FilePath.fromString "../foo" |> FilePath.Internal.isAbsolute)
89+
[ \_ -> Expect.equal True (FilePath.fromString "/foo" |> FilePath.toString |> FilePath.Internal.isAbsolute)
90+
, \_ -> Expect.equal True (FilePath.fromString "//server/share" |> FilePath.toString |> FilePath.Internal.isAbsolute)
91+
, \_ -> Expect.equal True (FilePath.fromString "C:/foo" |> FilePath.toString |> FilePath.Internal.isAbsolute)
92+
, \_ -> Expect.equal False (FilePath.fromString "C:foo" |> FilePath.toString |> FilePath.Internal.isAbsolute)
93+
, \_ -> Expect.equal False (FilePath.fromString "../foo" |> FilePath.toString |> FilePath.Internal.isAbsolute)
9494
]
9595
()
9696
|> BackendTask.succeed

src/FilePath.elm

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import BackendTask.Http
3737
import BackendTask.Internal.Request
3838
import Char
3939
import FatalError exposing (FatalError)
40+
import FilePath.Internal
4041
import Json.Decode as Decode
4142
import Json.Encode as Encode
4243

@@ -151,7 +152,7 @@ append basePath nextPath =
151152
{ root = baseParsed.root
152153
, pathSegments =
153154
normalizePathSegments
154-
(isAbsoluteRoot baseParsed.root)
155+
(FilePath.Internal.isAbsolute baseParsed.root)
155156
(baseParsed.pathSegments ++ nextParsed.pathSegments)
156157
}
157158
)
@@ -319,22 +320,10 @@ parse (FilePath rawPath) =
319320
, pathSegments =
320321
withoutRoot
321322
|> String.split "/"
322-
|> normalizePathSegments (isAbsoluteRoot root)
323+
|> normalizePathSegments (FilePath.Internal.isAbsolute root)
323324
}
324325

325326

326-
isAbsoluteRoot : String -> Bool
327-
isAbsoluteRoot root =
328-
case root of
329-
"/" ->
330-
True
331-
332-
"//" ->
333-
True
334-
335-
_ ->
336-
String.endsWith ":/" root
337-
338327

339328
normalizePathSegments : Bool -> List String -> List String
340329
normalizePathSegments hasAbsoluteRoot rawSegments =

src/FilePath/Internal.elm

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
module FilePath.Internal exposing (isAbsolute)
22

33
import Char
4-
import FilePath exposing (FilePath)
54

65

7-
{-| Whether this path is absolute. Package-internal only — not exposed to consumers.
6+
{-| Whether a path string represents an absolute path. Package-internal only — not
7+
exposed to consumers.
88
9-
Checks the normalized string prefix, which is equivalent to checking the parsed root
10-
since `FilePath.fromString` guarantees consistent formatting:
9+
Works on the normalized string form produced by `FilePath.toString`:
1110
1211
- `/...` → POSIX absolute
1312
- `//...` → UNC absolute
1413
- `X:/...` → Windows drive absolute
1514
1615
-}
17-
isAbsolute : FilePath -> Bool
18-
isAbsolute filePath =
19-
let
20-
str : String
21-
str =
22-
FilePath.toString filePath
23-
in
16+
isAbsolute : String -> Bool
17+
isAbsolute str =
2418
String.startsWith "/" str
2519
|| hasAbsoluteDriveRoot str
2620

0 commit comments

Comments
 (0)