-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pierre Curto <[email protected]>
- Loading branch information
Showing
2 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module std::core::dstring::tests @test; | ||
|
||
fn void test_insert_at() | ||
{ | ||
DString str = dstring::tnew(" world"); | ||
String s; | ||
|
||
str.insert_at(0, ""); | ||
s = str.str_view(); | ||
assert(s == " world", "got '%s'; want ' world'", s); | ||
|
||
str.insert_at(0, "hello"); | ||
s = str.str_view(); | ||
assert(s == "hello world", "got '%s'; want 'hello world'", s); | ||
|
||
str.insert_at(5, " shiny"); | ||
s = str.str_view(); | ||
assert(s == "hello shiny world", "got '%s'; want 'hello shiny world'", s); | ||
} | ||
|
||
fn void test_insert_at_overlaps() | ||
{ | ||
DString str = dstring::tnew("abc"); | ||
String s; | ||
String v; | ||
|
||
str.insert_at(0, "bc"); | ||
s = str.str_view(); | ||
assert(s == "bcabc", "got '%s'; want 'bcabc'", s); | ||
|
||
// Inserted string is unchanged. | ||
str.chop(0); | ||
str.append("abc"); | ||
v = str.str_view(); | ||
str.insert_at(0, v); | ||
s = str.str_view(); | ||
assert(s == "abc", "got '%s'; want 'abc'", s); | ||
|
||
// Inserted string is part of the tail. | ||
str.chop(0); | ||
str.append("abc"); | ||
v = str.str_view()[1..]; | ||
assert(v == "bc"); | ||
str.insert_at(0, v); | ||
s = str.str_view(); | ||
assert(s == "bcabc", "got '%s'; want 'bcabc'", s); | ||
|
||
// Inserted string is part of the head. | ||
str.chop(0); | ||
str.append("abc"); | ||
v = str.str_view()[1..]; | ||
str.insert_at(2, v); | ||
s = str.str_view(); | ||
assert(s == "abbcc", "got '%s'; want 'abbcc'", s); | ||
} |