Skip to content

Commit

Permalink
Add tab as literal to cudf::test::to_string output (#13993)
Browse files Browse the repository at this point in the history
Adds escaped `\\t` to the `cudf::test::to_string()` output.
Found this while working on #13891 where the output included tabs but was shown as a various number of spaces in the console when using `cudf::test::print()`.
Also added `\\b` for good measure as well as a gtest for all the supported escape sequences.

Authors:
  - David Wendt (https://github.com/davidwendt)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Vukasin Milovanovic (https://github.com/vuule)

URL: #13993
  • Loading branch information
davidwendt authored Aug 30, 2023
1 parent e63f641 commit ed754da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cpp/tests/utilities/column_utilities.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1091,16 +1091,21 @@ struct column_view_printer {
if (col.is_empty()) return;
auto h_data = cudf::test::to_host<std::string>(col);

// explicitly replace '\r' and '\n' characters with "\r" and "\n" strings respectively.
// explicitly replace some special whitespace characters with their literal equivalents
auto cleaned = [](std::string_view in) {
std::string out(in);
auto replace_char = [](std::string& out, char c, std::string_view repl) {
for (std::string::size_type pos{}; out.npos != (pos = out.find(c, pos)); pos++) {
out.replace(pos, 1, repl);
}
};
replace_char(out, '\a', "\\a");
replace_char(out, '\b', "\\b");
replace_char(out, '\f', "\\f");
replace_char(out, '\r', "\\r");
replace_char(out, '\t', "\\t");
replace_char(out, '\n', "\\n");
replace_char(out, '\v', "\\v");
return out;
};

Expand Down
8 changes: 8 additions & 0 deletions cpp/tests/utilities_tests/column_utilities_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ TEST_F(ColumnUtilitiesStringsTest, StringsToString)
EXPECT_EQ(cudf::test::to_string(strings, delimiter), tmp.str());
}

TEST_F(ColumnUtilitiesStringsTest, PrintEscapeStrings)
{
char const* delimiter = ",";
cudf::test::strings_column_wrapper input({"e\te\ne", "é\bé\ré", "e\vé\fé\abell"});
std::string expected{"e\\te\\ne,é\\\\ré,e\\\\\\abell"};
EXPECT_EQ(cudf::test::to_string(input, delimiter), expected);
}

TYPED_TEST(ColumnUtilitiesTestFixedPoint, NonNullableToHost)
{
using namespace numeric;
Expand Down

0 comments on commit ed754da

Please sign in to comment.