Skip to content

Commit 47ead4b

Browse files
committed
add tests
1 parent 06c7bf0 commit 47ead4b

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

test.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,82 @@ static void elif()
23702370
ASSERT_EQUALS("\n\n\n\n\n3", preprocess(code3));
23712371
}
23722372

2373+
static void elifdef()
2374+
{
2375+
simplecpp::DUI dui;
2376+
dui.std = "c++23";
2377+
2378+
{
2379+
const char code[] = "#if 1\n"
2380+
"1\n"
2381+
"#elifdef X\n"
2382+
"2\n"
2383+
"#else\n"
2384+
"3\n"
2385+
"#endif";
2386+
ASSERT_EQUALS("\n1", preprocess(code, dui));
2387+
}
2388+
{
2389+
const char code[] = "#define X\n"
2390+
"#if 0\n"
2391+
"1\n"
2392+
"#elifdef X\n"
2393+
"2\n"
2394+
"#else\n"
2395+
"3\n"
2396+
"#endif";
2397+
ASSERT_EQUALS("\n\n\n\n2", preprocess(code, dui));
2398+
}
2399+
{
2400+
const char code[] = "#if 0\n"
2401+
"1\n"
2402+
"#elifdef X\n"
2403+
"2\n"
2404+
"#else\n"
2405+
"3\n"
2406+
"#endif";
2407+
ASSERT_EQUALS("\n\n\n\n\n3", preprocess(code, dui));
2408+
}
2409+
}
2410+
2411+
static void elifndef()
2412+
{
2413+
simplecpp::DUI dui;
2414+
dui.std = "c++23";
2415+
2416+
{
2417+
const char code[] = "#if 1\n"
2418+
"1\n"
2419+
"#elifndef X\n"
2420+
"2\n"
2421+
"#else\n"
2422+
"3\n"
2423+
"#endif";
2424+
ASSERT_EQUALS("\n1", preprocess(code, dui));
2425+
}
2426+
{
2427+
const char code[] = "#if 0\n"
2428+
"1\n"
2429+
"#elifndef X\n"
2430+
"2\n"
2431+
"#else\n"
2432+
"3\n"
2433+
"#endif";
2434+
ASSERT_EQUALS("\n\n\n2", preprocess(code, dui));
2435+
}
2436+
{
2437+
const char code[] = "#define X\n"
2438+
"#if 0\n"
2439+
"1\n"
2440+
"#elifndef X\n"
2441+
"2\n"
2442+
"#else\n"
2443+
"3\n"
2444+
"#endif";
2445+
ASSERT_EQUALS("\n\n\n\n\n\n3", preprocess(code, dui));
2446+
}
2447+
}
2448+
23732449
static void ifif()
23742450
{
23752451
// source code from LLVM
@@ -4329,6 +4405,8 @@ static void runTests(int argc, char **argv, Input input)
43294405
TEST_CASE(ifLogical);
43304406
TEST_CASE(ifSizeof);
43314407
TEST_CASE(elif);
4408+
TEST_CASE(elifdef);
4409+
TEST_CASE(elifndef);
43324410
TEST_CASE(ifif);
43334411
TEST_CASE(ifoverflow);
43344412
TEST_CASE(ifdiv0);

0 commit comments

Comments
 (0)