Add String.trim_left() / right() (#1773)

* Add String.trim_left() / right()

* Fix formatting
This commit is contained in:
Louis Brauer
2025-01-05 21:53:18 +01:00
committed by GitHub
parent f1ef2e8138
commit 35812bd7ba
3 changed files with 55 additions and 4 deletions

View File

@@ -59,6 +59,7 @@ fn void test_ends_with()
assert(s.ends_with(""));
assert(!s.ends_with("e"));
}
fn void test_trim()
{
String s = " \t\nabc ";
@@ -67,6 +68,29 @@ fn void test_trim()
assert(" \n\tok".trim() == "ok");
assert("!! \n\t ".trim() == "!!");
assert(s.trim("c \t") == "\nab");
assert("".trim() == "");
}
fn void test_trim_left()
{
String s = " \t\nabc ";
assert(s.trim_left() == "abc ");
assert("\n\t".trim_left() == "");
assert(" \n\tok".trim_left() == "ok");
assert("!! \n\t ".trim_left() == "!! \n\t ");
assert("".trim_left() == "");
}
fn void test_trim_right()
{
String s = " \t\nabc ";
assert(s.trim_right() == " \t\nabc");
assert("\n\t".trim_right() == "");
assert(" \n\tok".trim_right() == " \n\tok");
assert("!! \n\t ".trim_right() == "!!");
assert("".trim_right() == "");
}
fn void test_split()
@@ -175,4 +199,4 @@ fn void! test_hex_conversion()
{
assert("0x123aCd".to_long()! == 0x123acd);
assert("123acD".to_long(16)! == 0x123acd);
}
}