Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions cpp/test/tools/command_e2e_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1815,9 +1815,9 @@ TEST(CliE2E, Utf8JsonKeyCollisionsFailWithoutPublishingOutput) {
args.insert(args.end() - 1, {"--start", "0", "-n", "0"});
}
std::ostringstream out, err;
EXPECT_EQ(tsfile_cli::run_cli(args, out, err), 3) << err.str();
EXPECT_EQ(tsfile_cli::run_cli(args, out, err), 2) << err.str();
EXPECT_TRUE(out.str().empty());
EXPECT_NE(err.str().find("duplicate NDJSON column name"),
EXPECT_NE(err.str().find("duplicate column name"),
std::string::npos);
EXPECT_TRUE(tsfile_cli::is_valid_utf8(err.str()));
}
Expand All @@ -1837,10 +1837,9 @@ TEST(CliE2E, Utf8JsonKeyCollisionsFailWithoutPublishingOutput) {
args.insert(args.end() - 1, "--force");
}
std::ostringstream out, err;
EXPECT_EQ(tsfile_cli::run_cli(args, out, err), 3) << err.str();
EXPECT_EQ(tsfile_cli::run_cli(args, out, err), 2) << err.str();
EXPECT_TRUE(out.str().empty());
EXPECT_NE(err.str().find("duplicate NDJSON column name"),
std::string::npos);
EXPECT_NE(err.str().find("duplicate column name"), std::string::npos);
std::ifstream target(output.c_str(), std::ios::binary);
if (existing) {
ASSERT_TRUE(target.is_open());
Expand Down Expand Up @@ -1897,10 +1896,9 @@ TEST(CliE2E, TableUtf8JsonKeyCollisionsFailInRowsAndStats) {
std::ostringstream out, err;
EXPECT_EQ(tsfile_cli::run_cli(
{command, "-t", table, "-f", "ndjson", path}, out, err),
3);
2);
EXPECT_TRUE(out.str().empty());
EXPECT_NE(err.str().find("duplicate NDJSON column name"),
std::string::npos);
EXPECT_NE(err.str().find("duplicate column name"), std::string::npos);
EXPECT_TRUE(tsfile_cli::is_valid_utf8(err.str()));
}
std::remove(path.c_str());
Expand Down
35 changes: 21 additions & 14 deletions cpp/test/tools/output_format_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,29 +346,36 @@ TEST(RowWriterTest, PreservesNonUtf8BlobBytesAsHex) {
}
}

TEST(RowWriterTest, RejectsJsonKeyCollisionsAfterUtf8Replacement) {
TEST(RowWriterTest, RejectsColumnCollisionsAfterUtf8Replacement) {
const std::vector<std::vector<std::string>> headers = {
{"bad\xff", "bad\xfe"},
{"bad\xff", "bad\xef\xbf\xbd"},
{"same", "same"},
};
for (const auto& header : headers) {
for (bool no_header : {false, true}) {
std::ostringstream out;
RowWriter writer(out, OutputFormat::kJson, header,
{common::INT64, common::INT64}, no_header);
EXPECT_FALSE(writer.write({"42", "7"}, {false, false}));
EXPECT_FALSE(writer.finish());
EXPECT_TRUE(out.str().empty());
for (OutputFormat format : {OutputFormat::kJson, OutputFormat::kCsv,
OutputFormat::kTable, OutputFormat::kTsv}) {
for (bool no_header : {false, true}) {
std::ostringstream out;
RowWriter writer(out, format, header,
{common::INT64, common::INT64}, no_header);
EXPECT_FALSE(writer.write({"42", "7"}, {false, false}));
EXPECT_FALSE(writer.finish());
EXPECT_TRUE(out.str().empty());
}
}
}
}

TEST(RowWriterTest, RejectsJsonKeyCollisionsWithoutRows) {
std::ostringstream out;
RowWriter writer(out, OutputFormat::kJson, {"bad\xff", "bad\xfe"},
{common::STRING, common::STRING}, false);
EXPECT_FALSE(writer.finish());
EXPECT_TRUE(out.str().empty());
TEST(RowWriterTest, RejectsColumnCollisionsWithoutRows) {
for (OutputFormat format : {OutputFormat::kJson, OutputFormat::kCsv,
OutputFormat::kTable, OutputFormat::kTsv}) {
std::ostringstream out;
RowWriter writer(out, format, {"bad\xff", "bad\xfe"},
{common::STRING, common::STRING}, false);
EXPECT_FALSE(writer.finish());
EXPECT_TRUE(out.str().empty());
}
}

TEST(RowWriterTest, CsvEscapesLeadingBackslashesOnlyInTextValues) {
Expand Down
Loading
Loading