Commit 534792577d6a4fe56f2a2c392c03a0d8c0bff554
Committed by
Henry Schreiner
1 parent
35816a4e
Do not lint chrono, thread, and regex
Showing
2 changed files
with
97 additions
and
2 deletions
tests/NewParseTest.cpp
| ... | ... | @@ -341,6 +341,101 @@ TEST_F(TApp, custom_string_converterFail) { |
| 341 | 341 | EXPECT_THROW(run(), CLI::ConversionError); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | +<<<<<<< HEAD | |
| 345 | +======= | |
| 346 | +// an example of custom complex number converter that can be used to add new parsing options | |
| 347 | +#if defined(__has_include) | |
| 348 | +#if __has_include(<regex>) | |
| 349 | +// an example of custom converter that can be used to add new parsing options | |
| 350 | +#define HAS_REGEX_INCLUDE | |
| 351 | +#endif | |
| 352 | +#endif | |
| 353 | + | |
| 354 | +#ifdef HAS_REGEX_INCLUDE | |
| 355 | +// Gcc 4.8 and older and the corresponding standard libraries have a broken <regex> so this would | |
| 356 | +// fail. And if a clang compiler is using libstd++ then this will generate an error as well so this is just a check to | |
| 357 | +// simplify compilation and prevent a much more complicated #if expression | |
| 358 | +#include <regex> // NOLINT(build/c++11) | |
| 359 | +namespace CLI { | |
| 360 | +namespace detail { | |
| 361 | + | |
| 362 | +// On MSVC and possibly some other new compilers this can be a free standing function without the template | |
| 363 | +// specialization but this is compiler dependent | |
| 364 | +template <> bool lexical_cast<std::complex<double>>(const std::string &input, std::complex<double> &output) { | |
| 365 | + // regular expression to handle complex numbers of various formats | |
| 366 | + static const std::regex creg( | |
| 367 | + R"(([+-]?(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?)\s*([+-]\s*(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?)[ji]*)"); | |
| 368 | + | |
| 369 | + std::smatch m; | |
| 370 | + double x{0.0}, y{0.0}; | |
| 371 | + bool worked; | |
| 372 | + std::regex_search(input, m, creg); | |
| 373 | + if(m.size() == 9) { | |
| 374 | + worked = CLI::detail::lexical_cast(m[1], x) && CLI::detail::lexical_cast(m[6], y); | |
| 375 | + if(worked) { | |
| 376 | + if(*m[5].first == '-') { | |
| 377 | + y = -y; | |
| 378 | + } | |
| 379 | + } | |
| 380 | + } else { | |
| 381 | + if((input.back() == 'j') || (input.back() == 'i')) { | |
| 382 | + auto strval = input.substr(0, input.size() - 1); | |
| 383 | + CLI::detail::trim(strval); | |
| 384 | + worked = CLI::detail::lexical_cast(strval, y); | |
| 385 | + } else { | |
| 386 | + std::string ival = input; | |
| 387 | + CLI::detail::trim(ival); | |
| 388 | + worked = CLI::detail::lexical_cast(ival, x); | |
| 389 | + } | |
| 390 | + } | |
| 391 | + if(worked) { | |
| 392 | + output = cx{x, y}; | |
| 393 | + } | |
| 394 | + return worked; | |
| 395 | +} | |
| 396 | +} // namespace detail | |
| 397 | +} // namespace CLI | |
| 398 | + | |
| 399 | +TEST_F(TApp, AddingComplexParserDetail) { | |
| 400 | + | |
| 401 | + bool skip_tests = false; | |
| 402 | + try { // check if the library actually supports regex, it is possible to link against a non working regex in the | |
| 403 | + // standard library | |
| 404 | + std::smatch m; | |
| 405 | + std::string input = "1.5+2.5j"; | |
| 406 | + static const std::regex creg( | |
| 407 | + R"(([+-]?(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?)\s*([+-]\s*(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?)[ji]*)"); | |
| 408 | + | |
| 409 | + auto rsearch = std::regex_search(input, m, creg); | |
| 410 | + if(!rsearch) { | |
| 411 | + skip_tests = true; | |
| 412 | + } else { | |
| 413 | + EXPECT_EQ(m.size(), 9u); | |
| 414 | + } | |
| 415 | + | |
| 416 | + } catch(...) { | |
| 417 | + skip_tests = true; | |
| 418 | + } | |
| 419 | + if(!skip_tests) { | |
| 420 | + cx comp{0, 0}; | |
| 421 | + app.add_option("-c,--complex", comp, "add a complex number option"); | |
| 422 | + args = {"-c", "1.5+2.5j"}; | |
| 423 | + | |
| 424 | + run(); | |
| 425 | + | |
| 426 | + EXPECT_DOUBLE_EQ(1.5, comp.real()); | |
| 427 | + EXPECT_DOUBLE_EQ(2.5, comp.imag()); | |
| 428 | + args = {"-c", "1.5-2.5j"}; | |
| 429 | + | |
| 430 | + run(); | |
| 431 | + | |
| 432 | + EXPECT_DOUBLE_EQ(1.5, comp.real()); | |
| 433 | + EXPECT_DOUBLE_EQ(-2.5, comp.imag()); | |
| 434 | + } | |
| 435 | +} | |
| 436 | +#endif | |
| 437 | + | |
| 438 | +>>>>>>> Do not lint chrono, thread, and regex | |
| 344 | 439 | /// simple class to wrap another with a very specific type constructor and assignment operators to test out some of the |
| 345 | 440 | /// option assignments |
| 346 | 441 | template <class X> class objWrapper { | ... | ... |
tests/TimerTest.cpp
| ... | ... | @@ -7,10 +7,10 @@ |
| 7 | 7 | #include "CLI/Timer.hpp" |
| 8 | 8 | #include "gmock/gmock.h" |
| 9 | 9 | #include "gtest/gtest.h" |
| 10 | -#include <chrono> | |
| 10 | +#include <chrono> // NOLINT(build/c++11) | |
| 11 | 11 | #include <sstream> |
| 12 | 12 | #include <string> |
| 13 | -#include <thread> | |
| 13 | +#include <thread> // NOLINT(build/c++11) | |
| 14 | 14 | |
| 15 | 15 | using ::testing::HasSubstr; |
| 16 | 16 | ... | ... |