summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bx/tests/string_test.cpp
diff options
context:
space:
mode:
author Miodrag Milanović <mmicko@gmail.com>2023-01-05 15:32:40 +0100
committer GitHub <noreply@github.com>2023-01-05 09:32:40 -0500
commit812e6094f47bb8d1da5a6b421aa4c724cf2035c0 (patch)
tree0f5bab2fe9393d1f629e9bf63e76cecca74ec0c9 /3rdparty/bx/tests/string_test.cpp
parent4a1b41854bba8fc2567906b88bab8ca81e75d187 (diff)
Update BGFX, BX and BIMG (#10789)
* Update to bgfx a93a714632b79b5ddbf5c86ac323fa9b76ed3433 Co-authored-by: Бранимир Караџић <branimirkaradzic@gmail.com>
Diffstat (limited to '3rdparty/bx/tests/string_test.cpp')
-rw-r--r--3rdparty/bx/tests/string_test.cpp65
1 files changed, 58 insertions, 7 deletions
diff --git a/3rdparty/bx/tests/string_test.cpp b/3rdparty/bx/tests/string_test.cpp
index 48ee8d83b9a..cbcb50e8b5a 100644
--- a/3rdparty/bx/tests/string_test.cpp
+++ b/3rdparty/bx/tests/string_test.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2010-2021 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
@@ -16,7 +16,7 @@ TEST_CASE("stringPrintfTy", "")
{
std::string test;
bx::stringPrintf(test, "printf into std::string.");
- REQUIRE(0 == bx::strCmp(bx::StringView(test), "printf into std::string.") );
+ REQUIRE(0 == bx::strCmp(bx::StringView(test.data(), int32_t(test.length() ) ), "printf into std::string.") );
}
TEST_CASE("prettify", "")
@@ -333,6 +333,7 @@ TEST_CASE("toString double", "")
REQUIRE(testToString(-270.000000, "-270.0") );
REQUIRE(testToString(2.225073858507201e-308, "2.225073858507201e-308") );
REQUIRE(testToString(-79.39773355813419, "-79.39773355813419") );
+ REQUIRE(testToString(-1.234567e-9, "-1.234567e-9") );
}
template<typename Ty>
@@ -474,12 +475,26 @@ TEST_CASE("StringView", "")
TEST_CASE("Trim", "")
{
+ REQUIRE(bx::strLTrim("a", "a").isEmpty() );
+ REQUIRE(0 == bx::strCmp(bx::strLTrim("aba", "a"), "ba") );
+
+ REQUIRE(bx::strRTrim("a", "a").isEmpty() );
+ REQUIRE(0 == bx::strCmp(bx::strRTrim("aba", "a"), "ab") );
+
+ REQUIRE(bx::strTrim("a", "a").isEmpty() );
+ REQUIRE(0 == bx::strCmp(bx::strTrim("aba", "a"), "b") );
+
REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "ab"), "vgd") );
- REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "vagbd"), "abvgd") );
+
+ REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "vagbd"), "") );
+ REQUIRE(0 == bx::strCmp(bx::strTrimPrefix("abvgd", "vagbd"), "abvgd") );
+
REQUIRE(0 == bx::strCmp(bx::strLTrim("abvgd", "vgd"), "abvgd") );
REQUIRE(0 == bx::strCmp(bx::strLTrim("/555333/podmac/", "/"), "555333/podmac/") );
- REQUIRE(0 == bx::strCmp(bx::strRTrim("abvgd", "vagbd"), "abvgd") );
+ REQUIRE(0 == bx::strCmp(bx::strRTrim("abvgd", "vagbd"), "") );
+ REQUIRE(0 == bx::strCmp(bx::strTrimSuffix("abvgd", "vagbd"), "abvgd") );
+
REQUIRE(0 == bx::strCmp(bx::strRTrim("abvgd", "abv"), "abvgd") );
REQUIRE(0 == bx::strCmp(bx::strRTrim("/555333/podmac/", "/"), "/555333/podmac") );
@@ -500,6 +515,10 @@ TEST_CASE("TrimSpace", "")
REQUIRE(bx::strRTrimSpace("").isEmpty() );
REQUIRE(bx::strTrimSpace( "").isEmpty() );
+ REQUIRE(bx::strLTrimSpace("\n").isEmpty() );
+ REQUIRE(bx::strRTrimSpace("\n").isEmpty() );
+ REQUIRE(bx::strTrimSpace( "\n").isEmpty() );
+
const bx::StringView t0("1389");
const bx::StringView t1(" 1389");
const bx::StringView t2("1389 ");
@@ -536,16 +555,48 @@ TEST_CASE("strFindBlock", "")
REQUIRE(19 == result.getLength() );
}
-TEST_CASE("hasPrefix", "")
+TEST_CASE("prefix", "")
{
REQUIRE( bx::hasPrefix("abvgd-1389.0", "abv") );
REQUIRE(!bx::hasPrefix("abvgd-1389.0", "bvg") );
REQUIRE( bx::hasPrefix("abvgd-1389.0", "") );
+
+ REQUIRE(0 == bx::strCmp(bx::strTrimPrefix("abvgd-1389.0", "abv"), "gd-1389.0") );
+ REQUIRE(0 == bx::strCmp(bx::strTrimPrefix("abvgd-1389.0", "xyz"), "abvgd-1389.0") );
}
-TEST_CASE("hasSuffix", "")
+TEST_CASE("suffix", "")
{
REQUIRE( bx::hasSuffix("abvgd-1389.0", "389.0") );
REQUIRE(!bx::hasSuffix("abvgd-1389.0", "1389") );
REQUIRE( bx::hasSuffix("abvgd-1389.0", "") );
+
+ REQUIRE(0 == bx::strCmp(bx::strTrimSuffix("abvgd-1389.0", "389.0"), "abvgd-1") );
+ REQUIRE(0 == bx::strCmp(bx::strTrimSuffix("abvgd-1389.0", "xyz"), "abvgd-1389.0") );
+}
+
+TEST_CASE("0terminated", "")
+{
+ const bx::StringView t0("1389");
+ REQUIRE(t0.is0Terminated() );
+ const bx::StringView t1(strTrimPrefix(t0, "13") );
+ REQUIRE(!t1.is0Terminated() );
+ const bx::StringView t2(strTrimSuffix(t0, "89") );
+ REQUIRE(!t2.is0Terminated() );
+
+ bx::DefaultAllocator crt;
+ g_allocator = &crt;
+
+ typedef bx::StringT<&g_allocator> String;
+
+ String st;
+ REQUIRE(st.is0Terminated() );
+
+ st = strTrimPrefix(t0, "13");
+ REQUIRE(2 == st.getLength() );
+ REQUIRE(st.is0Terminated() );
+
+ st = strTrimSuffix(t0, "89");
+ REQUIRE(2 == st.getLength() );
+ REQUIRE(st.is0Terminated() );
}