hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 19df031698ec34c2c3f398df8ba58a6f257f2c30
parent 0cefee1b35f96fb11f959a3f2ac1c295d18c81ee
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat,  8 Jan 2022 14:30:34 +0100

path::buffer: document+test trailing / behavior

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mpath/buffer.ha | 22++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/path/buffer.ha b/path/buffer.ha @@ -41,10 +41,18 @@ export fn dup(buf: *buffer) buffer = { // - Redundant ".." components // - Redundant path separators // - Any "." components, except in the case of "." -// - Trailing slashes, except in the case of "/" // // "/usr//bin/../bin/./hare" becomes "/usr/bin/hare" and "../../foo/bar" is -// unchanged. +// unchanged. The path will only end in a slash if the last item which was +// added ended in "/", like so: +// +// let buf = path::init(); +// path::set(&buf, "foo", "bar")!; +// assert(string(&buf) == "foo/bar"); +// path::set(&buf, "foo", "bar/")!; +// assert(string(&buf) == "foo/bar/"); +// path::set(&buf, "foo", "bar", "/")!; +// assert(string(&buf) == "foo/bar/"); export fn string(buf: *buffer) str = { const value = strings::fromutf8_unsafe(buf.cur); if (value == "") { @@ -172,4 +180,14 @@ fn doappend(buf: *buffer, elem: []u8) (void | errors::overflow) = { assert(string(&buf) == ".."); appendnorm(&buf, "..")!; assert(string(&buf) == "../.."); + + let buf = path::init(); + path::set(&buf, "foo", "bar")!; + assert(string(&buf) == "foo/bar"); + path::set(&buf, "foo", "bar/")!; + assert(string(&buf) == "foo/bar/"); + path::set(&buf, "foo", "bar", "/")!; + assert(string(&buf) == "foo/bar/"); + path::add(&buf, "/baz")!; + assert(string(&buf) == "foo/bar/baz"); };