diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index 00fa9d620..ef9469e15 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -167,7 +167,7 @@ fn void panicf(String fmt, String file, String function, uint line, args...) DString s; s.init(.using = mem); s.printf(fmt, ...args); - panic(s.as_str(), file, function, line); + panic(s.str_view(), file, function, line); }; } diff --git a/lib/std/core/dstring.c3 b/lib/std/core/dstring.c3 index a6e51e365..27c0114a4 100644 --- a/lib/std/core/dstring.c3 +++ b/lib/std/core/dstring.c3 @@ -93,7 +93,7 @@ fn void DString.chop(self, usz new_size) self.data().len = new_size; } -fn String DString.as_str(self) +fn String DString.str_view(self) { StringData* data = (StringData*)self; if (!data) return ""; @@ -261,14 +261,14 @@ fn void DString.append_chars(&self, String str) fn Char32[] DString.copy_utf32(&self, Allocator* using = mem::heap()) { - return self.as_str().to_utf32(using) @inline!!; + return self.str_view().to_utf32(using) @inline!!; } fn void DString.append_string(&self, DString str) { StringData* other = (StringData*)str; if (!other) return; - self.append(str.as_str()); + self.append(str.str_view()); } fn void DString.clear(self) diff --git a/lib/std/core/runtime.c3 b/lib/std/core/runtime.c3 index b80250a84..99056d588 100644 --- a/lib/std/core/runtime.c3 +++ b/lib/std/core/runtime.c3 @@ -96,7 +96,7 @@ fn bool run_benchmarks(BenchmarkUnit[] benchmarks) defer name.clear(); name.printf("Benchmarking %s ", unit.name); name.append_repeat('.', max_name - unit.name.len + 2); - io::printf("%s ", name.as_str()); + io::printf("%s ", name.str_view()); for (uint i = 0; i < benchmark_warmup_iterations; i++) { @@ -225,7 +225,7 @@ fn bool run_tests(TestUnit[] tests) defer name.clear(); name.printf("Testing %s ", unit.name); name.append_repeat('.', max_name - unit.name.len + 2); - io::printf("%s ", name.as_str()); + io::printf("%s ", name.str_view()); CallstackElement* stack = $$stacktrace(); if (stack) stack.prev = null; if (libc::setjmp(&context.buf) == 0) diff --git a/lib/std/core/string.c3 b/lib/std/core/string.c3 index 1fe51ec95..44fc8bed4 100644 --- a/lib/std/core/string.c3 +++ b/lib/std/core/string.c3 @@ -47,7 +47,7 @@ macro String tprintf(String fmt, ...) DString str; str.tinit(); str.printf(fmt, $vasplat()); - return str.as_str(); + return str.str_view(); } macro bool char_in_set(char c, String set) @@ -288,7 +288,7 @@ fn usz! String.rindex_of(s, String needle) return SearchResult.MISSING?; } -fn String ZString.as_str(str) +fn String ZString.str_view(str) { return (String)(str[:str.len()]); } @@ -355,8 +355,8 @@ fn void String.free(&s, Allocator* using = mem::heap()) fn String String.tcopy(s) => s.copy(mem::temp()) @inline; -fn String ZString.copy(z, Allocator* using = mem::heap()) => z.as_str().copy(using) @inline; -fn String ZString.tcopy(z) => z.as_str().copy(mem::temp()) @inline; +fn String ZString.copy(z, Allocator* using = mem::heap()) => z.str_view().copy(using) @inline; +fn String ZString.tcopy(z) => z.str_view().copy(mem::temp()) @inline; /** * Convert an UTF-8 string to UTF-16 diff --git a/lib/std/encoding/json.c3 b/lib/std/encoding/json.c3 index fab868a38..5ea266487 100644 --- a/lib/std/encoding/json.c3 +++ b/lib/std/encoding/json.c3 @@ -69,7 +69,7 @@ fn Object*! parse_from_token(JsonContext* context, JsonTokenType token) @local case RBRACE: case RBRACKET: case COLON: return JsonParsingError.UNEXPECTED_CHARACTER?; - case STRING: return object::new_string(context.last_string.as_str(), context.allocator); + case STRING: return object::new_string(context.last_string.str_view(), context.allocator); case NUMBER: return object::new_float(context.last_number, context.allocator); case TRUE: return object::new_bool(true); case FALSE: return object::new_bool(false); @@ -125,7 +125,7 @@ fn JsonTokenType! lex_number(JsonContext *context, char c) @local } } pushback(context, c); - double! d = t.as_str().to_double() ?? JsonParsingError.INVALID_NUMBER?; + double! d = t.str_view().to_double() ?? JsonParsingError.INVALID_NUMBER?; context.last_number = d!; return NUMBER; }; @@ -143,14 +143,14 @@ fn Object*! parse_map(JsonContext* context) @local { if (token != JsonTokenType.STRING) return JsonParsingError.UNEXPECTED_CHARACTER?; DString string = context.last_string; - if (map.has_key(string.as_str())) return JsonParsingError.DUPLICATE_MEMBERS?; + if (map.has_key(string.str_view())) return JsonParsingError.DUPLICATE_MEMBERS?; // Copy the key to our temp holder. We do this to work around the issue // if the temp allocator should be used as the default allocator. temp_key.clear(); temp_key.append(string); parse_expected(context, COLON)!; Object* element = parse_any(context)!; - map.set(temp_key.as_str(), element); + map.set(temp_key.str_view(), element); token = advance(context)!; if (token == JsonTokenType.COMMA) { diff --git a/lib/std/io/file.c3 b/lib/std/io/file.c3 index 9bca8fbfd..77ca1172c 100644 --- a/lib/std/io/file.c3 +++ b/lib/std/io/file.c3 @@ -17,7 +17,7 @@ fn File! open(String filename, String mode) fn File! open_path(Path path, String mode) { - return from_handle(os::native_fopen(path.as_str(), mode)); + return from_handle(os::native_fopen(path.str_view(), mode)); } fn File from_handle(CFile file) diff --git a/lib/std/io/formatter.c3 b/lib/std/io/formatter.c3 index c8d4cb52b..e0454f5e9 100644 --- a/lib/std/io/formatter.c3 +++ b/lib/std/io/formatter.c3 @@ -173,11 +173,11 @@ fn usz! Formatter.out_str(&self, any arg) @private case DISTINCT: if (arg.type == ZString.typeid) { - return self.out_substr(((ZString*)arg).as_str()); + return self.out_substr(((ZString*)arg).str_view()); } if (arg.type == DString.typeid) { - return self.out_substr(((DString*)arg).as_str()); + return self.out_substr(((DString*)arg).str_view()); } return self.out_str(any { arg.ptr, arg.type.inner }); case POINTER: diff --git a/lib/std/io/os/chdir.c3 b/lib/std/io/os/chdir.c3 index 57ce74b07..c479929f5 100644 --- a/lib/std/io/os/chdir.c3 +++ b/lib/std/io/os/chdir.c3 @@ -21,7 +21,7 @@ macro void! native_chdir(Path path) @pool() { // TODO improve with better error handling. - if (win32::setCurrentDirectoryW(path.as_str().to_temp_utf16()!!)) return; + if (win32::setCurrentDirectoryW(path.str_view().to_temp_utf16()!!)) return; }; return IoError.GENERAL_ERROR?; $default: diff --git a/lib/std/io/os/ls.c3 b/lib/std/io/os/ls.c3 index c8a8ec716..1cd423bd2 100644 --- a/lib/std/io/os/ls.c3 +++ b/lib/std/io/os/ls.c3 @@ -4,13 +4,13 @@ fn PathList! native_ls(Path dir, bool no_dirs, bool no_symlinks, String mask, Al { PathList list; list.init(.using = using); - DIRPtr directory = posix::opendir(dir.as_str() ? dir.as_zstr() : (ZString)"."); + DIRPtr directory = posix::opendir(dir.str_view() ? dir.as_zstr() : (ZString)"."); defer if (directory) posix::closedir(directory); if (!directory) return (path::is_dir(dir) ? IoError.CANNOT_READ_DIR : IoError.FILE_NOT_DIR)?; Posix_dirent* entry; while ((entry = posix::readdir(directory))) { - String name = ((ZString)&entry.name).as_str(); + String name = ((ZString)&entry.name).str_view(); if (!name || name == "." || name == "..") continue; if (entry.d_type == posix::DT_LNK && no_symlinks) continue; if (entry.d_type == posix::DT_DIR && no_dirs) continue; @@ -29,7 +29,7 @@ fn PathList! native_ls(Path dir, bool no_dirs, bool no_symlinks, String mask, Al @pool(using) { - WString result = dir.as_str().tconcat(`\*`).to_temp_wstring()!!; + WString result = dir.str_view().tconcat(`\*`).to_temp_wstring()!!; Win32_WIN32_FIND_DATAW find_data; Win32_HANDLE find = win32::findFirstFileW(result, &find_data); if (find == win32::INVALID_HANDLE_VALUE) return IoError.CANNOT_READ_DIR?; diff --git a/lib/std/io/os/mkdir.c3 b/lib/std/io/os/mkdir.c3 index 3ac638af5..1a2b4b5f4 100644 --- a/lib/std/io/os/mkdir.c3 +++ b/lib/std/io/os/mkdir.c3 @@ -29,7 +29,7 @@ macro bool! native_mkdir(Path path, MkdirPermissions permissions) @pool() { // TODO security attributes - if (win32::createDirectoryW(path.as_str().to_temp_utf16()!!, null)) return true; + if (win32::createDirectoryW(path.str_view().to_temp_utf16()!!, null)) return true; switch (win32::getLastError()) { case win32::ERROR_ACCESS_DENIED: diff --git a/lib/std/io/os/rmdir.c3 b/lib/std/io/os/rmdir.c3 index ed7648afa..80f8f5dc6 100644 --- a/lib/std/io/os/rmdir.c3 +++ b/lib/std/io/os/rmdir.c3 @@ -26,7 +26,7 @@ macro bool! native_rmdir(Path path) $case env::WIN32: @pool() { - if (win32::removeDirectoryW(path.as_str().to_temp_utf16()!!)) return true; + if (win32::removeDirectoryW(path.str_view().to_temp_utf16()!!)) return true; switch (win32::getLastError()) { case win32::ERROR_ACCESS_DENIED: diff --git a/lib/std/io/os/rmtree.c3 b/lib/std/io/os/rmtree.c3 index 8d62fa4f4..c301b3e0e 100644 --- a/lib/std/io/os/rmtree.c3 +++ b/lib/std/io/os/rmtree.c3 @@ -2,7 +2,7 @@ module std::io::file::os @if(env::POSIX); import libc; /** - * @require dir.as_str() + * @require dir.str_view() **/ fn void! native_rmtree(Path dir) { @@ -14,7 +14,7 @@ fn void! native_rmtree(Path dir) { @pool() { - String name = ((ZString)&entry.name).as_str(); + String name = ((ZString)&entry.name).str_view(); if (!name || name == "." || name == "..") continue; Path new_path = dir.tappend(name)!; if (entry.d_type == posix::DT_DIR) @@ -37,7 +37,7 @@ module std::io::os @if(env::WIN32); fn void! native_rmtree(Path path) { Win32_WIN32_FIND_DATAW find_data; - String s = path.as_str().tconcat("\\*"); + String s = path.str_view().tconcat("\\*"); Win32_HANDLE find = win32::findFirstFileW(s.to_utf16(mem::temp()), &find_data)!; if (find == win32::INVALID_HANDLE_VALUE) return IoError.CANNOT_READ_DIR?; @@ -55,7 +55,7 @@ fn void! native_rmtree(Path path) } else { - win32::deleteFileW(file_path.as_str().to_temp_wstring()!!); + win32::deleteFileW(file_path.str_view().to_temp_wstring()!!); } }; } while (win32::findNextFileW(find, &find_data) != 0); diff --git a/lib/std/io/path.c3 b/lib/std/io/path.c3 index 072912889..beb123f5a 100644 --- a/lib/std/io/path.c3 +++ b/lib/std/io/path.c3 @@ -34,14 +34,14 @@ fn Path! getcwd(Allocator* using = mem::heap()) }; } -fn bool is_dir(Path path) => os::native_is_dir(path.as_str()); -fn bool is_file(Path path) => os::native_is_file(path.as_str()); -fn usz! file_size(Path path) => os::native_file_size(path.as_str()); -fn bool exists(Path path) => os::native_file_or_dir_exists(path.as_str()); +fn bool is_dir(Path path) => os::native_is_dir(path.str_view()); +fn bool is_file(Path path) => os::native_is_file(path.str_view()); +fn usz! file_size(Path path) => os::native_file_size(path.str_view()); +fn bool exists(Path path) => os::native_file_or_dir_exists(path.str_view()); fn Path! tgetcwd() => getcwd(mem::temp()) @inline; fn void! chdir(Path path) => os::native_chdir(path) @inline; fn Path! temp_directory(Allocator* using = mem::heap()) => os::native_temp_directory(using); -fn void! delete(Path path) => os::native_remove(path.as_str()) @inline; +fn void! delete(Path path) => os::native_remove(path.str_view()) @inline; macro bool is_separator(char c, PathEnv path_env = DEFAULT_PATH_ENV) { @@ -168,7 +168,7 @@ fn usz Path.start_of_base_name(self) @local fn bool! Path.is_absolute(self) { - String path_str = self.as_str(); + String path_str = self.str_view(); if (!path_str.len) return false; usz path_start = volume_name_len(path_str, self.env)!; return path_start < path_str.len && is_separator(path_str[path_start], self.env); @@ -176,7 +176,7 @@ fn bool! Path.is_absolute(self) fn Path! Path.absolute(self, Allocator* using = mem::heap()) { - String path_str = self.as_str(); + String path_str = self.str_view(); if (!path_str.len) path_str = "."; if (path_str == ".") { @@ -225,7 +225,7 @@ fn String! Path.extension(self) fn String Path.volume_name(self) { - usz len = volume_name_len(self.as_str(), self.env)!!; + usz len = volume_name_len(self.str_view(), self.env)!!; if (!len) return ""; return self.path_string[:len]; } @@ -387,7 +387,7 @@ fn ZString Path.as_zstr(self) => (ZString)self.path_string.ptr; fn String Path.root_directory(self) { - String path_str = self.as_str(); + String path_str = self.str_view(); usz len = path_str.len; if (!len) return ""; if (self.env == PathEnv.WIN32) @@ -422,8 +422,8 @@ fn bool! Path.walk(self, PathWalker w, void* data) PathList files = ls(abs, .using = using)!; foreach (f : files) { - if (f.as_str() == "." || f.as_str() == "..") continue; - f = abs.append(f.as_str(), using)!; + if (f.str_view() == "." || f.str_view() == "..") continue; + f = abs.append(f.str_view(), using)!; bool is_directory = is_dir(f); if (w(f, is_directory, data)!) return true; if (is_directory && f.walk(w, data)!) return true; @@ -432,7 +432,7 @@ fn bool! Path.walk(self, PathWalker w, void* data) return false; } -fn String Path.as_str(self) @inline +fn String Path.str_view(self) @inline { return self.path_string; } @@ -440,7 +440,7 @@ fn String Path.as_str(self) @inline fn bool Path.has_suffix(self, String str) { - return self.as_str().ends_with(str); + return self.str_view().ends_with(str); } fn void Path.free(self) diff --git a/lib/std/io/stream.c3 b/lib/std/io/stream.c3 index d80fd8e3a..34d293cf6 100644 --- a/lib/std/io/stream.c3 +++ b/lib/std/io/stream.c3 @@ -132,9 +132,9 @@ macro usz! print_gen(self, x) $case String: return self.write(x); $case ZString: - return self.write(x.as_str()); + return self.write(x.str_view()); $case DString: - return self.write(x.as_str()); + return self.write(x.str_view()); $default: $if @convertible(x, String): return self.write((String)x); diff --git a/lib/std/io/stream/buffer.c3 b/lib/std/io/stream/buffer.c3 index f47c8df25..e56d13536 100644 --- a/lib/std/io/stream/buffer.c3 +++ b/lib/std/io/stream/buffer.c3 @@ -27,7 +27,7 @@ const StreamInterface READBUFFER_INTERFACE = { .read_byte_fn = (ReadByteStreamFn)&ReadBuffer.read_byte, }; -fn String ReadBuffer.as_str(&self) @inline +fn String ReadBuffer.str_view(&self) @inline { return (String)self.bytes[self.read_idx:self.write_idx - self.read_idx]; } @@ -90,7 +90,7 @@ const StreamInterface WRITEBUFFER_INTERFACE = { .write_byte_fn = (WriteByteStreamFn)&WriteBuffer.write_byte, }; -fn String WriteBuffer.as_str(&self) @inline +fn String WriteBuffer.str_view(&self) @inline { return (String)self.bytes[:self.index]; } diff --git a/lib/std/io/stream/bytewriter.c3 b/lib/std/io/stream/bytewriter.c3 index 05336be12..d4a53db08 100644 --- a/lib/std/io/stream/bytewriter.c3 +++ b/lib/std/io/stream/bytewriter.c3 @@ -42,7 +42,7 @@ fn void ByteWriter.destroy(&self) *self = { }; } -fn String ByteWriter.as_str(&self) @inline +fn String ByteWriter.str_view(&self) @inline { return (String)self.bytes[:self.index]; } diff --git a/lib/std/os/env.c3 b/lib/std/os/env.c3 index e7a864253..cf63339e0 100644 --- a/lib/std/os/env.c3 +++ b/lib/std/os/env.c3 @@ -14,7 +14,7 @@ fn String! get_var(String name) @pool() { ZString val = libc::getenv(name.zstr_tcopy()); - return val ? val.as_str() : SearchResult.MISSING?; + return val ? val.str_view() : SearchResult.MISSING?; }; $else return ""; diff --git a/lib/std/os/macos/darwin.c3 b/lib/std/os/macos/darwin.c3 index dfff76ff4..3369f94f2 100644 --- a/lib/std/os/macos/darwin.c3 +++ b/lib/std/os/macos/darwin.c3 @@ -88,7 +88,7 @@ fn uptr! load_address() @local { ZString image_name = darwin::_dyld_get_image_name(i); if (!image_name) continue; - if (image_name.as_str() != path) continue; + if (image_name.str_view() != path) continue; return cmd.vmaddr + darwin::_dyld_get_image_vmaddr_slide(i); } return BacktraceFault.IMAGE_NOT_FOUND?; diff --git a/lib/std/os/subprocess.c3 b/lib/std/os/subprocess.c3 index b0fc28bcd..5291a7f47 100644 --- a/lib/std/os/subprocess.c3 +++ b/lib/std/os/subprocess.c3 @@ -113,7 +113,7 @@ fn WString convert_command_line_win32(String[] command_line) @inline @if(env::WI str.append('"'); } str.append('\0'); - return str.as_str().to_temp_wstring()!!; + return str.str_view().to_temp_wstring()!!; } /** @@ -154,7 +154,7 @@ fn SubProcess! create(String[] command_line, SubProcessOptions options = {}, Str env.append("\0"); } env.append("\0"); - used_environment = env.as_str().to_temp_wstring()!; + used_environment = env.str_view().to_temp_wstring()!; } int fd = win32::_open_osfhandle((iptr)wr, 0); if (fd != -1) diff --git a/lib/std/time/time.c3 b/lib/std/time/time.c3 index 676544c62..210b9474c 100644 --- a/lib/std/time/time.c3 +++ b/lib/std/time/time.c3 @@ -160,5 +160,5 @@ fn usz! NanoDuration.to_format(&self, Formatter* formatter) @dynamic str.printf("%ds", sec); } } - return formatter.printf(str.as_str())!; + return formatter.printf(str.str_view())!; } \ No newline at end of file diff --git a/releasenotes.md b/releasenotes.md index cfb859fc8..d22f33a70 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -119,6 +119,7 @@ - `assert` may now take varargs for formatting. ### Stdlib changes +- `.as_str()` replaced by `.str_view()` - Added `math::log(x , base)` and `math::ln(x)`. - Hashmap keys implicitly copied if copy/free are defined. - Socket handling. diff --git a/resources/examples/contextfree/boolerr.c3 b/resources/examples/contextfree/boolerr.c3 index 389f6cd87..286b502a3 100644 --- a/resources/examples/contextfree/boolerr.c3 +++ b/resources/examples/contextfree/boolerr.c3 @@ -21,7 +21,7 @@ struct StringData @private fn void Summary.print(Summary *s, File* out) { - String title = s.title ? s.title.as_str() : "missing"; + String title = s.title ? s.title.str_view() : "missing"; out.printf("Summary({ .title = %s, .ok = %s})", title, s.ok); } @@ -128,7 +128,7 @@ fn void main() io::printf(" Summary: "); summary.print(io::stdout()); io::printn(""); - String title_sure = summary.title ? summary.title.as_str() : ""; + String title_sure = summary.title ? summary.title.str_view() : ""; io::printf(" Title: %s\n", title_sure); bool! has_title = readWhetherTitleNonEmpty(url); // This looks a bit less than elegant, but as you see it's mostly due to having to diff --git a/resources/examples/ls.c3 b/resources/examples/ls.c3 index 4167894f5..7bdc03917 100644 --- a/resources/examples/ls.c3 +++ b/resources/examples/ls.c3 @@ -5,6 +5,6 @@ fn void main() Path path = path::getcwd()!!; foreach (i, p : path::ls(path)!!) { - io::printfn("%02d %s", i, p.as_str()); + io::printfn("%02d %s", i, p.str_view()); } } \ No newline at end of file diff --git a/src/version.h b/src/version.h index 71391b196..94cab21e0 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.660" \ No newline at end of file +#define COMPILER_VERSION "0.4.661" \ No newline at end of file diff --git a/test/test_suite/stdlib/map.c3t b/test/test_suite/stdlib/map.c3t index f00487570..ac3cfef48 100644 --- a/test/test_suite/stdlib/map.c3t +++ b/test/test_suite/stdlib/map.c3t @@ -13,7 +13,7 @@ fn String Foo.to_string(Foo* foo, Allocator* allocator = mem::heap()) @dynamic { DString s = dstring::new_with_capacity(128, allocator); s.printf("{%s, %p}", foo.x, foo.bar); - return s.as_str(); + return s.str_view(); } @@ -74,7 +74,7 @@ entry: store %any %9, ptr %10, align 16 %11 = call i64 @std.core.dstring.DString.printf(ptr %retparam, ptr %s, ptr @.str.14, i64 8, ptr %varargslots, i64 2) %12 = load ptr, ptr %s, align 8 - %13 = call { ptr, i64 } @std.core.dstring.DString.as_str(ptr %12) + %13 = call { ptr, i64 } @std.core.dstring.DString.str_view(ptr %12) store { ptr, i64 } %13, ptr %result, align 8 %14 = load { ptr, i64 }, ptr %result, align 8 ret { ptr, i64 } %14 diff --git a/test/test_suite/switch/switch_in_defer_macro.c3t b/test/test_suite/switch/switch_in_defer_macro.c3t index 49f29e050..4ee9581f0 100644 --- a/test/test_suite/switch/switch_in_defer_macro.c3t +++ b/test/test_suite/switch/switch_in_defer_macro.c3t @@ -294,7 +294,7 @@ fn String! Lexer.parse_string(&self, char quote) @private { self.span = (uint)str.len(); self.column += self.span + 2; - return str.as_str(); + return str.str_view(); } prev = c; continue; @@ -366,7 +366,7 @@ fn void! Lexer.parse_comment(&self, String end) @private } if (end == (String)buf) { - self.string = acc.as_str(); + self.string = acc.str_view(); return; } acc.append_char(buf[0]); @@ -400,11 +400,11 @@ fn String! Lexer.parse_ident(&self) @private if (catch err = c) { case IoError.EOF: - return str.as_str(); + return str.str_view(); default: return err?; } - if (!self.ident(str.len(), c)) return str.as_str(); + if (!self.ident(str.len(), c)) return str.str_view(); str.append_char(c); } } diff --git a/test/unit/stdlib/collections/copy_map.c3 b/test/unit/stdlib/collections/copy_map.c3 index 43658a363..a1fab5b52 100644 --- a/test/unit/stdlib/collections/copy_map.c3 +++ b/test/unit/stdlib/collections/copy_map.c3 @@ -13,12 +13,12 @@ fn void! copy_map() @test x.init(); DString y; y.append("hello"); - x.set(y.as_str(), 123); + x.set(y.str_view(), 123); y.append("bye"); - x.set(y.as_str(), 333); + x.set(y.str_view(), 333); y.clear(); y.append("bye"); - x.set(y.as_str(), 444); + x.set(y.str_view(), 444); assert(x.get("hello")! == 123); assert(x.get("hellobye")! == 333); assert(x.get("bye")! == 444); diff --git a/test/unit/stdlib/io/bufferstream.c3 b/test/unit/stdlib/io/bufferstream.c3 index 70d402beb..43112c179 100644 --- a/test/unit/stdlib/io/bufferstream.c3 +++ b/test/unit/stdlib/io/bufferstream.c3 @@ -32,7 +32,7 @@ fn void! readbuffer() usz n = reader_buf.copy_to(&bw)!; assert(n == DATA.len, "got %d; want %d", n, DATA.len); - String got = bw.as_str(); + String got = bw.str_view(); assert(got == DATA, "got %d; want %d", got, DATA); } @@ -47,7 +47,7 @@ fn void! writebuffer_large() usz n = write_buf.write(DATA)!; assert(n == DATA.len, "large write failed: got %d; want %d", n, DATA.len); - String got = out.as_str(); + String got = out.str_view(); assert(got == DATA, "large write failed: got %d; want %d", got, DATA); } @@ -64,6 +64,6 @@ fn void! writebuffer() usz n = br.copy_to(&write_buf)!; assert(n == DATA.len, "got %d; want %d", n, DATA.len); - String got = out.as_str(); + String got = out.str_view(); assert(got == DATA, "got %d; want %d", got, DATA); } \ No newline at end of file diff --git a/test/unit/stdlib/io/bytestream.c3 b/test/unit/stdlib/io/bytestream.c3 index 13b6a8eac..afd6df36e 100644 --- a/test/unit/stdlib/io/bytestream.c3 +++ b/test/unit/stdlib/io/bytestream.c3 @@ -15,12 +15,12 @@ fn void! bytestream() w.init(); Stream* ws = &w; ws.write("helloworld")!; - assert(w.as_str() == "helloworld"); + assert(w.str_view() == "helloworld"); s.seek(0, SET)!; ws.read_from(s)!; s.seek(1, SET)!; s.write_to(ws)!; - assert(w.as_str() == "helloworldabcbc"); + assert(w.str_view() == "helloworldabcbc"); } fn void! bytewriter_buffer() @@ -31,7 +31,7 @@ fn void! bytewriter_buffer() Stream* s = &writer; s.write("hello")!!; s.write_byte(0)!!; - String o = ((ZString)&z).as_str(); + String o = ((ZString)&z).str_view(); assert(o == "hello"); assert(@catch(s.write("xxxx"))); } @@ -46,7 +46,7 @@ fn void! bytewriter_read_from() bw.tinit(); bw.read_from(s)!; - assert(bw.as_str() == data); + assert(bw.str_view() == data); } module std::io; diff --git a/test/unit/stdlib/io/dstringstream.c3 b/test/unit/stdlib/io/dstringstream.c3 index c83657ac5..73c689767 100644 --- a/test/unit/stdlib/io/dstringstream.c3 +++ b/test/unit/stdlib/io/dstringstream.c3 @@ -11,6 +11,6 @@ fn void! test_writing() ByteReader r; String test_str = "2134"; s.read_from(r.init(test_str))!; - String o = foo.as_str(); + String o = foo.str_view(); assert(o == "hello-what?-------------------------------------------------------2134"); } diff --git a/test/unit/stdlib/io/path.c3 b/test/unit/stdlib/io/path.c3 index 55d1b9111..ff8ad6be6 100644 --- a/test/unit/stdlib/io/path.c3 +++ b/test/unit/stdlib/io/path.c3 @@ -7,14 +7,14 @@ fn void! test_parent() p = path::new("/", .path_env = PathEnv.POSIX)!; assert(@catch(p.parent())); p = path::new("/a/b/c", .path_env = PathEnv.POSIX)!; - assert(p.parent().as_str()! == "/a/b"); + assert(p.parent().str_view()! == "/a/b"); p = path::new("/a/b/c", .path_env = PathEnv.WIN32)!; - assert(p.parent().as_str()! == `\a\b`); + assert(p.parent().str_view()! == `\a\b`); } fn void! test_path_normalized() { - assert(path::new("", .path_env = PathEnv.WIN32).as_str()! == ""); + assert(path::new("", .path_env = PathEnv.WIN32).str_view()! == ""); assert(@catch(path::new("1:\\a\\b\\c.txt", .path_env = PathEnv.WIN32))); assert(@catch(path::new(":", .path_env = PathEnv.WIN32))); assert(@catch(path::new("1:", .path_env = PathEnv.WIN32))); @@ -35,156 +35,156 @@ fn void! test_path_normalized() assert(@catch(path::new(`C:/../a`, .path_env = PathEnv.WIN32))); assert(@catch(path::new(`C:/..`, .path_env = PathEnv.WIN32))); - assert(path::new("/", .path_env = PathEnv.POSIX).as_str()! == "/"); - assert(path::new("/./", .path_env = PathEnv.POSIX).as_str()! == "/"); - assert(path::new("/foo/../", .path_env = PathEnv.POSIX).as_str()! == "/"); - assert(path::new("/foo/bar/../", .path_env = PathEnv.POSIX).as_str()! == "/foo"); - assert(path::new("/foo//bar", .path_env = PathEnv.POSIX).as_str()! == "/foo/bar"); - assert(path::new("/foo//bar/../", .path_env = PathEnv.POSIX).as_str()! == "/foo"); - assert(path::new("/foo/.bar", .path_env = PathEnv.POSIX).as_str()! == "/foo/.bar"); - assert(path::new(`\foo\.bar`, .path_env = PathEnv.WIN32).as_str()! == `\foo\.bar`); - assert(path::new("a\\b/c.txt", .path_env = PathEnv.WIN32).as_str()! == `a\b\c.txt`); - assert(path::new("a\\b/c.txt", .path_env = PathEnv.POSIX).as_str()! == "a\\b/c.txt"); - assert(path::new("C:\\a\\b/c.txt", .path_env = PathEnv.WIN32).as_str()! == `C:\a\b\c.txt`); - assert(path::new("C:\\a\\b/c.txt", .path_env = PathEnv.POSIX).as_str()! == "C:\\a\\b/c.txt"); - assert(path::new(`\\server\a\b/c.txt`, .path_env = PathEnv.WIN32).as_str()! == `\\server\a\b\c.txt`); - assert(path::new(`\\server\a\b/c.txt`, .path_env = PathEnv.POSIX).as_str()! == `\\server\a\b/c.txt`); - assert(path::new(`c:\hello//bar\\\\foo.txt`, .path_env = PathEnv.WIN32).as_str()! == `c:\hello\bar\foo.txt`); - - assert(path::new(`~\a\b/c.txt`, .path_env = PathEnv.WIN32).as_str()! == `~\a\b\c.txt`); - assert(path::new(`~\a\b/c.txt`, .path_env = PathEnv.POSIX).as_str()! == `~\a\b/c.txt`); - - - assert(path::new(`a/b/../../../c`, .path_env = PathEnv.WIN32).as_str()! == `..\c`); - assert(path::new(`a/b/../../../c`, .path_env = PathEnv.POSIX).as_str()! == `../c`); - assert(path::new(`a/b/../../..`, .path_env = PathEnv.WIN32).as_str()! == `..`); - assert(path::new(`a/b/../../..`, .path_env = PathEnv.POSIX).as_str()! == `..`); - assert(path::new(`../a`, .path_env = PathEnv.WIN32).as_str()! == `..\a`); - assert(path::new(`../a`, .path_env = PathEnv.POSIX).as_str()! == `../a`); - assert(path::new(`..`, .path_env = PathEnv.WIN32).as_str()! == `..`); - assert(path::new(`..`, .path_env = PathEnv.POSIX).as_str()! == `..`); - assert(path::new(`a/b/../c`, .path_env = PathEnv.WIN32).as_str()! == `a\c`); - assert(path::new(`a/b/../c`, .path_env = PathEnv.POSIX).as_str()! == `a/c`); - assert(path::new(`a/b/../../c`, .path_env = PathEnv.WIN32).as_str()! == `c`); - assert(path::new(`a/b/../../c`, .path_env = PathEnv.POSIX).as_str()! == `c`); - assert(path::new(`a/b/..`, .path_env = PathEnv.WIN32).as_str()! == `a`); - assert(path::new(`a/b/..`, .path_env = PathEnv.POSIX).as_str()! == `a`); - assert(path::new(`a/b/../`, .path_env = PathEnv.WIN32).as_str()! == `a`); - assert(path::new(`a/b/../`, .path_env = PathEnv.POSIX).as_str()! == `a`); - assert(path::new(`a/b/../..`, .path_env = PathEnv.WIN32).as_str()! == ""); - assert(path::new(`a/b/../..`, .path_env = PathEnv.POSIX).as_str()! == ""); - assert(path::new(`a/b/../../`, .path_env = PathEnv.WIN32).as_str()! == ""); - assert(path::new(`a/b/../../`, .path_env = PathEnv.POSIX).as_str()! == ""); - assert(path::new(`a/b/../c/../d`, .path_env = PathEnv.WIN32).as_str()! == `a\d`); - assert(path::new(`a/b/../c/../d`, .path_env = PathEnv.POSIX).as_str()! == `a/d`); - assert(path::new(`a/b/../c/../d/`, .path_env = PathEnv.WIN32).as_str()! == `a\d`); - assert(path::new(`a/b/../c/../d/`, .path_env = PathEnv.POSIX).as_str()! == `a/d`); - assert(path::new(`a/b//d`, .path_env = PathEnv.WIN32).as_str()! == `a\b\d`); - assert(path::new(`a/b//d`, .path_env = PathEnv.POSIX).as_str()! == `a/b/d`); - assert(path::new(`a/b/././.`, .path_env = PathEnv.WIN32).as_str()! == `a\b`); - assert(path::new(`a/b/././.`, .path_env = PathEnv.POSIX).as_str()! == `a/b`); - assert(path::new(`a/b/./././`, .path_env = PathEnv.WIN32).as_str()! == `a\b`); - assert(path::new(`a/b/./././`, .path_env = PathEnv.POSIX).as_str()! == `a/b`); - assert(path::new(`./a/`, .path_env = PathEnv.WIN32).as_str()! == `a`); - assert(path::new(`./a/`, .path_env = PathEnv.POSIX).as_str()! == `a`); - assert(path::new(`./`, .path_env = PathEnv.WIN32).as_str()! == ``); - assert(path::new(`./`, .path_env = PathEnv.POSIX).as_str()! == ``); - assert(path::new(`.`, .path_env = PathEnv.WIN32).as_str()! == ``); - assert(path::new(`.`, .path_env = PathEnv.POSIX).as_str()! == ``); - assert(path::new(``, .path_env = PathEnv.WIN32).as_str()! == ``); - assert(path::new(``, .path_env = PathEnv.POSIX).as_str()! == ``); - assert(path::new(`/a`, .path_env = PathEnv.WIN32).as_str()! == `\a`); - assert(path::new(`/a`, .path_env = PathEnv.POSIX).as_str()! == `/a`); - assert(path::new(`/a/`, .path_env = PathEnv.WIN32).as_str()! == `\a`); - assert(path::new(`/a/`, .path_env = PathEnv.POSIX).as_str()! == `/a`); - assert(path::new(`/a/b/../c`, .path_env = PathEnv.WIN32).as_str()! == `\a\c`); - assert(path::new(`/a/b/../c`, .path_env = PathEnv.POSIX).as_str()! == `/a/c`); - assert(path::new(`/a/b/../../c`, .path_env = PathEnv.WIN32).as_str()! == `\c`); - assert(path::new(`/a/b/../../c`, .path_env = PathEnv.POSIX).as_str()! == `/c`); - assert(path::new(`/a/b/..`, .path_env = PathEnv.WIN32).as_str()! == `\a`); - assert(path::new(`/a/b/..`, .path_env = PathEnv.POSIX).as_str()! == `/a`); - assert(path::new(`/a/b/../..`, .path_env = PathEnv.WIN32).as_str()! == `\`); - assert(path::new(`/a/b/../..`, .path_env = PathEnv.POSIX).as_str()! == `/`); - assert(path::new(`/a/b/../c/../d`, .path_env = PathEnv.WIN32).as_str()! == `\a\d`); - assert(path::new(`/a/b/../c/../d`, .path_env = PathEnv.POSIX).as_str()! == `/a/d`); - assert(path::new(`/a/b//d`, .path_env = PathEnv.WIN32).as_str()! == `\a\b\d`); - assert(path::new(`/a/b//d`, .path_env = PathEnv.POSIX).as_str()! == `/a/b/d`); - assert(path::new(`/./a/`, .path_env = PathEnv.WIN32).as_str()! == `\a`); - assert(path::new(`/./a/`, .path_env = PathEnv.POSIX).as_str()! == `/a`); - assert(path::new(`/./`, .path_env = PathEnv.WIN32).as_str()! == `\`); - assert(path::new(`/./`, .path_env = PathEnv.POSIX).as_str()! == `/`); - assert(path::new(`/.`, .path_env = PathEnv.WIN32).as_str()! == `\`); - assert(path::new(`/.`, .path_env = PathEnv.POSIX).as_str()! == `/`); - assert(path::new(`/`, .path_env = PathEnv.WIN32).as_str()! == `\`); - assert(path::new(`/`, .path_env = PathEnv.POSIX).as_str()! == `/`); - assert(path::new(`C:/a`, .path_env = PathEnv.WIN32).as_str()! == `C:\a`); - assert(path::new(`C:/a`, .path_env = PathEnv.POSIX).as_str()! == `C:/a`); - assert(path::new(`C:/a/b/../c`, .path_env = PathEnv.WIN32).as_str()! == `C:\a\c`); - assert(path::new(`C:/a/b/../c`, .path_env = PathEnv.POSIX).as_str()! == `C:/a/c`); - assert(path::new(`C:/a/b/../../c`, .path_env = PathEnv.WIN32).as_str()! == `C:\c`); - assert(path::new(`C:/a/b/../../c`, .path_env = PathEnv.POSIX).as_str()! == `C:/c`); - assert(path::new(`C:/a/b/../../../c`, .path_env = PathEnv.POSIX).as_str()! == `c`); - assert(path::new(`C:/a/b/..`, .path_env = PathEnv.WIN32).as_str()! == `C:\a`); - assert(path::new(`C:/a/b/..`, .path_env = PathEnv.POSIX).as_str()! == `C:/a`); - assert(path::new(`C:/a/b/../..`, .path_env = PathEnv.WIN32).as_str()! == `C:\`); - assert(path::new(`C:/a/b/../..`, .path_env = PathEnv.POSIX).as_str()! == `C:`); - assert(path::new(`C:/a/b/../c/../d`, .path_env = PathEnv.WIN32).as_str()! == `C:\a\d`); - assert(path::new(`C:/a/b/../c/../d`, .path_env = PathEnv.POSIX).as_str()! == `C:/a/d`); - assert(path::new(`C:/a/b//d`, .path_env = PathEnv.WIN32).as_str()! == `C:\a\b\d`); - assert(path::new(`C:/a/b//d`, .path_env = PathEnv.POSIX).as_str()! == `C:/a/b/d`); - assert(path::new(`C:/a/b/././.`, .path_env = PathEnv.WIN32).as_str()! == `C:\a\b`); - assert(path::new(`C:/a/b/././.`, .path_env = PathEnv.POSIX).as_str()! == `C:/a/b`); - assert(path::new(`C:/./a`, .path_env = PathEnv.WIN32).as_str()! == `C:\a`); - assert(path::new(`C:/./a`, .path_env = PathEnv.POSIX).as_str()! == `C:/a`); - assert(path::new(`C:/./`, .path_env = PathEnv.WIN32).as_str()! == `C:\`); - assert(path::new(`C:/./`, .path_env = PathEnv.POSIX).as_str()! == `C:`); - assert(path::new(`C:/../a`, .path_env = PathEnv.POSIX).as_str()! == `a`); - assert(path::new(`C:/..`, .path_env = PathEnv.POSIX).as_str()! == ``); - assert(path::new(`C:/`, .path_env = PathEnv.WIN32).as_str()! == `C:\`); - assert(path::new(`C:/`, .path_env = PathEnv.POSIX).as_str()! == `C:`); - assert(path::new(`C:a`, .path_env = PathEnv.WIN32).as_str()! == `C:a`); - assert(path::new(`C:a`, .path_env = PathEnv.POSIX).as_str()! == `C:a`); - assert(path::new(`C:a/`, .path_env = PathEnv.WIN32).as_str()! == `C:a`); - assert(path::new(`C:a/`, .path_env = PathEnv.POSIX).as_str()! == `C:a`); - - assert(path::new(`C:a/b/../c`, .path_env = PathEnv.WIN32).as_str()! == `C:a\c`); - assert(path::new(`C:a/b/../c`, .path_env = PathEnv.POSIX).as_str()! == `C:a/c`); - assert(path::new(`C:a/b/../../c`, .path_env = PathEnv.WIN32).as_str()! == `C:c`); - assert(path::new(`C:a/b/../../c`, .path_env = PathEnv.POSIX).as_str()! == `c`); - assert(path::new(`C:a/b/..`, .path_env = PathEnv.WIN32).as_str()! == `C:a`); - assert(path::new(`C:a/b/..`, .path_env = PathEnv.POSIX).as_str()! == `C:a`); - assert(path::new(`C:a/b/../..`, .path_env = PathEnv.WIN32).as_str()! == `C:`); - assert(path::new(`C:a/b/../..`, .path_env = PathEnv.POSIX).as_str()! == ``); - assert(path::new(`C:a/b/../c/../d`, .path_env = PathEnv.WIN32).as_str()! == `C:a\d`); - assert(path::new(`C:a/b/../c/../d`, .path_env = PathEnv.POSIX).as_str()! == `C:a/d`); - assert(path::new(`C:a/b//d`, .path_env = PathEnv.WIN32).as_str()! == `C:a\b\d`); - assert(path::new(`C:a/b//d`, .path_env = PathEnv.POSIX).as_str()! == `C:a/b/d`); - assert(path::new(`C:a/b/././.`, .path_env = PathEnv.WIN32).as_str()! == `C:a\b`); - assert(path::new(`C:a/b/././.`, .path_env = PathEnv.POSIX).as_str()! == `C:a/b`); - assert(path::new(`C:a/b/../../../c`, .path_env = PathEnv.WIN32).as_str()! == `C:..\c`); - assert(path::new(`C:./a`, .path_env = PathEnv.WIN32).as_str()! == `C:a`); - assert(path::new(`C:./a`, .path_env = PathEnv.POSIX).as_str()! == `C:./a`); - assert(path::new(`C:./`, .path_env = PathEnv.WIN32).as_str()! == `C:`); - assert(path::new(`C:./`, .path_env = PathEnv.POSIX).as_str()! == `C:.`); - assert(path::new(`C:../a`, .path_env = PathEnv.POSIX).as_str()! == `C:../a`); - assert(path::new(`C:../a`, .path_env = PathEnv.WIN32).as_str()! == `C:..\a`); - assert(path::new(`C:..`, .path_env = PathEnv.POSIX).as_str()! == `C:..`); - assert(path::new(`C:..`, .path_env = PathEnv.WIN32).as_str()! == `C:..`); - assert(path::new(`C:`, .path_env = PathEnv.WIN32).as_str()! == `C:`); - assert(path::new(`C:`, .path_env = PathEnv.POSIX).as_str()! == `C:`); - - assert(path::new(`\\server/a`, .path_env = PathEnv.WIN32).as_str()! == `\\server\a`); - assert(path::new(`\\server/a`, .path_env = PathEnv.POSIX).as_str()! == `\\server/a`); - assert(path::new(`\\server\a\b\..\c`, .path_env = PathEnv.WIN32).as_str()! == `\\server\a\c`); - assert(path::new(`\\server\a\b\..\..\c`, .path_env = PathEnv.WIN32).as_str()! == `\\server\c`); - assert(path::new(`\\server\a\b\..`, .path_env = PathEnv.WIN32).as_str()! == `\\server\a`); - assert(path::new(`\\server\a\..`, .path_env = PathEnv.WIN32).as_str()! == `\\server\`); - assert(path::new(`\\server\a\b\..\c\..\d`, .path_env = PathEnv.WIN32).as_str()! == `\\server\a\d`); - assert(path::new(`\\server\a\b\\d`, .path_env = PathEnv.WIN32).as_str()! == `\\server\a\b\d`); - assert(path::new(`\\server\a\b\.\.\.`, .path_env = PathEnv.WIN32).as_str()! == `\\server\a\b`); - assert(path::new(`\\server\.\a`, .path_env = PathEnv.WIN32).as_str()! == `\\server\a`); - assert(path::new(`\\server\.`, .path_env = PathEnv.WIN32).as_str()! == `\\server\`); - assert(path::new(`\\server\`, .path_env = PathEnv.WIN32).as_str()! == `\\server\`); + assert(path::new("/", .path_env = PathEnv.POSIX).str_view()! == "/"); + assert(path::new("/./", .path_env = PathEnv.POSIX).str_view()! == "/"); + assert(path::new("/foo/../", .path_env = PathEnv.POSIX).str_view()! == "/"); + assert(path::new("/foo/bar/../", .path_env = PathEnv.POSIX).str_view()! == "/foo"); + assert(path::new("/foo//bar", .path_env = PathEnv.POSIX).str_view()! == "/foo/bar"); + assert(path::new("/foo//bar/../", .path_env = PathEnv.POSIX).str_view()! == "/foo"); + assert(path::new("/foo/.bar", .path_env = PathEnv.POSIX).str_view()! == "/foo/.bar"); + assert(path::new(`\foo\.bar`, .path_env = PathEnv.WIN32).str_view()! == `\foo\.bar`); + assert(path::new("a\\b/c.txt", .path_env = PathEnv.WIN32).str_view()! == `a\b\c.txt`); + assert(path::new("a\\b/c.txt", .path_env = PathEnv.POSIX).str_view()! == "a\\b/c.txt"); + assert(path::new("C:\\a\\b/c.txt", .path_env = PathEnv.WIN32).str_view()! == `C:\a\b\c.txt`); + assert(path::new("C:\\a\\b/c.txt", .path_env = PathEnv.POSIX).str_view()! == "C:\\a\\b/c.txt"); + assert(path::new(`\\server\a\b/c.txt`, .path_env = PathEnv.WIN32).str_view()! == `\\server\a\b\c.txt`); + assert(path::new(`\\server\a\b/c.txt`, .path_env = PathEnv.POSIX).str_view()! == `\\server\a\b/c.txt`); + assert(path::new(`c:\hello//bar\\\\foo.txt`, .path_env = PathEnv.WIN32).str_view()! == `c:\hello\bar\foo.txt`); + + assert(path::new(`~\a\b/c.txt`, .path_env = PathEnv.WIN32).str_view()! == `~\a\b\c.txt`); + assert(path::new(`~\a\b/c.txt`, .path_env = PathEnv.POSIX).str_view()! == `~\a\b/c.txt`); + + + assert(path::new(`a/b/../../../c`, .path_env = PathEnv.WIN32).str_view()! == `..\c`); + assert(path::new(`a/b/../../../c`, .path_env = PathEnv.POSIX).str_view()! == `../c`); + assert(path::new(`a/b/../../..`, .path_env = PathEnv.WIN32).str_view()! == `..`); + assert(path::new(`a/b/../../..`, .path_env = PathEnv.POSIX).str_view()! == `..`); + assert(path::new(`../a`, .path_env = PathEnv.WIN32).str_view()! == `..\a`); + assert(path::new(`../a`, .path_env = PathEnv.POSIX).str_view()! == `../a`); + assert(path::new(`..`, .path_env = PathEnv.WIN32).str_view()! == `..`); + assert(path::new(`..`, .path_env = PathEnv.POSIX).str_view()! == `..`); + assert(path::new(`a/b/../c`, .path_env = PathEnv.WIN32).str_view()! == `a\c`); + assert(path::new(`a/b/../c`, .path_env = PathEnv.POSIX).str_view()! == `a/c`); + assert(path::new(`a/b/../../c`, .path_env = PathEnv.WIN32).str_view()! == `c`); + assert(path::new(`a/b/../../c`, .path_env = PathEnv.POSIX).str_view()! == `c`); + assert(path::new(`a/b/..`, .path_env = PathEnv.WIN32).str_view()! == `a`); + assert(path::new(`a/b/..`, .path_env = PathEnv.POSIX).str_view()! == `a`); + assert(path::new(`a/b/../`, .path_env = PathEnv.WIN32).str_view()! == `a`); + assert(path::new(`a/b/../`, .path_env = PathEnv.POSIX).str_view()! == `a`); + assert(path::new(`a/b/../..`, .path_env = PathEnv.WIN32).str_view()! == ""); + assert(path::new(`a/b/../..`, .path_env = PathEnv.POSIX).str_view()! == ""); + assert(path::new(`a/b/../../`, .path_env = PathEnv.WIN32).str_view()! == ""); + assert(path::new(`a/b/../../`, .path_env = PathEnv.POSIX).str_view()! == ""); + assert(path::new(`a/b/../c/../d`, .path_env = PathEnv.WIN32).str_view()! == `a\d`); + assert(path::new(`a/b/../c/../d`, .path_env = PathEnv.POSIX).str_view()! == `a/d`); + assert(path::new(`a/b/../c/../d/`, .path_env = PathEnv.WIN32).str_view()! == `a\d`); + assert(path::new(`a/b/../c/../d/`, .path_env = PathEnv.POSIX).str_view()! == `a/d`); + assert(path::new(`a/b//d`, .path_env = PathEnv.WIN32).str_view()! == `a\b\d`); + assert(path::new(`a/b//d`, .path_env = PathEnv.POSIX).str_view()! == `a/b/d`); + assert(path::new(`a/b/././.`, .path_env = PathEnv.WIN32).str_view()! == `a\b`); + assert(path::new(`a/b/././.`, .path_env = PathEnv.POSIX).str_view()! == `a/b`); + assert(path::new(`a/b/./././`, .path_env = PathEnv.WIN32).str_view()! == `a\b`); + assert(path::new(`a/b/./././`, .path_env = PathEnv.POSIX).str_view()! == `a/b`); + assert(path::new(`./a/`, .path_env = PathEnv.WIN32).str_view()! == `a`); + assert(path::new(`./a/`, .path_env = PathEnv.POSIX).str_view()! == `a`); + assert(path::new(`./`, .path_env = PathEnv.WIN32).str_view()! == ``); + assert(path::new(`./`, .path_env = PathEnv.POSIX).str_view()! == ``); + assert(path::new(`.`, .path_env = PathEnv.WIN32).str_view()! == ``); + assert(path::new(`.`, .path_env = PathEnv.POSIX).str_view()! == ``); + assert(path::new(``, .path_env = PathEnv.WIN32).str_view()! == ``); + assert(path::new(``, .path_env = PathEnv.POSIX).str_view()! == ``); + assert(path::new(`/a`, .path_env = PathEnv.WIN32).str_view()! == `\a`); + assert(path::new(`/a`, .path_env = PathEnv.POSIX).str_view()! == `/a`); + assert(path::new(`/a/`, .path_env = PathEnv.WIN32).str_view()! == `\a`); + assert(path::new(`/a/`, .path_env = PathEnv.POSIX).str_view()! == `/a`); + assert(path::new(`/a/b/../c`, .path_env = PathEnv.WIN32).str_view()! == `\a\c`); + assert(path::new(`/a/b/../c`, .path_env = PathEnv.POSIX).str_view()! == `/a/c`); + assert(path::new(`/a/b/../../c`, .path_env = PathEnv.WIN32).str_view()! == `\c`); + assert(path::new(`/a/b/../../c`, .path_env = PathEnv.POSIX).str_view()! == `/c`); + assert(path::new(`/a/b/..`, .path_env = PathEnv.WIN32).str_view()! == `\a`); + assert(path::new(`/a/b/..`, .path_env = PathEnv.POSIX).str_view()! == `/a`); + assert(path::new(`/a/b/../..`, .path_env = PathEnv.WIN32).str_view()! == `\`); + assert(path::new(`/a/b/../..`, .path_env = PathEnv.POSIX).str_view()! == `/`); + assert(path::new(`/a/b/../c/../d`, .path_env = PathEnv.WIN32).str_view()! == `\a\d`); + assert(path::new(`/a/b/../c/../d`, .path_env = PathEnv.POSIX).str_view()! == `/a/d`); + assert(path::new(`/a/b//d`, .path_env = PathEnv.WIN32).str_view()! == `\a\b\d`); + assert(path::new(`/a/b//d`, .path_env = PathEnv.POSIX).str_view()! == `/a/b/d`); + assert(path::new(`/./a/`, .path_env = PathEnv.WIN32).str_view()! == `\a`); + assert(path::new(`/./a/`, .path_env = PathEnv.POSIX).str_view()! == `/a`); + assert(path::new(`/./`, .path_env = PathEnv.WIN32).str_view()! == `\`); + assert(path::new(`/./`, .path_env = PathEnv.POSIX).str_view()! == `/`); + assert(path::new(`/.`, .path_env = PathEnv.WIN32).str_view()! == `\`); + assert(path::new(`/.`, .path_env = PathEnv.POSIX).str_view()! == `/`); + assert(path::new(`/`, .path_env = PathEnv.WIN32).str_view()! == `\`); + assert(path::new(`/`, .path_env = PathEnv.POSIX).str_view()! == `/`); + assert(path::new(`C:/a`, .path_env = PathEnv.WIN32).str_view()! == `C:\a`); + assert(path::new(`C:/a`, .path_env = PathEnv.POSIX).str_view()! == `C:/a`); + assert(path::new(`C:/a/b/../c`, .path_env = PathEnv.WIN32).str_view()! == `C:\a\c`); + assert(path::new(`C:/a/b/../c`, .path_env = PathEnv.POSIX).str_view()! == `C:/a/c`); + assert(path::new(`C:/a/b/../../c`, .path_env = PathEnv.WIN32).str_view()! == `C:\c`); + assert(path::new(`C:/a/b/../../c`, .path_env = PathEnv.POSIX).str_view()! == `C:/c`); + assert(path::new(`C:/a/b/../../../c`, .path_env = PathEnv.POSIX).str_view()! == `c`); + assert(path::new(`C:/a/b/..`, .path_env = PathEnv.WIN32).str_view()! == `C:\a`); + assert(path::new(`C:/a/b/..`, .path_env = PathEnv.POSIX).str_view()! == `C:/a`); + assert(path::new(`C:/a/b/../..`, .path_env = PathEnv.WIN32).str_view()! == `C:\`); + assert(path::new(`C:/a/b/../..`, .path_env = PathEnv.POSIX).str_view()! == `C:`); + assert(path::new(`C:/a/b/../c/../d`, .path_env = PathEnv.WIN32).str_view()! == `C:\a\d`); + assert(path::new(`C:/a/b/../c/../d`, .path_env = PathEnv.POSIX).str_view()! == `C:/a/d`); + assert(path::new(`C:/a/b//d`, .path_env = PathEnv.WIN32).str_view()! == `C:\a\b\d`); + assert(path::new(`C:/a/b//d`, .path_env = PathEnv.POSIX).str_view()! == `C:/a/b/d`); + assert(path::new(`C:/a/b/././.`, .path_env = PathEnv.WIN32).str_view()! == `C:\a\b`); + assert(path::new(`C:/a/b/././.`, .path_env = PathEnv.POSIX).str_view()! == `C:/a/b`); + assert(path::new(`C:/./a`, .path_env = PathEnv.WIN32).str_view()! == `C:\a`); + assert(path::new(`C:/./a`, .path_env = PathEnv.POSIX).str_view()! == `C:/a`); + assert(path::new(`C:/./`, .path_env = PathEnv.WIN32).str_view()! == `C:\`); + assert(path::new(`C:/./`, .path_env = PathEnv.POSIX).str_view()! == `C:`); + assert(path::new(`C:/../a`, .path_env = PathEnv.POSIX).str_view()! == `a`); + assert(path::new(`C:/..`, .path_env = PathEnv.POSIX).str_view()! == ``); + assert(path::new(`C:/`, .path_env = PathEnv.WIN32).str_view()! == `C:\`); + assert(path::new(`C:/`, .path_env = PathEnv.POSIX).str_view()! == `C:`); + assert(path::new(`C:a`, .path_env = PathEnv.WIN32).str_view()! == `C:a`); + assert(path::new(`C:a`, .path_env = PathEnv.POSIX).str_view()! == `C:a`); + assert(path::new(`C:a/`, .path_env = PathEnv.WIN32).str_view()! == `C:a`); + assert(path::new(`C:a/`, .path_env = PathEnv.POSIX).str_view()! == `C:a`); + + assert(path::new(`C:a/b/../c`, .path_env = PathEnv.WIN32).str_view()! == `C:a\c`); + assert(path::new(`C:a/b/../c`, .path_env = PathEnv.POSIX).str_view()! == `C:a/c`); + assert(path::new(`C:a/b/../../c`, .path_env = PathEnv.WIN32).str_view()! == `C:c`); + assert(path::new(`C:a/b/../../c`, .path_env = PathEnv.POSIX).str_view()! == `c`); + assert(path::new(`C:a/b/..`, .path_env = PathEnv.WIN32).str_view()! == `C:a`); + assert(path::new(`C:a/b/..`, .path_env = PathEnv.POSIX).str_view()! == `C:a`); + assert(path::new(`C:a/b/../..`, .path_env = PathEnv.WIN32).str_view()! == `C:`); + assert(path::new(`C:a/b/../..`, .path_env = PathEnv.POSIX).str_view()! == ``); + assert(path::new(`C:a/b/../c/../d`, .path_env = PathEnv.WIN32).str_view()! == `C:a\d`); + assert(path::new(`C:a/b/../c/../d`, .path_env = PathEnv.POSIX).str_view()! == `C:a/d`); + assert(path::new(`C:a/b//d`, .path_env = PathEnv.WIN32).str_view()! == `C:a\b\d`); + assert(path::new(`C:a/b//d`, .path_env = PathEnv.POSIX).str_view()! == `C:a/b/d`); + assert(path::new(`C:a/b/././.`, .path_env = PathEnv.WIN32).str_view()! == `C:a\b`); + assert(path::new(`C:a/b/././.`, .path_env = PathEnv.POSIX).str_view()! == `C:a/b`); + assert(path::new(`C:a/b/../../../c`, .path_env = PathEnv.WIN32).str_view()! == `C:..\c`); + assert(path::new(`C:./a`, .path_env = PathEnv.WIN32).str_view()! == `C:a`); + assert(path::new(`C:./a`, .path_env = PathEnv.POSIX).str_view()! == `C:./a`); + assert(path::new(`C:./`, .path_env = PathEnv.WIN32).str_view()! == `C:`); + assert(path::new(`C:./`, .path_env = PathEnv.POSIX).str_view()! == `C:.`); + assert(path::new(`C:../a`, .path_env = PathEnv.POSIX).str_view()! == `C:../a`); + assert(path::new(`C:../a`, .path_env = PathEnv.WIN32).str_view()! == `C:..\a`); + assert(path::new(`C:..`, .path_env = PathEnv.POSIX).str_view()! == `C:..`); + assert(path::new(`C:..`, .path_env = PathEnv.WIN32).str_view()! == `C:..`); + assert(path::new(`C:`, .path_env = PathEnv.WIN32).str_view()! == `C:`); + assert(path::new(`C:`, .path_env = PathEnv.POSIX).str_view()! == `C:`); + + assert(path::new(`\\server/a`, .path_env = PathEnv.WIN32).str_view()! == `\\server\a`); + assert(path::new(`\\server/a`, .path_env = PathEnv.POSIX).str_view()! == `\\server/a`); + assert(path::new(`\\server\a\b\..\c`, .path_env = PathEnv.WIN32).str_view()! == `\\server\a\c`); + assert(path::new(`\\server\a\b\..\..\c`, .path_env = PathEnv.WIN32).str_view()! == `\\server\c`); + assert(path::new(`\\server\a\b\..`, .path_env = PathEnv.WIN32).str_view()! == `\\server\a`); + assert(path::new(`\\server\a\..`, .path_env = PathEnv.WIN32).str_view()! == `\\server\`); + assert(path::new(`\\server\a\b\..\c\..\d`, .path_env = PathEnv.WIN32).str_view()! == `\\server\a\d`); + assert(path::new(`\\server\a\b\\d`, .path_env = PathEnv.WIN32).str_view()! == `\\server\a\b\d`); + assert(path::new(`\\server\a\b\.\.\.`, .path_env = PathEnv.WIN32).str_view()! == `\\server\a\b`); + assert(path::new(`\\server\.\a`, .path_env = PathEnv.WIN32).str_view()! == `\\server\a`); + assert(path::new(`\\server\.`, .path_env = PathEnv.WIN32).str_view()! == `\\server\`); + assert(path::new(`\\server\`, .path_env = PathEnv.WIN32).str_view()! == `\\server\`); } @@ -305,8 +305,8 @@ fn void! test_path_is_absolute() fn void! test_path_absolute() { - assert(path::new_posix("/").absolute()!.as_str() == "/"); - assert(path::new_posix(".").absolute()!.as_str() == path::getcwd(mem::temp())!!.as_str()); + assert(path::new_posix("/").absolute()!.str_view() == "/"); + assert(path::new_posix(".").absolute()!.str_view() == path::getcwd(mem::temp())!!.str_view()); - assert(path::new_windows(`C:\abs`).absolute()!.as_str() == `C:\abs`); + assert(path::new_windows(`C:\abs`).absolute()!.str_view() == `C:\abs`); } \ No newline at end of file