Skip to content

Commit 44522b9

Browse files
committed
improved test coverage of simplecpp::Macro::expandHashHash()
1 parent 3b3b30e commit 44522b9

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,16 @@ static void hashhash_empty_va_args()
18751875
ASSERT_EQUALS("\n\n\n( 2 )", preprocess(code));
18761876
}
18771877

1878+
static void hashhash_va_args_unexpected()
1879+
{
1880+
const char code[] =
1881+
"#define C(...)!##__VA_ARGS__\n"
1882+
"C(1)";
1883+
simplecpp::OutputList outputList;
1884+
preprocess(code, simplecpp::DUI(), &outputList);
1885+
ASSERT_EQUALS("file0,1,syntax_error,failed to expand 'C', Invalid ## usage when expanding 'C': Unexpected token '!'\n", toString(outputList));
1886+
}
1887+
18781888
static void hashhash_universal_character()
18791889
{
18801890
const char code[] =
@@ -1884,6 +1894,16 @@ static void hashhash_universal_character()
18841894
ASSERT_EQUALS("file0,1,syntax_error,failed to expand 'A', Invalid ## usage when expanding 'A': Combining '\\u01' and '04' yields universal character '\\u0104'. This is undefined behavior according to C standard chapter 5.1.1.2, paragraph 4.\n", toString(outputList));
18851895
}
18861896

1897+
static void hashhash_universal_character_2()
1898+
{
1899+
const char code[] =
1900+
"#define A(x,y) x##y\nint A(\\U0104, 0104);";
1901+
simplecpp::OutputList outputList;
1902+
preprocess(code, simplecpp::DUI(), &outputList);
1903+
ASSERT_EQUALS("file0,1,syntax_error,failed to expand 'A', Invalid ## usage when expanding 'A': Combining '\\U0104' and '0104' yields universal character '\\U01040104'. This is undefined behavior according to C standard chapter 5.1.1.2, paragraph 4.\n", toString(outputList));
1904+
}
1905+
1906+
18871907
static void has_include_1()
18881908
{
18891909
const char code[] = "#ifdef __has_include\n"
@@ -4019,11 +4039,14 @@ static void runTests(int argc, char **argv, Input input)
40194039
TEST_CASE(hashhash_invalid_missing_args);
40204040
TEST_CASE(hashhash_null_stmt);
40214041
TEST_CASE(hashhash_empty_va_args);
4042+
TEST_CASE(hashhash_va_args_unexpected);
4043+
40224044
// C standard, 5.1.1.2, paragraph 4:
40234045
// If a character sequence that matches the syntax of a universal
40244046
// character name is produced by token concatenation (6.10.3.3),
40254047
// the behavior is undefined."
40264048
TEST_CASE(hashhash_universal_character);
4049+
TEST_CASE(hashhash_universal_character_2);
40274050

40284051
// c++17 __has_include
40294052
TEST_CASE(has_include_1);

0 commit comments

Comments
 (0)