Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable std::string tests on all platforms #14

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
Loading