From 0af3754b7dafa548f792368182dc15b5f9b468b4 Mon Sep 17 00:00:00 2001 From: Luke Boswell Date: Thu, 26 Sep 2024 18:12:19 +1000 Subject: [PATCH 1/3] ignore macos files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bea433 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.DS_Store From e5ed4ef6578556a9db057b17fe2a1435771dc025 Mon Sep 17 00:00:00 2001 From: Luke Boswell Date: Thu, 26 Sep 2024 18:12:59 +1000 Subject: [PATCH 2/3] fix invalid references --- package/Path.roc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package/Path.roc b/package/Path.roc index dc737d5..c7094b3 100644 --- a/package/Path.roc +++ b/package/Path.roc @@ -145,13 +145,13 @@ filename = \@Path path -> Ok lastSepIndex -> Ok (@Path (Unix (afterSep bytes lastSepIndex))) Err NotFound -> Ok (@Path path) # No separators? Entire path is the filename! -expect Path.filename (Path.unix "foo/bar.txt") == Ok (Path.unix "bar.txt") -expect Path.filename (Path.unix "foo/bar") == Ok (Path.unix "bar") -expect Path.filename (Path.unix "foo/bar/") == Err IsDirPath -expect Path.filename (Path.windows "foo\\bar\\") == Err IsDirPath -expect Path.filename (Path.unix "foo/bar..") == Err EndsInDots -expect Path.filename (Path.unix "foo") == Ok (Path.unix "foo") -expect Path.filename (Path.unix "") == Ok (Path.unix "") +expect filename (unix "foo/bar.txt") == Ok (unix "bar.txt") +expect filename (unix "foo/bar") == Ok (unix "bar") +expect filename (unix "foo/bar/") == Err IsDirPath +expect filename (windows "foo\\bar\\") == Err IsDirPath +expect filename (unix "foo/bar..") == Err EndsInDots +expect filename (unix "foo") == Ok (unix "foo") +expect filename (unix "") == Ok (unix "") afterSep : List (Num a), U64 -> List (Num a) afterSep = \list, lastSepIndex -> From b31e0c427bca46105e50e65d910ff88da8410310 Mon Sep 17 00:00:00 2001 From: Luke Boswell Date: Thu, 26 Sep 2024 18:13:16 +1000 Subject: [PATCH 3/3] implement custom Inspect ability for Path --- package/Path.roc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/package/Path.roc b/package/Path.roc index c7094b3..3ae019d 100644 --- a/package/Path.roc +++ b/package/Path.roc @@ -25,7 +25,10 @@ Path := [ Unix (List U8), Windows (List U16), ] - implements [Eq] + implements [Eq, Inspect { toInspector: pathInspector }] + +pathInspector : Path -> Inspector f where f implements InspectFormatter +pathInspector = \path -> Inspect.str (display path) unix : Str -> Path unix = \str -> @Path (Unix (Str.toUtf8 str)) @@ -406,15 +409,17 @@ normalizeUnix = \answer, remaining -> |> normalizeUnix (remaining |> List.dropFirst 1) ## Returns a string representation of the path, replacing anything that can't be -## represented in a string with the Unicode Replacement Character. +## represented in a string with the Unicode Replacement Character (U+FFFD) �. ## ## To get back an `Err` instead of silently replacing problems with the Unicode Replacement Character, ## use [toStr] instead. display : Path -> Str -# display = \@Path path -> -# when path is -# Unix bytes -> crash "TODO fromUtf8Lossy" -# Windows u16s -> crash "TODO fromUtf16Lossy" +display = \@Path path -> + when path is + Unix u8s -> + # TODO replace with Str.fromUtf8Lossy when it exists + Str.fromUtf8 u8s |> Result.withDefault "INVALID UTF-8" + Windows _u16s -> crash "TODO use fromUtf16Lossy" ## Like [display], but renders the path Windows-style (with backslashes for directory separators) ## even if it was originally created as a UNIX path (e.g. using [Path.unix]).