Skip to content

Commit

Permalink
Update to new include syntax, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-snezhko committed Mar 2, 2024
1 parent 43154a3 commit abc6b71
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 283 deletions.
42 changes: 16 additions & 26 deletions compiler/test/stdlib/sys.fs.test.gr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module FsTest

include "sys/fs"
include "path"
include "bytes"
include "result"
include "list"
from "sys/fs" include Fs
from "path" include Path
from "bytes" include Bytes
from "result" include Result
from "list" include List

let path = Path.fromString
let testPath = str => path("test/test-data/" ++ str)
Expand All @@ -30,8 +30,7 @@ assert Fs.Binary.readFile(testPath("baz.txt")) == Err(Fs.NoSuchFileOrDirectory)
assert Fs.Binary.writeFile(testPath("baz.txt"), b"some stuff") == Ok(void)
assert Fs.Binary.readFile(testPath("baz.txt")) == Ok(b"some stuff")

assert Fs.Utf8.writeFile(testPath("baz.txt"), "some other stuff 🌾") ==
Ok(void)
assert Fs.Utf8.writeFile(testPath("baz.txt"), "some other stuff 🌾") == Ok(void)
assert Fs.Utf8.readFile(testPath("baz.txt")) == Ok("some other stuff 🌾")

assert Fs.Binary.writeFile(
Expand Down Expand Up @@ -96,11 +95,11 @@ assert !Fs.exists(testPath("blahblah"))
assert !Fs.exists(path(".."))

// readDir
from Fs use { type DirectoryEntry }
assert Result.map(x =>
List.sort((x, y) => compare(x.name, y.name), x), Fs.readDir(
testPath("test-dir")
)) ==
use Fs.{ type DirectoryEntry }
assert Result.map(
x => List.sort(compare=(x, y) => compare(x.name, y.name), x),
Fs.readDir(testPath("test-dir"))
) ==
Ok(
[
{ name: "dir", fileType: Fs.Directory },
Expand All @@ -109,7 +108,7 @@ assert Result.map(x =>
{ name: "file3.txt", fileType: Fs.File },
{ name: "in-directory.txt", fileType: Fs.File },
{ name: "link", fileType: Fs.SymbolicLink },
]
],
)
assert Fs.readDir(baseDirPath=Some(testPath("test-dir")), path("dir")) ==
Ok([{ name: "nested.txt", fileType: Fs.File }])
Expand Down Expand Up @@ -137,13 +136,9 @@ assert Fs.readLink(testPath("foo.txt")) == Err(Fs.InvalidArgument)
assert !Fs.exists(testPath("symlink"))
assert Fs.makeSymlink(path("foo.txt"), testPath("symlink")) == Ok(void)
assert Fs.readLink(testPath("symlink")) == Ok(path("foo.txt"))
assert Result.unwrap(
Fs.stats(testPath("symlink"), followSymlink=false)
).fileType ==
assert Result.unwrap(Fs.stats(testPath("symlink"), followSymlink=false)).fileType ==
Fs.SymbolicLink
assert Result.unwrap(
Fs.stats(testPath("symlink"), followSymlink=true)
).fileType ==
assert Result.unwrap(Fs.stats(testPath("symlink"), followSymlink=true)).fileType ==
Fs.File
assert Fs.makeSymlink(path("bar.txt"), testPath("symlink")) ==
Err(Fs.FileExists)
Expand Down Expand Up @@ -224,9 +219,7 @@ assert Fs.copy(
followSymlink=false
) ==
Ok(void)
assert Result.unwrap(
Fs.stats(testPath("copied-link"), followSymlink=false)
).fileType ==
assert Result.unwrap(Fs.stats(testPath("copied-link"), followSymlink=false)).fileType ==
Fs.SymbolicLink

// rename
Expand Down Expand Up @@ -289,8 +282,5 @@ assert Fs.remove(testPath("test-dir/symlink")) == Ok(void)
assert Fs.remove(testPath("test-dir/newfile.txt")) == Ok(void)
assert Fs.remove(testPath("copied-dir"), removeMode=Fs.RemoveRecursive) ==
Ok(void)
assert Fs.remove(
testPath("copied-link-to-dir"),
removeMode=Fs.RemoveRecursive
) ==
assert Fs.remove(testPath("copied-link-to-dir"), removeMode=Fs.RemoveRecursive) ==
Ok(void)
Loading

0 comments on commit abc6b71

Please sign in to comment.