mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
try? / catch?
This commit is contained in:
committed by
Christoffer Lerno
parent
1b667cbc93
commit
8b0df0ee11
@@ -158,7 +158,7 @@ fn void! test_pop() @test
|
||||
assert(list.first()? == 23);
|
||||
assert(list.pop()? == 23);
|
||||
assert(list.len() == 0);
|
||||
assert(catch(list.pop()));
|
||||
assert(catch? list.pop());
|
||||
assert(list.len() == 0);
|
||||
list.push(55);
|
||||
assert(list.len() == 1);
|
||||
@@ -173,16 +173,16 @@ fn void! test_remove_first() @test
|
||||
assert(list.len() == 3);
|
||||
assert(list.last()? == 23);
|
||||
assert(list.first()? == -3);
|
||||
assert(try(list.remove_first()));
|
||||
assert(try? list.remove_first());
|
||||
assert(list.len() == 2);
|
||||
assert(list.last()? == 23);
|
||||
assert(list.first()? == 55);
|
||||
assert(try(list.remove_first()));
|
||||
assert(try? list.remove_first());
|
||||
assert(list.last()? == 23);
|
||||
assert(list.first()? == 23);
|
||||
assert(try(list.remove_first()));
|
||||
assert(try? list.remove_first());
|
||||
assert(list.len() == 0);
|
||||
assert(catch(list.pop()));
|
||||
assert(catch? list.pop());
|
||||
assert(list.len() == 0);
|
||||
list.push(55);
|
||||
assert(list.len() == 1);
|
||||
@@ -197,16 +197,16 @@ fn void! test_remove_last() @test
|
||||
assert(list.len() == 3);
|
||||
assert(list.last()? == 23);
|
||||
assert(list.first()? == -3);
|
||||
assert(try(list.remove_last()));
|
||||
assert(try? list.remove_last());
|
||||
assert(list.len() == 2);
|
||||
assert(list.first()? == -3);
|
||||
assert(list.last()? == 55);
|
||||
assert(try(list.remove_last()));
|
||||
assert(try? list.remove_last());
|
||||
assert(list.first()? == -3);
|
||||
assert(list.last()? == -3);
|
||||
assert(try(list.remove_last()));
|
||||
assert(try? list.remove_last());
|
||||
assert(list.len() == 0);
|
||||
assert(catch(list.remove_last()));
|
||||
assert(catch? list.remove_last());
|
||||
assert(list.len() == 0);
|
||||
list.push(55);
|
||||
assert(list.len() == 1);
|
||||
|
||||
@@ -23,7 +23,7 @@ fn void! comparison_helper_8_to_32(String in, Char32 c32)
|
||||
fn void assert_utf8_is_error(String in)
|
||||
{
|
||||
usz len = in.len;
|
||||
assert(catch(conv::utf8_to_char32(in.ptr, &len)), "Expected error");
|
||||
assert(catch? conv::utf8_to_char32(in.ptr, &len), "Expected error");
|
||||
}
|
||||
|
||||
fn void! test_char32_ut8_boundary() @test
|
||||
@@ -33,7 +33,7 @@ fn void! test_char32_ut8_boundary() @test
|
||||
comparison_helper_32_to_8(0x00000080, { 0xc2, 0x80 })?;
|
||||
comparison_helper_32_to_8(0x00000800, { 0xe0, 0xa0, 0x80 })?;
|
||||
comparison_helper_32_to_8(0x00010000, { 0xf0, 0x90, 0x80, 0x80 })?;
|
||||
assert(catch(comparison_helper_32_to_8(0x10ffff + 1, { 0 })), "Expected error");
|
||||
assert(catch? comparison_helper_32_to_8(0x10ffff + 1, { 0 }), "Expected error");
|
||||
// Last seq per len
|
||||
comparison_helper_32_to_8(0x0000007f, { 0x7f })?;
|
||||
comparison_helper_32_to_8(0x000007ff, { 0xdf, 0xbf })?;
|
||||
|
||||
@@ -80,7 +80,7 @@ fn void! test_index_of()
|
||||
String test = "hello world hello";
|
||||
assert(test.index_of("o")? == 4);
|
||||
assert(test.index_of("ll")? == 2);
|
||||
assert(catch(test.index_of("wi")));
|
||||
assert(catch? test.index_of("wi"));
|
||||
}
|
||||
|
||||
fn void! test_rindex_of()
|
||||
@@ -90,5 +90,5 @@ fn void! test_rindex_of()
|
||||
assert(test.rindex_of("ll")? == 14);
|
||||
assert(test.rindex_of("he")? == 12);
|
||||
assert(test.rindex_of("world")? == 6);
|
||||
assert(catch(test.rindex_of("wi")));
|
||||
assert(catch? test.rindex_of("wi"));
|
||||
}
|
||||
@@ -4,9 +4,9 @@ module std::io::path @test;
|
||||
fn void! test_parent()
|
||||
{
|
||||
Path p = path::new("")?;
|
||||
assert(catch(p.parent()));
|
||||
assert(catch? p.parent());
|
||||
p = path::new("/", .path_env = PathEnv.POSIX)?;
|
||||
assert(catch(p.parent()));
|
||||
assert(catch? p.parent());
|
||||
p = path::new("/a/b/c", .path_env = PathEnv.POSIX)?;
|
||||
assert(p.parent().as_str()? == "/a/b");
|
||||
p = path::new("/a/b/c", .path_env = PathEnv.WIN32)?;
|
||||
@@ -16,25 +16,25 @@ fn void! test_parent()
|
||||
fn void! test_path_normalized()
|
||||
{
|
||||
assert(path::new("", .path_env = PathEnv.WIN32).as_str()? == "");
|
||||
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)));
|
||||
assert(catch(path::new("1:a", .path_env = PathEnv.WIN32)));
|
||||
// assert(catch(path::new(`\\\a\b\c.txt`, .path_env = PathEnv.WIN32)));
|
||||
assert(catch(path::new(`\\server\a\b\..\..\..\c`, .path_env = PathEnv.WIN32)));
|
||||
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));
|
||||
assert(catch? path::new("1:a", .path_env = PathEnv.WIN32));
|
||||
// assert(catch? path::new(`\\\a\b\c.txt`, .path_env = PathEnv.WIN32));
|
||||
assert(catch? path::new(`\\server\a\b\..\..\..\c`, .path_env = PathEnv.WIN32));
|
||||
|
||||
assert(catch(path::new(`\\a`, .path_env = PathEnv.WIN32)));
|
||||
assert(catch(path::new(`/a/b/../../../c`, .path_env = PathEnv.WIN32)));
|
||||
assert(catch(path::new(`/a/b/../../../c`, .path_env = PathEnv.POSIX)));
|
||||
assert(catch(path::new(`/a/b/../../..`, .path_env = PathEnv.WIN32)));
|
||||
assert(catch(path::new(`/a/b/../../..`, .path_env = PathEnv.POSIX)));
|
||||
assert(catch(path::new(`/../a`, .path_env = PathEnv.WIN32)));
|
||||
assert(catch(path::new(`/../a`, .path_env = PathEnv.POSIX)));
|
||||
assert(catch(path::new(`/..`, .path_env = PathEnv.WIN32)));
|
||||
assert(catch(path::new(`/..`, .path_env = PathEnv.POSIX)));
|
||||
assert(catch(path::new(`C:/a/b/../../../c`, .path_env = PathEnv.WIN32)));
|
||||
assert(catch(path::new(`C:/../a`, .path_env = PathEnv.WIN32)));
|
||||
assert(catch(path::new(`C:/..`, .path_env = PathEnv.WIN32)));
|
||||
assert(catch? path::new(`\\a`, .path_env = PathEnv.WIN32));
|
||||
assert(catch? path::new(`/a/b/../../../c`, .path_env = PathEnv.WIN32));
|
||||
assert(catch? path::new(`/a/b/../../../c`, .path_env = PathEnv.POSIX));
|
||||
assert(catch? path::new(`/a/b/../../..`, .path_env = PathEnv.WIN32));
|
||||
assert(catch? path::new(`/a/b/../../..`, .path_env = PathEnv.POSIX));
|
||||
assert(catch? path::new(`/../a`, .path_env = PathEnv.WIN32));
|
||||
assert(catch? path::new(`/../a`, .path_env = PathEnv.POSIX));
|
||||
assert(catch? path::new(`/..`, .path_env = PathEnv.WIN32));
|
||||
assert(catch? path::new(`/..`, .path_env = PathEnv.POSIX));
|
||||
assert(catch? path::new(`C:/a/b/../../../c`, .path_env = PathEnv.WIN32));
|
||||
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()? == "/");
|
||||
@@ -189,11 +189,11 @@ fn void! test_path_normalized()
|
||||
|
||||
fn void! test_extension()
|
||||
{
|
||||
assert(catch(path::new(`C:`, .path_env = PathEnv.WIN32).extension()));
|
||||
assert(catch(path::new(`C:`, .path_env = PathEnv.POSIX).extension()));
|
||||
assert(catch(path::new(`file`, .path_env = PathEnv.WIN32).extension()));
|
||||
assert(catch(path::new(`file`, .path_env = PathEnv.POSIX).extension()));
|
||||
assert(catch(path::new(`C:\temp\foo.bar\README`, .path_env = PathEnv.WIN32).extension()));
|
||||
assert(catch? path::new(`C:`, .path_env = PathEnv.WIN32).extension());
|
||||
assert(catch? path::new(`C:`, .path_env = PathEnv.POSIX).extension());
|
||||
assert(catch? path::new(`file`, .path_env = PathEnv.WIN32).extension());
|
||||
assert(catch? path::new(`file`, .path_env = PathEnv.POSIX).extension());
|
||||
assert(catch? path::new(`C:\temp\foo.bar\README`, .path_env = PathEnv.WIN32).extension());
|
||||
|
||||
assert(path::new_windows("file.txt").extension()? == "txt");
|
||||
assert(path::new_posix("file.txt").extension()? == "txt");
|
||||
|
||||
@@ -34,11 +34,11 @@ fn void! test_ipv4_parse()
|
||||
assert(a.ipv4.a == 127 && a.ipv4.b == 0 && a.ipv4.c == 0 && a.ipv4.d == 1);
|
||||
a = net::ipv4_from_str("255.254.253.255")?;
|
||||
assert(a.ipv4.a == 255 && a.ipv4.b == 254 && a.ipv4.c == 253 && a.ipv4.d == 255);
|
||||
assert(catch(net::ipv4_from_str(".1.1.1.1")));
|
||||
assert(catch(net::ipv4_from_str("1..1.1")));
|
||||
assert(catch(net::ipv4_from_str("1..1.1.1")));
|
||||
assert(catch(net::ipv4_from_str("1.1.1.256")));
|
||||
assert(catch(net::ipv4_from_str("256.1.1.1")));
|
||||
assert(catch? net::ipv4_from_str(".1.1.1.1"));
|
||||
assert(catch? net::ipv4_from_str("1..1.1"));
|
||||
assert(catch? net::ipv4_from_str("1..1.1.1"));
|
||||
assert(catch? net::ipv4_from_str("1.1.1.256"));
|
||||
assert(catch? net::ipv4_from_str("256.1.1.1"));
|
||||
}
|
||||
|
||||
fn void test_ipv6()
|
||||
|
||||
Reference in New Issue
Block a user