Skip to content

Commit

Permalink
Add more tests for std::string on all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmankoko authored and Geod24 committed Feb 11, 2024
1 parent 180c74a commit 0f6f44e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion source/stdcpp/test/string.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,22 @@ 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);
immutable LongStr = "Hi, this is a test for string capacity growth for a length more than the base SSO";
auto b = std_string(LongStr);
assert(b.capacity == stringCapacity(LongStr.ptr));
a.swap(b); // a and b swaps
assert(a.capacity == stringCapacity(LongStr.ptr));
assert(b.capacity == stringCapacity("hell")); // a was shrinked to hell so b contains 'hell'
b.pop_back();
assert(b.size() == 3);
assert(b[0] == 'h');
assert(b[1] == 'e');
assert(a.empty == 0);
a.clear();
assert(a.empty == 1);
}

0 comments on commit 0f6f44e

Please sign in to comment.