diff --git a/extras/test.cpp b/extras/test.cpp index 1394590..f680df7 100644 --- a/extras/test.cpp +++ b/extras/test.cpp @@ -8,6 +8,7 @@ *******************************************************************************/ #include +#include #include namespace stdcpp { @@ -16,9 +17,17 @@ namespace stdcpp { std::size_t cppSizeOf() { return sizeof(T); } + + /// Returns the result of `std::string` capacity with the provided string + std::size_t stringCapacity (char const* str) { + std::string s(str); + return s.capacity(); + } }; }; +template std::size_t stdcpp::test::cppSizeOf(); + template class std::list; template std::size_t stdcpp::test::cppSizeOf >(); diff --git a/source/stdcpp/test/string.d b/source/stdcpp/test/string.d index f10ec04..13c8a9c 100644 --- a/source/stdcpp/test/string.d +++ b/source/stdcpp/test/string.d @@ -5,16 +5,23 @@ *******************************************************************************/ module stdcpp.test.string; + +import stdcpp.test.base; import stdcpp.string; -version (CppRuntime_Gcc) + +extern(C++, "stdcpp", "test") size_t stringCapacity (const(char)* str); + +/// Test that the sizes matches +unittest +{ + assert(cppSizeOf!(std_string) == std_string.sizeof); +} + +unittest { - unittest - { - auto a = std_string("hello"); - a.push_back('a'); - assert(a.size() == 6); - assert(std_string.sizeof == 32); - // verifying small string optimization - assert(a.capacity == 15); - } -} \ No newline at end of file + auto a = std_string("hello"); + 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")); +}