Skip to content

Commit

Permalink
ADDING MORE TEST FOR std::string ON ALL PLATFORMS
Browse files Browse the repository at this point in the history
  • Loading branch information
Geod24 authored and Emmanuel Nyarko committed Feb 11, 2024
1 parent 180c74a commit 00d78a1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion source/stdcpp/test/string.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,20 @@ unittest
a.push_back('a');
assert(a.size() == 6);
// verifying small string optimization, this is 15 on GCC, 22-23 on clang
assert(a.capacity == stringCapacity("hello"));
assert(a.capacity == stringCapacity("helloa"));
assert(a.front() == 'h');
assert(a.back() == 'a');
a.resize(4); // shrinks a to "hell"
assert(a.size() == 4);
auto b = std_string("Hi, this is a test for string capacity growth for a length more than the base SSO");
assert(b.capacity == stringCapacity("Hi, this is a test for string capacity growth for a length more than the base SSO"));
a.swap(b); // a and b swaps
assert(a.capacity == stringCapacity("Hi, this is a test for string capacity growth for a length more than the base SSO"));
assert(b.capacity == stringCapacity("hell")); // a was shrinked to hell so b contains 'hell'
b.pop_back();
assert(b.size() == 3);
assert(a.empty == 0);
a.clear();
assert(a.empty == 1);

}

0 comments on commit 00d78a1

Please sign in to comment.