{
test_diagnostic_context dc;
rich_location richloc (line_table, UNKNOWN_LOCATION);
- dc.test_show_locus (richloc);
- ASSERT_STREQ ("", pp_formatted_text (dc.m_printer));
+ ASSERT_STREQ ("", dc.test_show_locus (richloc));
}
/* Verify that diagnostic_show_locus works sanely for various
test_diagnostic_context dc;
location_t caret = linemap_position_for_column (line_table, 10);
rich_location richloc (line_table, caret);
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* No column information (column == 0).
test_diagnostic_context dc;
location_t caret = linemap_position_for_column (line_table, 0);
rich_location richloc (line_table, caret);
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Caret and range. */
location_t finish = linemap_position_for_column (line_table, 15);
location_t loc = make_location (caret, start, finish);
rich_location richloc (line_table, loc);
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ~~~^~~~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Multiple ranges and carets. */
rich_location richloc (line_table, foo);
richloc.add_range (bar, SHOW_RANGE_WITH_CARET);
richloc.add_range (field, SHOW_RANGE_WITH_CARET);
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ~A~ ~B~ ~~C~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Insertion fix-it hint: adding an "&" to the front of "bar.field". */
location_t caret = linemap_position_for_column (line_table, 7);
rich_location richloc (line_table, caret);
richloc.add_fixit_insert_before ("&");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^\n"
" &\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Insertion fix-it hint: adding a "[0]" after "foo". */
location_t foo = make_location (start, start, finish);
rich_location richloc (line_table, foo);
richloc.add_fixit_insert_after ("[0]");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~\n"
" [0]\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Removal fix-it hint: removal of the ".field".
/* Normal. */
{
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~~~~\n"
" ------\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Test of adding a prefix. */
test_diagnostic_context dc;
pp_prefixing_rule (dc.m_printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
pp_set_prefix (dc.m_printer, xstrdup ("TEST PREFIX:"));
- dc.test_show_locus (richloc);
ASSERT_STREQ ("TEST PREFIX: foo = bar.field;\n"
"TEST PREFIX: ^~~~~~\n"
"TEST PREFIX: ------\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Normal, with ruler. */
test_diagnostic_context dc;
dc.m_source_printing.show_ruler_p = true;
dc.m_source_printing.max_width = 104;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" 0 0 0 0 0 0 0 0 0 1 \n"
" 1 2 3 4 5 6 7 8 9 0 \n"
" 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234\n"
" foo = bar.field;\n"
" ^~~~~~\n"
" ------\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Test of adding a prefix, with ruler. */
dc.m_source_printing.max_width = 50;
pp_prefixing_rule (dc.m_printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
pp_set_prefix (dc.m_printer, xstrdup ("TEST PREFIX:"));
- dc.test_show_locus (richloc);
ASSERT_STREQ ("TEST PREFIX: 1 2 3 4 5\n"
"TEST PREFIX: 12345678901234567890123456789012345678901234567890\n"
"TEST PREFIX: foo = bar.field;\n"
"TEST PREFIX: ^~~~~~\n"
"TEST PREFIX: ------\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Test of adding a prefix, with ruler and line numbers. */
dc.m_source_printing.show_line_numbers_p = true;
pp_prefixing_rule (dc.m_printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
pp_set_prefix (dc.m_printer, xstrdup ("TEST PREFIX:"));
- dc.test_show_locus (richloc);
ASSERT_STREQ ("TEST PREFIX: | 1 2 3 4 5\n"
"TEST PREFIX: | 12345678901234567890123456789012345678901234567890\n"
"TEST PREFIX: 1 | foo = bar.field;\n"
"TEST PREFIX: | ^~~~~~\n"
"TEST PREFIX: | ------\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
location_t field = make_location (start, start, finish);
rich_location richloc (line_table, field);
richloc.add_fixit_replace ("m_field");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~~~\n"
" m_field\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Replace fix-it hint: replacing "field" with "m_field",
range.m_start = start;
range.m_finish = finish;
richloc.add_fixit_replace (range, "m_field");
- dc.test_show_locus (richloc);
/* The replacement range is not indicated in the annotation line, so
it should be indicated via an additional underline. */
ASSERT_STREQ (" foo = bar.field;\n"
" ^\n"
" -----\n"
" m_field\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Replace fix-it hint: replacing "field" with "m_field",
location_t field = make_location (start, start, finish);
richloc.add_range (field);
richloc.add_fixit_replace (field, "m_field");
- dc.test_show_locus (richloc);
/* The replacement range is indicated in the annotation line,
so it shouldn't be indicated via an additional underline. */
ASSERT_STREQ (" foo = bar.field;\n"
" ^ ~~~~~\n"
" m_field\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Verify that we can use ad-hoc locations when adding fixits to a
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~~~~~~~~ \n"
" test\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Remove. */
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~~~~~~~~ \n"
" -----------------------------------------\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Replace. */
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~~~~~~~~ \n"
" test\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
for (int i = 0; i < 19; i++)
richloc.add_fixit_insert_before ("a");
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^\n"
" aaaaaaaaaaaaaaaaaaa\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Ensure that we can add an arbitrary number of fix-it hints to a
richloc.add_fixit_insert_before (loc, "a");
}
ASSERT_EQ (19, richloc.get_num_fixit_hints ());
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^\n"
" a a a a a a a a a a a a a a a a a a a\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Test of labeling the ranges within a rich_location. */
{
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~ ~~~ ~~~~~\n"
" | | |\n"
" 0 1 2\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Verify that we can disable label-printing. */
{
test_diagnostic_context dc;
dc.m_source_printing.show_labels_p = false;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~ ~~~ ~~~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~ ~~~ ~~~~~\n"
" | | |\n"
" | | label 2\n"
" | label 1\n"
" label 0\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example of boundary conditions: label 0 and 1 have just enough clearance,
richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~ ~~~ ~~~~~\n"
" | | |\n"
" | | c\n"
" aaaaa bbbb\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example of out-of-order ranges (thus requiring a sort). */
richloc.add_range (foo, SHOW_RANGE_WITHOUT_CARET, &label2);
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ~~~ ~~~ ^~~~~\n"
" | | |\n"
" 2 1 0\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Ensure we don't ICE if multiple ranges with labels are on
richloc.add_range (bar, SHOW_RANGE_WITHOUT_CARET, &label2);
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~\n"
" |\n"
" label 0\n"
" label 1\n"
" label 2\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example of out-of-order ranges (thus requiring a sort), where
richloc.add_range (foo, SHOW_RANGE_WITHOUT_CARET, &label_2c);
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ~~~ ~~~ ^~~~~\n"
" | | |\n"
" label 2a\n"
" label 2b\n"
" label 2c\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Verify that a NULL result from range_label::get_text is
gcc_rich_location richloc (bar, &label, nullptr);
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* TODO: example of formatted printing (needs to be in
test_diagnostic_context dc;
location_t caret = linemap_position_for_column (line_table, 18);
rich_location richloc (line_table, caret);
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
"_field\xcf\x80"
";\n"
" ^\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Caret and range. */
location_t finish = linemap_position_for_column (line_table, 30);
location_t loc = make_location (caret, start, finish);
rich_location richloc (line_table, loc);
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
"_field\xcf\x80"
";\n"
" ~~~~~^~~~~~~~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Multiple ranges and carets. */
rich_location richloc (line_table, foo);
richloc.add_range (bar, SHOW_RANGE_WITH_CARET);
richloc.add_range (field, SHOW_RANGE_WITH_CARET);
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
"_field\xcf\x80"
";\n"
" ~~~~A~ ~~~B~ ~~~~~C~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Insertion fix-it hint: adding an "&" to the front of "P_bar.field". */
location_t caret = linemap_position_for_column (line_table, 12);
rich_location richloc (line_table, caret);
richloc.add_fixit_insert_before ("&");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
";\n"
" ^\n"
" &\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Insertion fix-it hint: adding a "[0]" after "SS_foo". */
location_t foo = make_location (start, start, finish);
rich_location richloc (line_table, foo);
richloc.add_fixit_insert_after ("[0]");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
";\n"
" ^~~~~~\n"
" [0]\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Removal fix-it hint: removal of the ".SS_fieldP". */
location_t dot = make_location (start, start, finish);
rich_location richloc (line_table, dot);
richloc.add_fixit_remove ();
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
";\n"
" ^~~~~~~~~~\n"
" ----------\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Replace fix-it hint: replacing "SS_fieldP" with "m_SSfieldP". */
location_t field = make_location (start, start, finish);
rich_location richloc (line_table, field);
richloc.add_fixit_replace ("m_\xf0\x9f\x98\x82_field\xcf\x80");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
" ^~~~~~~~~\n"
" m_\xf0\x9f\x98\x82"
"_field\xcf\x80\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Replace fix-it hint: replacing "SS_fieldP" with "m_SSfieldP",
range.m_start = start;
range.m_finish = finish;
richloc.add_fixit_replace (range, "m_\xf0\x9f\x98\x82_field\xcf\x80");
- dc.test_show_locus (richloc);
/* The replacement range is not indicated in the annotation line, so
it should be indicated via an additional underline. */
ASSERT_STREQ (" \xf0\x9f\x98\x82"
" ---------\n"
" m_\xf0\x9f\x98\x82"
"_field\xcf\x80\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Replace fix-it hint: replacing "SS_fieldP" with "m_SSfieldP",
location_t field = make_location (start, start, finish);
richloc.add_range (field);
richloc.add_fixit_replace (field, "m_\xf0\x9f\x98\x82_field\xcf\x80");
- dc.test_show_locus (richloc);
/* The replacement range is indicated in the annotation line,
so it shouldn't be indicated via an additional underline. */
ASSERT_STREQ (" \xf0\x9f\x98\x82"
" ^ ~~~~~~~~~\n"
" m_\xf0\x9f\x98\x82"
"_field\xcf\x80\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Verify that we can use ad-hoc locations when adding fixits to a
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
";\n"
" ^~~~~~~~~~~~~~~~ \n"
" test\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Remove. */
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
";\n"
" ^~~~~~~~~~~~~~~~ \n"
" -------------------------------------\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Replace. */
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
";\n"
" ^~~~~~~~~~~~~~~~ \n"
" test\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
for (int i = 0; i < 19; i++)
richloc.add_fixit_insert_before (i & 1 ? "@" : "\xcf\x80");
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
" ^\n"
" \xcf\x80@\xcf\x80@\xcf\x80@\xcf\x80@\xcf\x80@"
"\xcf\x80@\xcf\x80@\xcf\x80@\xcf\x80@\xcf\x80\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Ensure that we can add an arbitrary number of fix-it hints to a
}
ASSERT_EQ (nlocs, richloc.get_num_fixit_hints ());
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
" ^\n"
" \xcf\x80 @ \xcf\x80 @ \xcf\x80 @ \xcf\x80 @ \xcf\x80 @"
" \xcf\x80 @ \xcf\x80 @ \xcf\x80 @ \xcf\x80 @ \xcf\x80\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Test of labeling the ranges within a rich_location. */
{
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
" \xf0\x9f\x98\x82\xf0\x9f\x98\x82\xcf\x80"
" \xf0\x9f\x98\x82\xcf\x80\xf0\x9f\x98\x82"
"\xf0\x9f\x98\x82\xcf\x80\xcf\x80\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
-
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
" | | label 2\xcf\x80\n"
" | label 1\xcf\x80\n"
" label 0\xf0\x9f\x98\x82\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example of boundary conditions: label 0 and 1 have just enough clearance,
richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
" | | c\n"
" aaaaa\xf0\x9f\x98\x82\xcf\x80"
" bb\xf0\x9f\x98\x82\xf0\x9f\x98\x82\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example of escaping the source lines. */
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
- dc.test_show_locus (richloc);
ASSERT_STREQ (" <U+1F602>_foo = <U+03C0>_bar.<U+1F602>_field<U+03C0>;\n"
" ^~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~\n"
" | | |\n"
" label 0\xf0\x9f\x98\x82"
/* ... */ " label 1\xcf\x80"
/* ...................*/ " label 2\xcf\x80\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
- dc.test_show_locus (richloc);
ASSERT_STREQ
(" <f0><9f><98><82>_foo = <cf><80>_bar.<f0><9f><98><82>_field<cf><80>;\n"
" ^~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
" label 0\xf0\x9f\x98\x82"
/* ... */ " label 1\xcf\x80"
/* ..........................*/ " label 2\xcf\x80\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
}
diagnostic_color_init (&dc, DIAGNOSTICS_COLOR_YES);
const location_t pi = linemap_position_for_column (line_table, 12);
rich_location richloc (line_table, pi);
- dc.test_show_locus (richloc);
/* In order to avoid having the test depend on exactly how the colorization
was effected, just confirm there are two pi characters in the output. */
- const char *result = pp_formatted_text (dc.m_printer);
+ const char *result = dc.test_show_locus (richloc);
const char *null_term = result + strlen (result);
const char *first_pi = strstr (result, "\xcf\x80");
ASSERT_TRUE (first_pi && first_pi <= null_term - 2);
matching_open_brace_1_18);
ASSERT_TRUE (added);
ASSERT_EQ (2, richloc.get_num_locations ());
- dc.test_show_locus (richloc);
ASSERT_STREQ (" struct same_line { double x; double y; ;\n"
" ~ ^\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Test of add_location_if_nearby on a different line to the
rich_location richloc (line_table, colon);
richloc.add_fixit_insert_before (x, ".");
richloc.add_fixit_replace (colon, "=");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" struct point origin = {x: 0.0,\n"
" ^\n"
" .=\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* The multiline case. The caret for the rich_location is on line 6;
rich_location richloc (line_table, colon);
richloc.add_fixit_insert_before (y, ".");
richloc.add_fixit_replace (colon, "=");
- dc.test_show_locus (richloc);
ASSERT_STREQ ("FILENAME:3:24:\n"
" y\n"
" .\n"
" : 0.0};\n"
" ^\n"
" =\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* As above, but verify the behavior of multiple line spans
richloc.add_fixit_replace (colon, "=");
test_diagnostic_context dc;
dc.m_source_printing.show_line_numbers_p = true;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" 3 | y\n"
" | .\n"
"......\n"
" 6 | : 0.0};\n"
" | ^\n"
" | =\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
richloc.add_fixit_replace (close_paren, "> (");
richloc.add_fixit_insert_after (")");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n"
" ^~~~~~~~~~\n"
" -----------------\n"
" const_cast<foo *> (ptr->field)\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
/* Unit-test the line_corrections machinery. */
char_display_policy policy (make_char_policy (dc, richloc));
richloc.add_fixit_replace (close_paren, ") (");
richloc.add_fixit_insert_after (")");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n"
" ^~~~~~~~~~\n"
" -\n"
" CAST (-\n"
" ) ( )\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example where none are consolidated during printing. */
richloc.add_fixit_replace (close_paren, ") (");
richloc.add_fixit_insert_after (")");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n"
" ^~~~~~~~~~\n"
" -\n"
" CST ( -\n"
" ) ( )\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example of deletion fix-it hints. */
rather than by line_corrections. */
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n"
" ^~~~~~~~~~\n"
" -------\n"
" (bar *)\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example of deletion fix-it hints that would overlap. */
ASSERT_EQ (2, richloc.get_num_fixit_hints ());
/* But the corrections are. */
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n"
" ^~~~~~~~~~\n"
" -----------------\n"
" (longer *)(foo *)\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example of insertion fix-it hints that would overlap. */
/* The first insertion is long enough that if printed naively,
it would overlap with the second.
Verify that they are printed as a single replacement. */
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n"
" ^~~~~~~~~~\n"
" -------\n"
" LONGER THAN THE CAST(foo *)TEST\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
richloc.add_fixit_replace (close_paren, "> (");
richloc.add_fixit_insert_after (")");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" f\xf0\x9f\x98\x82"
" *f = (f\xf0\x9f\x98\x82"
" *)ptr->field\xcf\x80"
" const_cast<f\xf0\x9f\x98\x82"
" *> (ptr->field\xcf\x80"
")\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
/* Unit-test the line_corrections machinery. */
char_display_policy policy (make_char_policy (dc, richloc));
richloc.add_fixit_replace (close_paren, ") (");
richloc.add_fixit_insert_after (")");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" f\xf0\x9f\x98\x82"
" *f = (f\xf0\x9f\x98\x82"
" *)ptr->field\xcf\x80"
" -\n"
" CAST (-\n"
" ) ( )\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example where none are consolidated during printing. */
richloc.add_fixit_replace (close_paren, ") (");
richloc.add_fixit_insert_after (")");
- dc.test_show_locus (richloc);
ASSERT_STREQ (" f\xf0\x9f\x98\x82"
" *f = (f\xf0\x9f\x98\x82"
" *)ptr->field\xcf\x80"
" -\n"
" CST ( -\n"
" ) ( )\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example of deletion fix-it hints. */
rather than by line_corrections. */
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
- dc.test_show_locus (richloc);
ASSERT_STREQ (" f\xf0\x9f\x98\x82"
" *f = (f\xf0\x9f\x98\x82"
" *)ptr->field\xcf\x80"
" -------\n"
" (bar\xf0\x9f\x98\x82"
" *)\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example of deletion fix-it hints that would overlap. */
ASSERT_EQ (2, richloc.get_num_fixit_hints ());
/* But the corrections are. */
- dc.test_show_locus (richloc);
ASSERT_STREQ (" f\xf0\x9f\x98\x82"
" *f = (f\xf0\x9f\x98\x82"
" *)ptr->field\xcf\x80"
" (long\xf0\x9f\x98\x82"
" *)(f\xf0\x9f\x98\x82"
" *)\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Example of insertion fix-it hints that would overlap. */
/* The first insertion is long enough that if printed naively,
it would overlap with the second.
Verify that they are printed as a single replacement. */
- dc.test_show_locus (richloc);
ASSERT_STREQ (" f\xf0\x9f\x98\x82"
" *f = (f\xf0\x9f\x98\x82"
" *)ptr->field\xcf\x80"
" L\xf0\x9f\x98\x82"
"NGER THAN THE CAST(f\xf0\x9f\x98\x82"
" *)TEST\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
ASSERT_EQ (column_range (21, 21), get_printed_columns (fc, policy, hint_1));
/* Verify that they're printed correctly. */
- dc.test_show_locus (richloc);
ASSERT_STREQ (" int a5[][0][0] = { 1, 2 };\n"
" ^\n"
" } {\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Various overlapping insertions, some occurring "out of order"
richloc.add_fixit_insert_before (col_21, "}");
richloc.add_fixit_insert_before (col_1, "{");
richloc.add_fixit_insert_before (col_25, "}");
- dc.test_show_locus (richloc);
+
ASSERT_STREQ (" int a5[][0][0] = { 1, 2 };\n"
" ^\n"
" { -----\n"
" {{1}}}}, {{{2 }}\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
/* Without line numbers. */
{
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" x = a;\n"
"+ break;\n"
" case 'b':\n"
" ^~~~~~~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* With line numbers. */
{
test_diagnostic_context dc;
dc.m_source_printing.show_line_numbers_p = true;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" 2 | x = a;\n"
" +++ |+ break;\n"
" 3 | case 'b':\n"
" | ^~~~~~~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
richloc.add_fixit_insert_before (case_start, "break;\n");
ASSERT_TRUE (richloc.seen_impossible_fixit_p ());
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" case 'b':\n"
" ^~~~~~~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
{
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ ("FILENAME:1:1:\n"
"+#include <stdio.h>\n"
" test (int ch)\n"
"FILENAME:3:2:\n"
" putchar (ch);\n"
" ^~~~~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* With line-numbering, the line spans are close enough to be
{
test_diagnostic_context dc;
dc.m_source_printing.show_line_numbers_p = true;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" +++ |+#include <stdio.h>\n"
" 1 | test (int ch)\n"
" 2 | {\n"
" 3 | putchar (ch);\n"
" | ^~~~~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
return;
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar ();\n"
" ^\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Fix-it hint, attempting to delete a newline.
return;
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar (\n"
" ~^\n"
" );\n"
" ~ \n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
static void
rich_location richloc (line_table,
linemap_position_for_column (line_table,
first_non_ws_byte_col));
- dc.test_show_locus (richloc);
ASSERT_STREQ (" This: ` ' is a tab.\n"
" ^\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Confirm the display width was tracked correctly across the internal tab
rich_location richloc (line_table,
linemap_position_for_column (line_table,
right_quote_byte_col));
- dc.test_show_locus (richloc);
ASSERT_STREQ (" This: ` ' is a tab.\n"
" ^\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
{
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" before \1\2\3\v\x80\xff""after\n"
" ^ ~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
richloc.set_escape_on_output (true);
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
- dc.test_show_locus (richloc);
ASSERT_STREQ
(" before<U+0000><U+0001><U+0002><U+0003><U+000B><80><ff>after\n"
" ^~~~~~~~ ~~~~~~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
- dc.test_show_locus (richloc);
ASSERT_STREQ (" before<00><01><02><03><0b><80><ff>after\n"
" ^~~~ ~~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
{
test_diagnostic_context dc;
- dc.test_show_locus (richloc);
ASSERT_STREQ (" after\n"
" ^\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
richloc.set_escape_on_output (true);
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
- dc.test_show_locus (richloc);
ASSERT_STREQ (" <U+0000>after\n"
" ^~~~~~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
- dc.test_show_locus (richloc);
ASSERT_STREQ (" <00>after\n"
" ^~~~\n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
}
dc.m_source_printing.show_line_numbers_p = true;
dc.m_source_printing.min_margin_width = 0;
gcc_rich_location richloc (loc);
- dc.test_show_locus (richloc);
ASSERT_STREQ (" 9 | this is line 9\n"
" | ~~~~~~\n"
"10 | this is line 10\n"
" | ~~~~~^~~~~~~~~~\n"
"11 | this is line 11\n"
" | ~~~~ \n",
- pp_formatted_text (dc.m_printer));
+ dc.test_show_locus (richloc));
}
/* Run all of the selftests within this file. */