Branch data Line data Source code
1 : : /* Support for selftests involving diagnostic_show_locus.
2 : : Copyright (C) 1999-2024 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify it under
7 : : the terms of the GNU General Public License as published by the Free
8 : : Software Foundation; either version 3, or (at your option) any later
9 : : version.
10 : :
11 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : : #ifndef GCC_SELFTEST_DIAGNOSTIC_SHOW_LOCUS_H
21 : : #define GCC_SELFTEST_DIAGNOSTIC_SHOW_LOCUS_H
22 : :
23 : : #include "selftest.h"
24 : :
25 : : /* The selftest code should entirely disappear in a production
26 : : configuration, hence we guard all of it with #if CHECKING_P. */
27 : :
28 : : #if CHECKING_P
29 : :
30 : : namespace selftest {
31 : :
32 : : /* RAII class for use in selftests involving diagnostic_show_locus.
33 : :
34 : : Manages creating and cleaning up the following:
35 : : - writing out a temporary .c file containing CONTENT
36 : : - temporarily override the global "line_table" (using CASE_) and
37 : : push a line_map starting at the first line of the temporary file
38 : : - provide a file_cache. */
39 : :
40 : : struct diagnostic_show_locus_fixture
41 : : {
42 : : diagnostic_show_locus_fixture (const line_table_case &case_,
43 : : const char *content);
44 : :
45 : 472 : const char *get_filename () const
46 : : {
47 : 472 : return m_tmp_source_file.get_filename ();
48 : : }
49 : :
50 : : const char *m_content;
51 : : temp_source_file m_tmp_source_file;
52 : : line_table_test m_ltt;
53 : : file_cache m_fc;
54 : : };
55 : :
56 : : /* Fixture for one-liner tests exercising multibyte awareness. For
57 : : simplicity we stick to using two multibyte characters in the test, U+1F602
58 : : == "\xf0\x9f\x98\x82", which uses 4 bytes and 2 display columns, and U+03C0
59 : : == "\xcf\x80", which uses 2 bytes and 1 display column.
60 : :
61 : : This works with the following 1-line source file:
62 : :
63 : : .0000000001111111111222222 display
64 : : .1234567890123456789012345 columns
65 : : "SS_foo = P_bar.SS_fieldP;\n"
66 : : .0000000111111111222222223 byte
67 : : .1356789012456789134567891 columns
68 : :
69 : : Here SS represents the two display columns for the U+1F602 emoji and
70 : : P represents the one display column for the U+03C0 pi symbol. */
71 : :
72 : 192 : struct diagnostic_show_locus_fixture_one_liner_utf8
73 : : : public diagnostic_show_locus_fixture
74 : : {
75 : : diagnostic_show_locus_fixture_one_liner_utf8 (const line_table_case &case_);
76 : : };
77 : :
78 : : } // namespace selftest
79 : :
80 : : #endif /* #if CHECKING_P */
81 : :
82 : : #endif /* GCC_SELFTEST_DIAGNOSTIC_SHOW_LOCUS_H */
|