Skip to content

Commit 11c9eee

Browse files
committed
TestPreprocessor: re-grouped and extended some tests
1 parent bd2b385 commit 11c9eee

2 files changed

Lines changed: 247 additions & 55 deletions

File tree

lib/preprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set<s
425425
}
426426

427427
const auto lessGreaterThanConfig = [](const simplecpp::Token* dtok, const simplecpp::Token* ctok) {
428-
int v = MathLib::toBigNumber(ctok->next->str());
428+
auto v = MathLib::toBigNumber(ctok->next->str());
429429
if (ctok->op == '<')
430430
v -= 1;
431431
else

test/testpreprocessor.cpp

Lines changed: 246 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,15 @@ class TestPreprocessor : public TestFixture {
319319
TEST_CASE(getConfigs11); // #9832 - include guards
320320
TEST_CASE(getConfigs12); // #14222
321321
TEST_CASE(getConfigs13); // #14222
322-
TEST_CASE(getConfigs14); // #1059
323-
TEST_CASE(getConfigs15); // #1059
324-
TEST_CASE(getConfigs16); // #1059
325-
TEST_CASE(getConfigs17); // #1059
326-
TEST_CASE(getConfigs18); // #1059
327-
TEST_CASE(getConfigs19); // #1059
328-
TEST_CASE(getConfigs20); // #1059
329-
TEST_CASE(getConfigs21); // #1059
330-
TEST_CASE(getConfigs22); // #1059
322+
TEST_CASE(getConfigs_gte); // #1059
323+
TEST_CASE(getConfigs_lte); // #1059
324+
TEST_CASE(getConfigs_gt); // #1059
325+
TEST_CASE(getConfigs_lt); // #1059
326+
TEST_CASE(getConfigs_eq_compound); // #1059
327+
TEST_CASE(getConfigs_gte_compound); // #1059
328+
TEST_CASE(getConfigs_lte_compound); // #1059
329+
TEST_CASE(getConfigs_gt_compound); // #1059
330+
TEST_CASE(getConfigs_lt_compound); // #1059
331331
TEST_CASE(getConfigsError);
332332

333333
TEST_CASE(getConfigsD1);
@@ -2336,67 +2336,259 @@ class TestPreprocessor : public TestFixture {
23362336
ASSERT_EQUALS("\n", getConfigsStr(filedata, nullptr, "gnu.cfg"));
23372337
}
23382338

2339-
void getConfigs14() { // #1059
2340-
const char filedata[] = "#if A >= 1\n"
2341-
"1\n"
2342-
"#endif\n";
2343-
ASSERT_EQUALS("\nA=1\n", getConfigsStr(filedata));
2339+
void getConfigs_gte() { // #1059
2340+
{
2341+
const char filedata[] = "#if A >= 1\n"
2342+
"1\n"
2343+
"#endif\n";
2344+
ASSERT_EQUALS("\nA=1\n", getConfigsStr(filedata));
2345+
}
2346+
{
2347+
const char filedata[] = "#if A >= 201112L\n"
2348+
"1\n"
2349+
"#endif\n";
2350+
ASSERT_EQUALS("\nA=201112L\n", getConfigsStr(filedata));
2351+
}
2352+
{
2353+
const char filedata[] = "#if A >= 12147483647\n"
2354+
"1\n"
2355+
"#endif\n";
2356+
ASSERT_EQUALS("\nA=12147483647\n", getConfigsStr(filedata));
2357+
}
23442358
}
23452359

2346-
void getConfigs15() { // #1059
2347-
const char filedata[] = "#if A <= 1\n"
2348-
"1\n"
2349-
"#endif\n";
2350-
ASSERT_EQUALS("\nA=1\n", getConfigsStr(filedata));
2360+
void getConfigs_lte() { // #1059
2361+
{
2362+
const char filedata[] = "#if A <= 1\n"
2363+
"1\n"
2364+
"#endif\n";
2365+
ASSERT_EQUALS("\nA=1\n", getConfigsStr(filedata));
2366+
}
2367+
{
2368+
const char filedata[] = "#if A <= 201112L\n"
2369+
"1\n"
2370+
"#endif\n";
2371+
ASSERT_EQUALS("\nA=201112L\n", getConfigsStr(filedata));
2372+
}
2373+
{
2374+
const char filedata[] = "#if A <= 12147483647\n"
2375+
"1\n"
2376+
"#endif\n";
2377+
ASSERT_EQUALS("\nA=12147483647\n", getConfigsStr(filedata));
2378+
}
23512379
}
23522380

2353-
void getConfigs16() { // #1059
2354-
const char filedata[] = "#if A > 1\n"
2355-
"1\n"
2356-
"#endif\n";
2357-
ASSERT_EQUALS("\nA=2\n", getConfigsStr(filedata));
2381+
void getConfigs_gt() { // #1059
2382+
{
2383+
const char filedata[] = "#if A > 1\n"
2384+
"1\n"
2385+
"#endif\n";
2386+
ASSERT_EQUALS("\nA=2\n", getConfigsStr(filedata));
2387+
}
2388+
{
2389+
const char filedata[] = "#if A > 1L\n"
2390+
"1\n"
2391+
"#endif\n";
2392+
ASSERT_EQUALS("\nA=2\n", getConfigsStr(filedata));
2393+
}
2394+
{
2395+
const char filedata[] = "#if A > 1U\n"
2396+
"1\n"
2397+
"#endif\n";
2398+
ASSERT_EQUALS("\nA=2\n", getConfigsStr(filedata));
2399+
}
2400+
{
2401+
const char filedata[] = "#if A > 1UL\n"
2402+
"1\n"
2403+
"#endif\n";
2404+
ASSERT_EQUALS("\nA=2\n", getConfigsStr(filedata));
2405+
}
2406+
{
2407+
const char filedata[] = "#if A > 1Z\n"
2408+
"1\n"
2409+
"#endif\n";
2410+
ASSERT_EQUALS("\nA=2\n", getConfigsStr(filedata));
2411+
}
2412+
{
2413+
const char filedata[] = "#if A > 0x1\n"
2414+
"1\n"
2415+
"#endif\n";
2416+
ASSERT_EQUALS("\nA=2\n", getConfigsStr(filedata));
2417+
}
2418+
{
2419+
const char filedata[] = "#if A > 01\n"
2420+
"1\n"
2421+
"#endif\n";
2422+
ASSERT_EQUALS("\nA=2\n", getConfigsStr(filedata));
2423+
}
2424+
{
2425+
const char filedata[] = "#if A > 0b1\n"
2426+
"1\n"
2427+
"#endif\n";
2428+
ASSERT_EQUALS("\nA=2\n", getConfigsStr(filedata));
2429+
}
2430+
{
2431+
const char filedata[] = "#if A > 1t\n"
2432+
"1\n"
2433+
"#endif\n";
2434+
ASSERT_THROW_INTERNAL_EQUALS(getConfigsStr(filedata), INTERNAL, "Internal Error. MathLib::toBigNumber: input was not completely consumed: 1t");
2435+
}
2436+
{
2437+
const char filedata[] = "#if A > 1.0\n"
2438+
"1\n"
2439+
"#endif\n";
2440+
TODO_ASSERT_THROW(getConfigsStr(filedata), InternalError); // floating point literals are not allowed
2441+
}
2442+
{
2443+
const char filedata[] = "#if A > 12147483647\n"
2444+
"1\n"
2445+
"#endif\n";
2446+
ASSERT_EQUALS("\nA=12147483648\n", getConfigsStr(filedata));
2447+
}
23582448
}
23592449

2360-
void getConfigs17() { // #1059
2361-
const char filedata[] = "#if A < 1\n"
2362-
"1\n"
2363-
"#endif\n";
2364-
ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata));
2450+
void getConfigs_lt() { // #1059
2451+
{
2452+
const char filedata[] = "#if A < 1\n"
2453+
"1\n"
2454+
"#endif\n";
2455+
ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata));
2456+
}
2457+
{
2458+
const char filedata[] = "#if A < 1L\n"
2459+
"1\n"
2460+
"#endif\n";
2461+
ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata));
2462+
}
2463+
{
2464+
const char filedata[] = "#if A < 1U\n"
2465+
"1\n"
2466+
"#endif\n";
2467+
ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata));
2468+
}
2469+
{
2470+
const char filedata[] = "#if A < 1UL\n"
2471+
"1\n"
2472+
"#endif\n";
2473+
ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata));
2474+
}
2475+
{
2476+
const char filedata[] = "#if A < 1Z\n"
2477+
"1\n"
2478+
"#endif\n";
2479+
ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata));
2480+
}
2481+
{
2482+
const char filedata[] = "#if A < 0x1\n"
2483+
"1\n"
2484+
"#endif\n";
2485+
ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata));
2486+
}
2487+
{
2488+
const char filedata[] = "#if A < 01\n"
2489+
"1\n"
2490+
"#endif\n";
2491+
ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata));
2492+
}
2493+
{
2494+
const char filedata[] = "#if A < 0b1\n"
2495+
"1\n"
2496+
"#endif\n";
2497+
ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata));
2498+
}
2499+
{
2500+
const char filedata[] = "#if A < 1t\n"
2501+
"1\n"
2502+
"#endif\n";
2503+
ASSERT_THROW_INTERNAL_EQUALS(getConfigsStr(filedata), INTERNAL, "Internal Error. MathLib::toBigNumber: input was not completely consumed: 1t");
2504+
}
2505+
{
2506+
const char filedata[] = "#if A < 1.0\n"
2507+
"1\n"
2508+
"#endif\n";
2509+
TODO_ASSERT_THROW(getConfigsStr(filedata), InternalError); // floating point literals are not allowed
2510+
}
2511+
{
2512+
const char filedata[] = "#if A < 12147483647\n"
2513+
"1\n"
2514+
"#endif\n";
2515+
ASSERT_EQUALS("\nA=12147483646\n", getConfigsStr(filedata));
2516+
}
23652517
}
23662518

