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. static void
  22. test(int lineNo,
  23. const std::initializer_list<const char*> args,
  24. const active& matches )
  25. {
  26. using namespace clipp;
  27. active m;
  28. auto cli = joinable(
  29. option("a").set(m.a),
  30. option("b").set(m.b)
  31. );
  32. run_wrapped_variants({ __FILE__, lineNo }, args, cli,
  33. [&]{ m = active{}; },
  34. [&]{ return m == matches; });
  35. }
  36. //-------------------------------------------------------------------
  37. int main()
  38. {
  39. using std::string;
  40. try {
  41. test(__LINE__, {""}, active{});
  42. test(__LINE__, {"a"}, active{1,0});
  43. test(__LINE__, {"b"}, active{0,1});
  44. test(__LINE__, {"a","b"}, active{1,1});
  45. test(__LINE__, {"b","a"}, active{1,1});
  46. test(__LINE__, {"ab"}, active{1,1});
  47. test(__LINE__, {"ba"}, active{1,1});
  48. //fail cases
  49. test(__LINE__, {"-ab"}, active{});
  50. test(__LINE__, {"-ba"}, active{});
  51. test(__LINE__, {"bac"}, active{});
  52. }
  53. catch(std::exception& e) {
  54. std::cerr << e.what() << std::endl;
  55. return 1;
  56. }
  57. }