1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <string>
#include "Test.h"
#include "Util.h"
#include "Util2.h"
TEST_CASE("join_to_string", "[Util]")
{
auto ch = '!';
auto str = pymol::join_to_string("Hello ", 42, ch);
REQUIRE(str == "Hello 42!");
}
TEST_CASE("string_format", "[Util]")
{
auto str = pymol::string_format("%s %d!", "Hello", 42);
REQUIRE(str == "Hello 42!");
auto str2 = pymol::string_format("%s %d!", std::string("Hello"), 42);
REQUIRE(str2 == "Hello 42!");
#if 0
// We have a static assert which won't allow empty string. Allowing empty
// string would produce a compiler warning with clang.
auto str3 = pymol::string_format("");
REQUIRE(str3 == "");
#endif
auto str4 = pymol::string_format("%s %d!", "ThisStringWillNotBeSmallStringOptimized", 42);
REQUIRE(str4 == "ThisStringWillNotBeSmallStringOptimized 42!");
}
TEST_CASE("CleanStr", "[Util]")
{
char str[256];
strcpy(str, "Hello");
UtilCleanStr(str);
REQUIRE(strcmp(str, "Hello") == 0);
char str2[256];
strcpy(str2, " Hello ");
UtilCleanStr(str2);
REQUIRE(strcmp(str2, "Hello") == 0);
char str3[256];
strcpy(str3, " Hello 42 ");
UtilCleanStr(str3);
REQUIRE(strcmp(str3, "Hello 42") == 0);
}
TEST_CASE("CleanStdStr", "[Util]")
{
std::string str = "Hello";
str = UtilCleanStdStr(str);
REQUIRE(str == "Hello");
std::string str2 = " Hello ";
str2 = UtilCleanStdStr(str2);
REQUIRE(str2 == "Hello");
std::string str3 = " Hello 42 ";
str3 = UtilCleanStdStr(str3);
REQUIRE(str3 == "Hello 42");
}
TEST_CASE("StartsWith", "[Util]")
{
char str[256];
strcpy(str, "_Hello");
REQUIRE(pymol::starts_with(str, "_H"));
std::string str2 = "_Jello";
REQUIRE(pymol::starts_with(str2, "_J"));
std::string str3 = "_Fello";
REQUIRE(!pymol::starts_with(str2, "F"));
}
|