Add a printer test case for newlines surrounding a sub Emit() call.

PiperOrigin-RevId: 493033566
pull/11132/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 192cd096b1
commit 09cfed19e7
  1. 36
      src/google/protobuf/io/printer_unittest.cc

@ -806,6 +806,42 @@ TEST_F(PrinterTest, EmitCallbacks) {
"};\n");
}
TEST_F(PrinterTest, PreserveNewlinesThroughEmits) {
{
Printer printer(output());
const std::vector<std::string> insertion_lines = {"// line 1", "// line 2"};
printer.Emit(
{
{"insert_lines",
[&] {
for (const auto& line : insertion_lines) {
printer.Emit({{"line", line}}, R"cc(
$line$
)cc");
}
}},
},
R"cc(
// one
// two
$insert_lines$;
// three
// four
)cc");
}
EXPECT_EQ(written(),
"// one\n"
"// two\n"
"\n"
"// line 1\n"
"// line 2\n"
"\n"
"// three\n"
"// four\n");
}
} // namespace io
} // namespace protobuf
} // namespace google

Loading…
Cancel
Save