56 const int block_size = 100;
65 for (
int block_size = 1; block_size < 512; block_size *= 2) {
71 printer.
Print(
"Hello World!");
72 printer.
Print(
" This is the same line.\n");
73 printer.
Print(
"But this is a new one.\nAnd this is another one.");
81 "Hello World! This is the same line.\n"
82 "But this is a new one.\n"
83 "And this is another one.",
91 for (
int block_size = 1; block_size < 512; block_size *= 2) {
97 printer.
WriteRaw(
"Hello World!", 12);
98 printer.
PrintRaw(
" This is the same line.\n");
99 printer.
PrintRaw(
"But this is a new one.\nAnd this is another one.");
108 "Hello World! This is the same line.\n"
109 "But this is a new one.\n"
110 "And this is another one."
120 for (
int block_size = 1; block_size < 512; block_size *= 2) {
125 std::map<std::string, std::string> vars;
127 vars[
"foo"] =
"World";
128 vars[
"bar"] =
"$foo$";
129 vars[
"abcdefg"] =
"1234";
131 printer.
Print(vars,
"Hello $foo$!\nbar = $bar$\n");
133 printer.
Print(vars,
"$abcdefg$\nA literal dollar sign: $$");
135 vars[
"foo"] =
"blah";
136 printer.
Print(vars,
"\nNow foo = $foo$.");
148 "A literal dollar sign: $\n"
161 printer.
Print(
"Hello $foo$!\n",
"foo",
"World");
163 printer.
Print(
"$foo$ $bar$\n",
"foo",
"one",
"bar",
"two");
217 std::map<std::string, std::string> vars;
220 printer.
Print(vars,
"012$foo$4$bar$\n");
221 std::vector<int> path_1;
222 path_1.push_back(33);
223 std::vector<int> path_2;
224 path_2.push_back(11);
225 path_2.push_back(22);
228 printer.
Annotate(
"foo",
"foo", &descriptor_1);
229 printer.
Annotate(
"bar",
"bar", &descriptor_2);
260 printer.
Print(
"012$foo$4$bar$\n",
"foo",
"3",
"bar",
"5");
261 std::vector<int> path_1;
262 path_1.push_back(33);
263 std::vector<int> path_2;
264 path_2.push_back(11);
265 path_2.push_back(22);
268 printer.
Annotate(
"foo",
"foo", &descriptor_1);
269 printer.
Annotate(
"bar",
"bar", &descriptor_2);
300 printer.
Print(
"012$foo$4$bar$\n",
"foo",
"3",
"bar",
"5");
301 std::vector<int>
path;
324 printer.
Print(
"012$foo$4$baz$$bam$$bar$\n",
"foo",
"3",
"bar",
"5",
"baz",
326 std::vector<int>
path;
349 printer.
Print(
"012$foo$4$foo$$bar$\n",
"foo",
"3",
"bar",
"5");
350 std::vector<int>
path;
373 printer.
Print(
"0\n");
375 printer.
Print(
"$foo$",
"foo",
"4");
376 std::vector<int>
path;
380 printer.
Print(
",\n");
381 printer.
Print(
"$bar$",
"bar",
"9");
384 printer.
Annotate(
"bar", &descriptor_two);
385 printer.
Print(
"\n${$$D$$}$\n",
"{",
"",
"}",
"",
"D",
"d");
388 printer.
Annotate(
"{",
"}", &descriptor_three);
423 printer.
Print(
"$A$$N$$B$C\n",
"A",
"",
"N",
"\nz",
"B",
"");
424 std::vector<int>
path;
445 for (
int block_size = 1; block_size < 512; block_size *= 2) {
450 std::map<std::string, std::string> vars;
452 vars[
"newline"] =
"\n";
454 printer.
Print(
"This is not indented.\n");
456 printer.
Print(
"This is indented\nAnd so is this\n");
458 printer.
Print(
"But this is not.");
461 " And this is still the same line.\n"
462 "But this is indented.\n");
463 printer.
PrintRaw(
"RawBit has indent at start\n");
464 printer.
PrintRaw(
"but not after a raw newline\n");
466 "Note that a newline in a variable will break "
467 "indenting, as we see$newline$here.\n");
469 printer.
Print(
"And this");
472 printer.
Print(
" is double-indented\nBack to normal.");
480 "This is not indented.\n"
481 " This is indented\n"
483 "But this is not. And this is still the same line.\n"
484 " But this is indented.\n"
485 " RawBit has indent at start\n"
486 "but not after a raw newline\n"
487 "Note that a newline in a variable will break indenting, as we see\n"
489 " And this is double-indented\n"
496 #ifdef PROTOBUF_HAS_DEATH_TEST
497 TEST(Printer, Death) {
501 Printer printer(&
output,
'$');
503 EXPECT_DEBUG_DEATH(printer.Print(
"$nosuchvar$"),
"Undefined variable");
504 EXPECT_DEBUG_DEATH(printer.Print(
"$unclosed"),
"Unclosed variable name");
505 EXPECT_DEBUG_DEATH(printer.Outdent(),
"without matching Indent");
508 TEST(Printer, AnnotateMultipleUsesDeath) {
512 AnnotationProtoCollector<GeneratedCodeInfo> info_collector(&info);
514 Printer printer(&
output,
'$', &info_collector);
515 printer.Print(
"012$foo$4$foo$\n",
"foo",
"3");
516 std::vector<int>
path;
519 EXPECT_DEBUG_DEATH(printer.Annotate(
"foo",
"foo", &
descriptor),
"multiple");
523 TEST(Printer, AnnotateNegativeLengthDeath) {
527 AnnotationProtoCollector<GeneratedCodeInfo> info_collector(&info);
529 Printer printer(&
output,
'$', &info_collector);
530 printer.Print(
"012$foo$4$bar$\n",
"foo",
"3",
"bar",
"5");
531 std::vector<int>
path;
534 EXPECT_DEBUG_DEATH(printer.Annotate(
"bar",
"foo", &
descriptor),
"negative");
538 TEST(Printer, AnnotateUndefinedDeath) {
542 AnnotationProtoCollector<GeneratedCodeInfo> info_collector(&info);
544 Printer printer(&
output,
'$', &info_collector);
545 printer.Print(
"012$foo$4$foo$\n",
"foo",
"3");
546 std::vector<int>
path;
549 EXPECT_DEBUG_DEATH(printer.Annotate(
"bar",
"bar", &
descriptor),
553 #endif // PROTOBUF_HAS_DEATH_TEST
562 printer.
Print(
"0123456789abcdef");
572 printer.
Print(
"blah");
586 printer.
Print(
"0123456789abcdef");
594 printer.
Print(
"blah");
602 std::vector<std::string>
args{
"arg1",
"arg2"};
603 std::map<std::string, std::string> vars{
604 {
"foo",
"bar"}, {
"baz",
"bla"}, {
"empty",
""}};
672 std::vector<std::string>
args{annotation.SerializeAsString(),
"arg1",
686 #ifdef PROTOBUF_HAS_DEATH_TEST
730 #endif // PROTOBUF_HAS_DEATH_TEST