TinySTL attempt 3. (#342)

* Update TinySTL (attempt 2).

* Fix MSVC compilation issue for TinySTL.

* Fix MSVC warning.

* Favor ptrdiff_t for sizes in string.

* Update genie.lua

* Update math_test.cpp

* Update test.h

* Update test.h

---------

Co-authored-by: Бранимир Караџић <branimirkaradzic@gmail.com>
This commit is contained in:
Martijn Courteaux
2025-02-01 01:14:20 +01:00
committed by GitHub
parent fae06fa431
commit 5fb8c15e15
20 changed files with 1230 additions and 271 deletions

View File

@@ -9,6 +9,7 @@
#include <bx/handlealloc.h>
#include <bx/sort.h>
#include <string>
#include <tinystl/string.h>
bx::AllocatorI* g_allocator;
@@ -637,3 +638,93 @@ TEST_CASE("0terminated", "[string]")
REQUIRE(2 == st.getLength() );
REQUIRE(st.is0Terminated() );
}
TEST(tinystl_string_constructor) {
using tinystl::string;
{
string s;
CHECK( s.size() == 0 );
}
{
string s("hello");
CHECK( s.size() == 5 );
CHECK( 0 == strcmp(s.c_str(), "hello") );
}
{
string s("hello world", 5);
CHECK( s.size() == 5 );
CHECK( 0 == strcmp(s.c_str(), "hello") );
}
{
const string other("hello");
string s = other;
CHECK( s.size() == 5 );
CHECK( 0 == strcmp(s.c_str(), "hello") );
}
{
string other("hello");
string s = std::move(other);
CHECK( s.size() == 5 );
CHECK( 0 == strcmp(s.c_str(), "hello") );
CHECK( other.size() == 0 );
}
}
TEST(tinystl_string_assign) {
using tinystl::string;
{
const string other("hello");
string s("new");
s = other;
CHECK( s.size() == 5 );
CHECK( 0 == strcmp(s.c_str(), "hello") );
}
{
string other("hello");
string s("new");
s = std::move(other);
CHECK( s.size() == 5 );
CHECK( 0 == strcmp(s.c_str(), "hello") );
CHECK( other.size() == 0 );
}
{
const string other("hello longer string here");
string s("short");
s = other;
CHECK( s.size() == 24 );
CHECK( 0 == strcmp(s.c_str(), "hello longer string here") );
}
{
string other("hello longer string here");
string s("short");
s = std::move(other);
CHECK( s.size() == 24 );
CHECK( 0 == strcmp(s.c_str(), "hello longer string here") );
CHECK( other.size() == 0 );
}
{
const string other("short");
string s("hello longer string here");
s = other;
CHECK( s.size() == 5 );
CHECK( 0 == strcmp(s.c_str(), "short") );
}
{
string other("short");
string s("hello longer string here");
s = std::move(other);
CHECK( s.size() == 5 );
CHECK( 0 == strcmp(s.c_str(), "short") );
CHECK( other.size() == 0 );
}
}