tomo/test/paths.tm

57 lines
1.0 KiB
Plaintext
Raw Normal View History

2024-09-08 23:43:15 -07:00
# Tests for file paths
func main():
>> (/):exists()
= yes
>> (~/):exists()
= yes
>> tmpdir := (/tmp/tomo-test-path-XXXXXX):unique_directory()
>> (/tmp):subdirectories():has(tmpdir)
= yes
>> tmpfile := (tmpdir++(./one.txt))
>> tmpfile:write("Hello world")
>> tmpfile:append("!")
>> tmpfile:read()
= "Hello world!"
>> tmpdir:files():has(tmpfile)
= yes
>> tmpfile:remove()
>> tmpdir:files():has(tmpfile)
= no
>> tmpdir:remove()
2024-09-09 00:52:56 -07:00
>> p := (/foo/baz.x/qux.tar.gz)
>> p:base_name()
= "qux.tar.gz"
>> p:parent()
2024-09-09 01:49:02 -07:00
= (/foo/baz.x/)
2024-09-09 00:52:56 -07:00
>> p:extension()
= "tar.gz"
>> p:extension(full=no)
= "gz"
>> (~/.foo):extension()
= ""
>> (~/foo):extension()
= ""
2024-09-09 01:49:02 -07:00
>> (~/.foo.baz.qux):extension()
= "baz.qux"
>> (/):parent()
= (/)
>> (~/x/.):parent()
= (~/)
>> (~/x):parent()
= (~/)
>> (./):parent()
= (../)
>> (../):parent()
= (../../)
>> (../foo):parent()
= (../)