From 4298bcb555aba8d06817c28354c9c76c6f943cf7 Mon Sep 17 00:00:00 2001 From: Emmankoko Date: Fri, 9 Feb 2024 17:06:22 +0100 Subject: [PATCH] Add more tests for std::string on all platforms --- source/stdcpp/test/string.d | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/source/stdcpp/test/string.d b/source/stdcpp/test/string.d index 13c8a9c..70518be 100644 --- a/source/stdcpp/test/string.d +++ b/source/stdcpp/test/string.d @@ -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); }