Add char_at method in DString

This commit is contained in:
neokeld
2024-11-28 10:15:32 +01:00
committed by Christoffer Lerno
parent 44c2486a74
commit a0f4976b07
3 changed files with 47 additions and 3 deletions

View File

@@ -246,4 +246,29 @@ fn void test_insert_at_overlaps()
str.chop(3);
s = str.str_view();
assert(s == "def", "got '%s'; want 'def'", s);
}
}
fn void test_char_at()
{
DString str = dstring::new("hello");
defer str.free();
char c = str.char_at(1);
assert(c == 'e');
char c_with_operator = str[4];
assert(c_with_operator == 'o');
}
fn void test_operators()
{
DString str = dstring::new("hello");
defer str.free();
str[0] = 'p';
assert(str.str_view() == "pello");
char* c = &str[1];
assert(*c == 'e');
}