You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.8 KiB

2 years ago
  1. /*****************************************************************************
  2. *
  3. * CLIPP - command line interfaces for modern C++
  4. *
  5. * released under MIT license
  6. *
  7. * (c) 2017-2018 André Müller; foss@andremueller-online.de
  8. *
  9. *****************************************************************************/
  10. #include "testing.h"
  11. //-------------------------------------------------------------------
  12. struct active {
  13. active() = default;
  14. active(bool a_, bool b_): a{a_}, b{b_} {}
  15. bool a = false, b = false;
  16. friend bool operator == (const active& x, const active& y) noexcept {
  17. return (x.a == y.a && x.b == y.b);
  18. }
  19. };
  20. //-------------------------------------------------------------------
  21. void test(int lineNo,
  22. const std::initializer_list<const char*> args,
  23. const active& matches)
  24. {
  25. using namespace clipp;
  26. active m;
  27. auto cli = joinable(
  28. option(">:a").set(m.a),
  29. option(">:b").set(m.b)
  30. );
  31. run_wrapped_variants({ __FILE__, lineNo }, args, cli,
  32. [&]{ m = active{}; },
  33. [&]{ return m == matches; });
  34. }
  35. //-------------------------------------------------------------------
  36. int main()
  37. {
  38. using std::string;
  39. try {
  40. test(__LINE__, {""}, active{});
  41. test(__LINE__, {">:a"}, active{1,0});
  42. test(__LINE__, {">:b"}, active{0,1});
  43. test(__LINE__, {">:a",">:b"}, active{1,1});
  44. test(__LINE__, {">:b",">:a"}, active{1,1});
  45. test(__LINE__, {">:ab"}, active{1,1});
  46. test(__LINE__, {">:ba"}, active{1,1});
  47. //fail cases
  48. test(__LINE__, {">:-ab"}, active{});
  49. test(__LINE__, {"bca"}, active{});
  50. test(__LINE__, {"-bca"}, active{});
  51. test(__LINE__, {">:b-a"}, active{});
  52. }
  53. catch(std::exception& e) {
  54. std::cerr << e.what() << std::endl;
  55. return 1;
  56. }
  57. }