Skip to content

Commit

Permalink
Enable std::string tests on all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Geod24 committed Feb 11, 2024
1 parent 1f423eb commit 7533094
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
9 changes: 9 additions & 0 deletions extras/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*******************************************************************************/

#include <list>
#include <string>
#include <vector>

namespace stdcpp {
Expand All @@ -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<std::string>();

template class std::list<int>;
template std::size_t stdcpp::test::cppSizeOf<std::list<int> >();

Expand Down
29 changes: 18 additions & 11 deletions source/stdcpp/test/string.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
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"));
}

0 comments on commit 7533094

Please sign in to comment.