aboutsummaryrefslogtreecommitdiff
path: root/test/paths.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-09-21 17:44:08 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-09-21 17:44:08 -0400
commitc941b9a3325228eba404455afea7ccea0da45095 (patch)
treed4ca88c6848ac2e6ceee635bb87add87ba6d2322 /test/paths.tm
parent1cec086a6034ad546977cae7aeaf4bb876d21970 (diff)
Fix tests
Diffstat (limited to 'test/paths.tm')
-rw-r--r--test/paths.tm127
1 files changed, 43 insertions, 84 deletions
diff --git a/test/paths.tm b/test/paths.tm
index 22f79c7b..e72cddec 100644
--- a/test/paths.tm
+++ b/test/paths.tm
@@ -3,15 +3,12 @@ func main()
assert (/).exists()
assert (~/).exists()
- >> (~/Downloads/file(1).txt)
- = (~/Downloads/file(1).txt)
+ assert (~/Downloads/file(1).txt) == (~/Downloads/file(1).txt)
- >> (/half\)paren)
- = (/half\)paren)
+ assert (/half\)paren) == (/half\)paren)
>> filename := "example.txt"
- >> (~).child(filename)
- = (~/example.txt)
+ assert (~).child(filename) == (~/example.txt)
>> tmpdir := (/tmp/tomo-test-path-XXXXXX).unique_directory()
assert (/tmp).subdirectories().has(tmpdir)
@@ -19,22 +16,17 @@ func main()
>> tmpfile := (tmpdir++(./one.txt))
>> tmpfile.write("Hello world")
>> tmpfile.append("!")
- >> tmpfile.read()
- = "Hello world!"
- >> tmpfile.read_bytes()!
- = [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21]
+ assert tmpfile.read() == "Hello world!"
+ assert tmpfile.read_bytes()! == [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21]
assert tmpdir.files().has(tmpfile)
if tmp_lines := tmpfile.by_line() then
- >> [line for line in tmp_lines]
- = ["Hello world!"]
+ assert [line for line in tmp_lines] == ["Hello world!"]
else
fail("Couldn't read lines in $tmpfile")
- >> (./does-not-exist.xxx).read()
- = none
- >> (./does-not-exist.xxx).read_bytes()
- = none
+ assert (./does-not-exist.xxx).read() == none
+ assert (./does-not-exist.xxx).read_bytes() == none
if lines := (./does-not-exist.xxx).by_line() then
fail("I could read lines in a nonexistent file")
else
@@ -42,101 +34,68 @@ func main()
>> tmpfile.remove()
- >> tmpdir.files().has(tmpfile)
- = no
+ assert tmpdir.files().has(tmpfile) == no
>> tmpdir.remove()
>> p := (/foo/baz.x/qux.tar.gz)
- >> p.base_name()
- = "qux.tar.gz"
- >> p.parent()
- = (/foo/baz.x)
- >> p.extension()
- = "tar.gz"
- >> p.extension(full=no)
- = "gz"
- >> p.has_extension("gz")
- = yes
- >> p.has_extension(".gz")
- = yes
- >> p.has_extension("tar.gz")
- = yes
- >> p.has_extension("txt")
- = no
- >> p.has_extension("")
- = no
- >> (./foo).has_extension("")
- = yes
- >> (..).has_extension("")
- = yes
- >> (~/.foo).has_extension("foo")
- = no
- >> (~/.foo).extension()
- = ""
- >> (~/foo).extension()
- = ""
-
- >> (~/.foo.baz.qux).extension()
- = "baz.qux"
-
- >> (/).parent()
- = (/)
- >> (~/x/.).parent()
- = (~)
- >> (~/x).parent()
- = (~)
- >> (.).parent()
- = (..)
- >> (..).parent()
- = (../..)
- >> (../foo).parent()
- = (..)
+ assert p.base_name() == "qux.tar.gz"
+ assert p.parent() == (/foo/baz.x)
+ assert p.extension() == "tar.gz"
+ assert p.extension(full=no) == "gz"
+ assert p.has_extension("gz") == yes
+ assert p.has_extension(".gz") == yes
+ assert p.has_extension("tar.gz") == yes
+ assert p.has_extension("txt") == no
+ assert p.has_extension("") == no
+ assert (./foo).has_extension("") == yes
+ assert (..).has_extension("") == yes
+ assert (~/.foo).has_extension("foo") == no
+ assert (~/.foo).extension() == ""
+ assert (~/foo).extension() == ""
+
+ assert (~/.foo.baz.qux).extension() == "baz.qux"
+
+ assert (/).parent() == (/)
+ assert (~/x/.).parent() == (~)
+ assert (~/x).parent() == (~)
+ assert (.).parent() == (..)
+ assert (..).parent() == (../..)
+ assert (../foo).parent() == (..)
# Concatenation tests:
say("Basic relative path concatenation:")
- >> (/foo) ++ (./baz)
- = (/foo/baz)
+ assert (/foo) ++ (./baz) == (/foo/baz)
say("Concatenation with a current directory (`.`):")
- >> (/foo/bar) ++ (./.)
- = (/foo/bar)
+ assert (/foo/bar) ++ (./.) == (/foo/bar)
say("Trailing slash in the first path:")
- >> (/foo/) ++ (./baz)
- = (/foo/baz)
+ assert (/foo/) ++ (./baz) == (/foo/baz)
say("Trailing slash in the second path:")
- >> (/foo/bar) ++ (./baz/)
- = (/foo/bar/baz)
+ assert (/foo/bar) ++ (./baz/) == (/foo/bar/baz)
say("Removing redundant current directory (`.`):")
- >> (/foo/bar) ++ (./baz/./qux)
- = (/foo/bar/baz/qux)
+ assert (/foo/bar) ++ (./baz/./qux) == (/foo/bar/baz/qux)
say("Removing redundant parent directory (`..`):")
- >> (/foo/bar) ++ (./baz/qux/../quux)
- = (/foo/bar/baz/quux)
+ assert (/foo/bar) ++ (./baz/qux/../quux) == (/foo/bar/baz/quux)
say("Collapsing `..` to navigate up:")
- >> (/foo/bar/baz) ++ (../qux)
- = (/foo/bar/qux)
+ assert (/foo/bar/baz) ++ (../qux) == (/foo/bar/qux)
say("Current directory and parent directory mixed:")
- >> (/foo/bar) ++ (././../baz)
- = (/foo/baz)
+ assert (/foo/bar) ++ (././../baz) == (/foo/baz)
say("Path begins with a `.`:")
- >> (/foo) ++ (./baz/../qux)
- = (/foo/qux)
+ assert (/foo) ++ (./baz/../qux) == (/foo/qux)
say("Multiple slashes:")
- >> (/foo) ++ (./baz//qux)
- = (/foo/baz/qux)
+ assert (/foo) ++ (./baz//qux) == (/foo/baz/qux)
say("Complex path with multiple `.` and `..`:")
- >> (/foo/bar/baz) ++ (./.././qux/./../quux)
- = (/foo/bar/quux)
+ assert (/foo/bar/baz) ++ (./.././qux/./../quux) == (/foo/bar/quux)
say("Globbing:")
>> (./*.tm).glob()