Fixes initializer_list casting bug in PrettyPrint tests.

This commit is contained in:
2023-05-08 22:40:03 -07:00
parent 49e47090aa
commit 1338002944

View File

@@ -54,7 +54,7 @@ using std::wstring;
TestResults test_EscapeForPrintingWithAConstCharPointer() { TestResults test_EscapeForPrintingWithAConstCharPointer() {
TestResults results; TestResults results;
auto escape_const_char_pointer = [](const char* value) -> string { return EscapeForPrinting(value); }; auto escape_const_char_pointer = [](const char *value) -> string { return EscapeForPrinting(value); };
results += execute_suite(make_test_suite( results += execute_suite(make_test_suite(
"CPPUtils::EscapeForPrinting(const char*)", "CPPUtils::EscapeForPrinting(const char*)",
escape_const_char_pointer, escape_const_char_pointer,
@@ -73,7 +73,7 @@ TestResults test_EscapeForPrintingWithAConstCharPointer() {
TestResults test_EscapeForPrintingWithAString() { TestResults test_EscapeForPrintingWithAString() {
TestResults results; TestResults results;
auto escape_string = [](const string& value) -> string { return EscapeForPrinting(value); }; auto escape_string = [](const string &value) -> string { return EscapeForPrinting(value); };
results += execute_suite(make_test_suite( results += execute_suite(make_test_suite(
"CPPUtils::EscapeForPrinting(const std::string&)", "CPPUtils::EscapeForPrinting(const std::string&)",
escape_string, escape_string,
@@ -91,7 +91,7 @@ TestResults test_EscapeForPrintingWithAString() {
} }
TestResults test_EscapeForPrintingWithAStringView() { TestResults test_EscapeForPrintingWithAStringView() {
auto escape_string_view = [](const string_view& value) -> string { return EscapeForPrinting(value); }; auto escape_string_view = [](const string_view &value) -> string { return EscapeForPrinting(value); };
return execute_suite(make_test_suite( return execute_suite(make_test_suite(
"CPPUtils::EscapeForPrinting(const std::string_view&)", "CPPUtils::EscapeForPrinting(const std::string_view&)",
escape_string_view, escape_string_view,
@@ -108,7 +108,7 @@ TestResults test_EscapeForPrintingWithAStringView() {
} }
TestResults test_PrettyPrintWithAConstCharPointer() { TestResults test_PrettyPrintWithAConstCharPointer() {
auto pretty_print = [](const char* value) -> string { auto pretty_print = [](const char *value) -> string {
ostringstream os; ostringstream os;
PrettyPrint(os, value); PrettyPrint(os, value);
return os.str(); return os.str();
@@ -123,7 +123,7 @@ TestResults test_PrettyPrintWithAConstCharPointer() {
} }
TestResults test_PrettyPrintWithAString() { TestResults test_PrettyPrintWithAString() {
auto pretty_print = [](const string& value) -> string { auto pretty_print = [](const string &value) -> string {
ostringstream os; ostringstream os;
PrettyPrint(os, value); PrettyPrint(os, value);
return os.str(); return os.str();
@@ -138,7 +138,7 @@ TestResults test_PrettyPrintWithAString() {
} }
TestResults test_PrettyPrintWithAStringView() { TestResults test_PrettyPrintWithAStringView() {
auto pretty_print = [](const std::string_view& value) -> string { auto pretty_print = [](const std::string_view &value) -> string {
ostringstream os; ostringstream os;
PrettyPrint(os, value); PrettyPrint(os, value);
return os.str(); return os.str();
@@ -182,12 +182,13 @@ TestResults test_PrettyPrintWithATuple() {
TestResults test_PrettyPrintWithAnInitializerList() { TestResults test_PrettyPrintWithAnInitializerList() {
auto pretty_print = [](int i) { auto pretty_print = [](int i) {
ostringstream os; ostringstream os;
std::initializer_list<string> empty_initializer_list = {};
switch (i) { switch (i) {
case 1: case 1:
PrettyPrint(os, {"one", "two", "three"}); PrettyPrint(os, {"one", "two", "three"});
break; break;
case 2: case 2:
PrettyPrint(os, (std::initializer_list<string>){}); PrettyPrint(os, empty_initializer_list);
break; break;
case 3: case 3:
PrettyPrint(os, {1, 2, 3}); PrettyPrint(os, {1, 2, 3});
@@ -288,7 +289,7 @@ TestResults test_PrettyPrintWithSimpleTypes() {
make_test("should print 3.14 for a float", (string) "3.14", make_tuple(3.14f)), make_test("should print 3.14 for a float", (string) "3.14", make_tuple(3.14f)),
})); }));
auto pretty_print_string = [](const string& value) -> string { auto pretty_print_string = [](const string &value) -> string {
ostringstream os; ostringstream os;
PrettyPrint(os, value); PrettyPrint(os, value);
return os.str(); return os.str();
@@ -332,7 +333,7 @@ TestResults test_PrettyPrintWithAPair() {
} }
TestResults test_PrettyPrintWithSeparatorWithAConstCharPointer() { TestResults test_PrettyPrintWithSeparatorWithAConstCharPointer() {
auto pretty_print = [](const char* separator, int id) -> string { auto pretty_print = [](const char *separator, int id) -> string {
ostringstream os; ostringstream os;
switch (id) { switch (id) {
case 1: case 1:
@@ -362,7 +363,7 @@ TestResults test_PrettyPrintWithSeparatorWithAConstCharPointer() {
} }
TestResults test_PrettyPrintWithSeparatorWithAString() { TestResults test_PrettyPrintWithSeparatorWithAString() {
auto pretty_print = [](const string& separator, int id) -> string { auto pretty_print = [](const string &separator, int id) -> string {
ostringstream os; ostringstream os;
switch (id) { switch (id) {
case 1: case 1:
@@ -392,7 +393,7 @@ TestResults test_PrettyPrintWithSeparatorWithAString() {
} }
TestResults test_PrettyPrintWithSeparatorWithAStringView() { TestResults test_PrettyPrintWithSeparatorWithAStringView() {
auto pretty_print = [](const string_view& separator, int id) -> string { auto pretty_print = [](const string_view &separator, int id) -> string {
ostringstream os; ostringstream os;
switch (id) { switch (id) {
case 1: case 1:
@@ -422,7 +423,7 @@ TestResults test_PrettyPrintWithSeparatorWithAStringView() {
})); }));
} }
int main(int argc, char* argv[]) { int main(int argc, char *argv[]) {
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
TestResults results; TestResults results;