Updates tests to work with the latest TinyTest.
Adds StringTraits::Literal variants that work with strings. Names the workspace CPPUtils to match the import name in TinyTest. This resolves the dependency issue.
This commit is contained in:
@@ -43,45 +43,45 @@ using std::ostream;
|
||||
using std::ostringstream;
|
||||
using std::string;
|
||||
using std::string_view;
|
||||
using TinyTest::execute_suite;
|
||||
using TinyTest::make_test;
|
||||
using TinyTest::make_test_suite;
|
||||
using TinyTest::ExecuteSuite;
|
||||
using TinyTest::MakeTest;
|
||||
using TinyTest::MakeTestSuite;
|
||||
using TinyTest::TestResults;
|
||||
} // End namespace
|
||||
} // End namespace
|
||||
|
||||
string filter(const string& text) {
|
||||
string filter(const string &text) {
|
||||
std::regex pattern("\033");
|
||||
return std::regex_replace(text, pattern, "\\033");
|
||||
}
|
||||
|
||||
TestResults test_GetRedComponent() {
|
||||
return execute_suite(make_test_suite(
|
||||
"CPPUtils::GetRedComponent(uint32_t)",
|
||||
CPPUtils::GetRedComponent,
|
||||
{
|
||||
make_test("should get the red component 0x34 from 0x12345678", 0x34U, make_tuple(0x12345678U)),
|
||||
make_test("should get the red component 0x56 from 0x34567890", 0x56U, make_tuple(0x34567890U)),
|
||||
}));
|
||||
return ExecuteSuite(
|
||||
MakeTestSuite("CPPUtils::GetRedComponent(uint32_t)",
|
||||
CPPUtils::GetRedComponent,
|
||||
{
|
||||
MakeTest("should get the red component 0x34 from 0x12345678", 0x34U, make_tuple(0x12345678U)),
|
||||
MakeTest("should get the red component 0x56 from 0x34567890", 0x56U, make_tuple(0x34567890U)),
|
||||
}));
|
||||
}
|
||||
|
||||
TestResults test_GetGreenComponent() {
|
||||
return execute_suite(make_test_suite(
|
||||
"CPPUtils::GetGreenComponent(uint32_t)",
|
||||
CPPUtils::GetGreenComponent,
|
||||
{
|
||||
make_test("should get the green component 0x56 from 0x12345678", 0x56U, make_tuple(0x12345678U)),
|
||||
make_test("should get the green component 0x78 from 0x34567890", 0x78U, make_tuple(0x34567890U)),
|
||||
}));
|
||||
return ExecuteSuite(
|
||||
MakeTestSuite("CPPUtils::GetGreenComponent(uint32_t)",
|
||||
CPPUtils::GetGreenComponent,
|
||||
{
|
||||
MakeTest("should get the green component 0x56 from 0x12345678", 0x56U, make_tuple(0x12345678U)),
|
||||
MakeTest("should get the green component 0x78 from 0x34567890", 0x78U, make_tuple(0x34567890U)),
|
||||
}));
|
||||
}
|
||||
|
||||
TestResults test_GetBlueComponent() {
|
||||
return execute_suite(
|
||||
make_test_suite("CPPUtils::GetBlueComponent(uint32_t)",
|
||||
CPPUtils::GetBlueComponent,
|
||||
{
|
||||
make_test("should get the blue component 0x78 from 0x12345678", 0x78, make_tuple(0x12345678)),
|
||||
make_test("should get the blue component 0x90 from 0x34567890", 0x90, make_tuple(0x34567890)),
|
||||
}));
|
||||
return ExecuteSuite(
|
||||
MakeTestSuite("CPPUtils::GetBlueComponent(uint32_t)",
|
||||
CPPUtils::GetBlueComponent,
|
||||
{
|
||||
MakeTest("should get the blue component 0x78 from 0x12345678", 0x78, make_tuple(0x12345678)),
|
||||
MakeTest("should get the blue component 0x90 from 0x34567890", 0x90, make_tuple(0x34567890)),
|
||||
}));
|
||||
}
|
||||
|
||||
TestResults test_EscapeWithBasicString() {
|
||||
@@ -90,13 +90,13 @@ TestResults test_EscapeWithBasicString() {
|
||||
CPPUtils::Escape(os, text);
|
||||
return os.str();
|
||||
};
|
||||
return execute_suite(make_test_suite(
|
||||
return ExecuteSuite(MakeTestSuite(
|
||||
"CPPUtils::Escape(string)",
|
||||
function_to_test,
|
||||
{
|
||||
make_test("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
||||
make_test("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")),
|
||||
make_test("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
||||
MakeTest("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
||||
MakeTest("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")),
|
||||
MakeTest("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -106,29 +106,29 @@ TestResults test_EscapeWithBasicStringView() {
|
||||
CPPUtils::Escape(os, text);
|
||||
return os.str();
|
||||
};
|
||||
return execute_suite(make_test_suite(
|
||||
return ExecuteSuite(MakeTestSuite(
|
||||
"CPPUtils::Escape(string_view)",
|
||||
function_to_test,
|
||||
{
|
||||
make_test("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
||||
make_test("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")),
|
||||
make_test("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
||||
MakeTest("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
||||
MakeTest("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")),
|
||||
MakeTest("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
||||
}));
|
||||
}
|
||||
|
||||
TestResults test_EscapeWithConstCharStar() {
|
||||
auto function_to_test = [](const char* text) {
|
||||
auto function_to_test = [](const char *text) {
|
||||
ostringstream os;
|
||||
CPPUtils::Escape(os, text);
|
||||
return os.str();
|
||||
};
|
||||
return execute_suite(make_test_suite(
|
||||
return ExecuteSuite(MakeTestSuite(
|
||||
"CPPUtils::Escape(const char*)",
|
||||
function_to_test,
|
||||
{
|
||||
make_test("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
||||
make_test("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")),
|
||||
make_test("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
||||
MakeTest("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
||||
MakeTest("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")),
|
||||
MakeTest("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -138,14 +138,14 @@ TestResults test_ForegroundColor8Bit() {
|
||||
CPPUtils::ForegroundColor8Bit(os, color);
|
||||
return os.str();
|
||||
};
|
||||
return execute_suite(
|
||||
make_test_suite("CPPUtils::ForegroundColor8Bit(uint8_t)",
|
||||
function_to_test,
|
||||
{
|
||||
make_test("should write \"\\033[38;5;7m\"", (string) "\033[38;5;7m", make_tuple(0x07U)),
|
||||
make_test("should write \"\\033[38;5;1m\"", (string) "\033[38;5;1m", make_tuple(0x01U)),
|
||||
make_test("should write \"\\033[38;5;11m\"", (string) "\033[38;5;11m", make_tuple(0x0BU)),
|
||||
}));
|
||||
return ExecuteSuite(
|
||||
MakeTestSuite("CPPUtils::ForegroundColor8Bit(uint8_t)",
|
||||
function_to_test,
|
||||
{
|
||||
MakeTest("should write \"\\033[38;5;7m\"", (string) "\033[38;5;7m", make_tuple(0x07U)),
|
||||
MakeTest("should write \"\\033[38;5;1m\"", (string) "\033[38;5;1m", make_tuple(0x01U)),
|
||||
MakeTest("should write \"\\033[38;5;11m\"", (string) "\033[38;5;11m", make_tuple(0x0BU)),
|
||||
}));
|
||||
}
|
||||
|
||||
TestResults test_BackgroundColor8Bit() {
|
||||
@@ -154,14 +154,14 @@ TestResults test_BackgroundColor8Bit() {
|
||||
CPPUtils::BackgroundColor8Bit(os, color);
|
||||
return os.str();
|
||||
};
|
||||
return execute_suite(
|
||||
make_test_suite("CPPUtils::BackgroundColor8Bit(uint8_t)",
|
||||
function_to_test,
|
||||
{
|
||||
make_test("should write \"\\033[48;5;7m\"", (string) "\033[48;5;7m", make_tuple(0x07U)),
|
||||
make_test("should write \"\\033[48;5;1m\"", (string) "\033[48;5;1m", make_tuple(0x01U)),
|
||||
make_test("should write \"\\033[48;5;11m\"", (string) "\033[48;5;11m", make_tuple(0x0BU)),
|
||||
}));
|
||||
return ExecuteSuite(
|
||||
MakeTestSuite("CPPUtils::BackgroundColor8Bit(uint8_t)",
|
||||
function_to_test,
|
||||
{
|
||||
MakeTest("should write \"\\033[48;5;7m\"", (string) "\033[48;5;7m", make_tuple(0x07U)),
|
||||
MakeTest("should write \"\\033[48;5;1m\"", (string) "\033[48;5;1m", make_tuple(0x01U)),
|
||||
MakeTest("should write \"\\033[48;5;11m\"", (string) "\033[48;5;11m", make_tuple(0x0BU)),
|
||||
}));
|
||||
}
|
||||
|
||||
TestResults test_ForegroundTrueColorWithUInt32() {
|
||||
@@ -170,11 +170,11 @@ TestResults test_ForegroundTrueColorWithUInt32() {
|
||||
CPPUtils::ForegroundTrueColor(os, color);
|
||||
return os.str();
|
||||
};
|
||||
return execute_suite(make_test_suite(
|
||||
return ExecuteSuite(MakeTestSuite(
|
||||
"CPPUtils::ForegroundTrueColor(uint32_t)",
|
||||
function_to_test,
|
||||
{
|
||||
make_test("should write \"\\033[38;2;21;69;136m\"", (string) "\033[38;2;21;69;136m", make_tuple(0x00154588)),
|
||||
MakeTest("should write \"\\033[38;2;21;69;136m\"", (string) "\033[38;2;21;69;136m", make_tuple(0x00154588)),
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -184,11 +184,11 @@ TestResults test_BackgroundTrueColorWithUInt32() {
|
||||
CPPUtils::BackgroundTrueColor(os, color);
|
||||
return os.str();
|
||||
};
|
||||
return execute_suite(make_test_suite(
|
||||
return ExecuteSuite(MakeTestSuite(
|
||||
"CPPUtils::BackgroundTrueColor(uint32_t)",
|
||||
function_to_test,
|
||||
{
|
||||
make_test("should write \"\\033[48;2;21;69;136m\"", (string) "\033[48;2;21;69;136m", make_tuple(0x00154588)),
|
||||
MakeTest("should write \"\\033[48;2;21;69;136m\"", (string) "\033[48;2;21;69;136m", make_tuple(0x00154588)),
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -198,13 +198,13 @@ TestResults test_ForegroundTrueColorWith3UInt8() {
|
||||
CPPUtils::ForegroundTrueColor(os, red, green, blue);
|
||||
return os.str();
|
||||
};
|
||||
return execute_suite(make_test_suite(
|
||||
"CPPUtils::ForegroundTrueColor(uint8_t, uint8_t, uint8_t)",
|
||||
function_to_test,
|
||||
{
|
||||
make_test(
|
||||
"should write \"\\033[38;2;21;69;136m\"", (string) "\033[38;2;21;69;136m", make_tuple(0x15, 0x45, 0x88)),
|
||||
}));
|
||||
return ExecuteSuite(MakeTestSuite("CPPUtils::ForegroundTrueColor(uint8_t, uint8_t, uint8_t)",
|
||||
function_to_test,
|
||||
{
|
||||
MakeTest("should write \"\\033[38;2;21;69;136m\"",
|
||||
(string) "\033[38;2;21;69;136m",
|
||||
make_tuple(0x15, 0x45, 0x88)),
|
||||
}));
|
||||
}
|
||||
|
||||
TestResults test_BackgroundTrueColorWith3UInt8() {
|
||||
@@ -213,13 +213,13 @@ TestResults test_BackgroundTrueColorWith3UInt8() {
|
||||
CPPUtils::BackgroundTrueColor(os, red, green, blue);
|
||||
return os.str();
|
||||
};
|
||||
return execute_suite(make_test_suite(
|
||||
"CPPUtils::BackgroundTrueColor(uint8_t, uint8_t, uint8_t)",
|
||||
function_to_test,
|
||||
{
|
||||
make_test(
|
||||
"should write \"\\033[48;2;21;69;136m\"", (string) "\033[48;2;21;69;136m", make_tuple(0x15, 0x45, 0x88)),
|
||||
}));
|
||||
return ExecuteSuite(MakeTestSuite("CPPUtils::BackgroundTrueColor(uint8_t, uint8_t, uint8_t)",
|
||||
function_to_test,
|
||||
{
|
||||
MakeTest("should write \"\\033[48;2;21;69;136m\"",
|
||||
(string) "\033[48;2;21;69;136m",
|
||||
make_tuple(0x15, 0x45, 0x88)),
|
||||
}));
|
||||
}
|
||||
|
||||
TestResults test_Reset() {
|
||||
@@ -228,14 +228,14 @@ TestResults test_Reset() {
|
||||
CPPUtils::Reset(os);
|
||||
return os.str();
|
||||
};
|
||||
return execute_suite(make_test_suite("CPPUtils::Reset",
|
||||
function_to_test,
|
||||
{
|
||||
make_test("should write \"\\033[m\"", (string) "\033[m", make_tuple()),
|
||||
}));
|
||||
return ExecuteSuite(MakeTestSuite("CPPUtils::Reset",
|
||||
function_to_test,
|
||||
{
|
||||
MakeTest("should write \"\\033[m\"", (string) "\033[m", make_tuple()),
|
||||
}));
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int main(int argc, char *argv[]) {
|
||||
TestResults results;
|
||||
|
||||
results += test_GetRedComponent();
|
||||
@@ -252,5 +252,5 @@ int main(int argc, char* argv[]) {
|
||||
results += test_BackgroundTrueColorWith3UInt8();
|
||||
results += test_Reset();
|
||||
|
||||
return results.failed() + results.errors();
|
||||
return results.Failed() + results.Errors();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user