os: let `os.dir("/xyz")` return "/" (fixes compiling .v files in /)

pull/10999/head
Delyan Angelov 2021-07-30 03:14:09 +03:00
parent 7c504920e1
commit 44892fd942
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 5 additions and 0 deletions

View File

@ -170,6 +170,9 @@ pub fn dir(path string) string {
return '.'
}
pos := path.last_index(path_separator) or { return '.' }
if pos == 0 && path_separator == '/' {
return '/'
}
return path[..pos]
}

View File

@ -534,6 +534,8 @@ fn test_dir() {
assert os.dir('C:\\a\\b\\c') == 'C:\\a\\b'
assert os.dir('C:\\a\\b\\') == 'C:\\a\\b'
} $else {
assert os.dir('/') == '/'
assert os.dir('/abc') == '/'
assert os.dir('/var/tmp/foo') == '/var/tmp'
assert os.dir('/var/tmp/') == '/var/tmp'
}