2367-
void getConfigs18() { // #1059
2368-
const char filedata[] = "#if A == 1 && defined(B)\n"
2369-
"1\n"
2370-
"#endif\n";
2371-
ASSERT_EQUALS("\nA=1;B\n", getConfigsStr(filedata));
2519+
void getConfigs_eq_compound() { // #1059
2520+
{
2521+
const char filedata[] = "#if A == 1 && defined(B)\n"
2522+
"1\n"
2523+
"#endif\n";
2524+
ASSERT_EQUALS("\nA=1;B=B\n", getConfigsStr(filedata));
2525+
}
2526+
{
2527+
const char filedata[] = "#if A == 201112L && defined(B)\n"
2528+
"1\n"
2529+
"#endif\n";
2530+
ASSERT_EQUALS("\nA=201112L;B=B\n", getConfigsStr(filedata));
2531+
}
23722532
}
23732533

2374-
void getConfigs19() { // #1059
2375-
const char filedata[] = "#if A >= 1 && defined(B)\n"
2376-
"1\n"
2377-
"#endif\n";
2378-
ASSERT_EQUALS("\nA=1;B\n", getConfigsStr(filedata));
2534+
void getConfigs_gte_compound() { // #1059
2535+
{
2536+
const char filedata[] = "#if A >= 1 && defined(B)\n"
2537+
"1\n"
2538+
"#endif\n";
2539+
ASSERT_EQUALS("\nA=1;B=B\n", getConfigsStr(filedata));
2540+
}
2541+
{
2542+
const char filedata[] = "#if A >= 201112L && defined(B)\n"
2543+
"1\n"
2544+
"#endif\n";
2545+
ASSERT_EQUALS("\nA=201112L;B=B\n", getConfigsStr(filedata));
2546+
}
23792547
}
23802548

2381-
void getConfigs20() { // #1059
2382-
const char filedata[] = "#if A <= 1 && defined(B)\n"
2383-
"1\n"
2384-
"#endif\n";
2385-
ASSERT_EQUALS("\nA=1;B\n", getConfigsStr(filedata));
2549+
void getConfigs_lte_compound() { // #1059
2550+
{
2551+
const char filedata[] = "#if A <= 1 && defined(B)\n"
2552+
"1\n"
2553+
"#endif\n";
2554+
ASSERT_EQUALS("\nA=1;B=B\n", getConfigsStr(filedata));
2555+
}
2556+
{
2557+
const char filedata[] = "#if A <= 201112L && defined(B)\n"
2558+
"1\n"
2559+
"#endif\n";
2560+
ASSERT_EQUALS("\nA=201112L;B=B\n", getConfigsStr(filedata));
2561+
}
23862562
}
23872563

2388-
void getConfigs21() { // #1059
2389-
const char filedata[] = "#if A > 1 && defined(B)\n"
2390-
"1\n"
2391-
"#endif\n";
2392-
ASSERT_EQUALS("\nA=2;B\n", getConfigsStr(filedata));
2564+
void getConfigs_gt_compound() { // #1059
2565+
{
2566+
const char filedata[] = "#if A > 1 && defined(B)\n"
2567+
"1\n"
2568+
"#endif\n";
2569+
ASSERT_EQUALS("\nA=2;B=B\n", getConfigsStr(filedata));
2570+
}
2571+
{
2572+
const char filedata[] = "#if A > 201112L && defined(B)\n"
2573+
"1\n"
2574+
"#endif\n";
2575+
ASSERT_EQUALS("\nA=201113;B=B\n", getConfigsStr(filedata));
2576+
}
23932577
}
23942578

2395-
void getConfigs22() { // #1059
2396-
const char filedata[] = "#if A < 1 && defined(B)\n"
2397-
"1\n"
2398-
"#endif\n";
2399-
ASSERT_EQUALS("\nA=0;B\n", getConfigsStr(filedata));
2579+
void getConfigs_lt_compound() { // #1059
2580+
{
2581+
const char filedata[] = "#if A < 1 && defined(B)\n"
2582+
"1\n"
2583+
"#endif\n";
2584+
ASSERT_EQUALS("\nA=0;B=B\n", getConfigsStr(filedata));
2585+
}
2586+
{
2587+
const char filedata[] = "#if A < 201112L && defined(B)\n"
2588+
"1\n"
2589+
"#endif\n";
2590+
ASSERT_EQUALS("\nA=201111;B=B\n", getConfigsStr(filedata));
2591+
}
24002592
}
24012593

24022594
void getConfigsError() {

0 commit comments

Comments
 (0)