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.

96 lines
3.4 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. explicit
  15. active(bool a_, bool b_, bool c_, bool d_, bool e_, bool f_) :
  16. a{a_}, b{b_}, c{c_}, d{d_}, e{e_}, f{f_}
  17. {}
  18. bool a = false, b = false, c = false, d = false, e = false, f = false;
  19. friend bool operator == (const active& x, const active& y) noexcept {
  20. return (x.a == y.a && x.b == y.b && x.c == y.c &&
  21. x.d == y.d && x.e == y.e && x.f == y.f );
  22. }
  23. };
  24. //-------------------------------------------------------------------
  25. void test(int lineNo,
  26. const std::initializer_list<const char*> args,
  27. const active& matches)
  28. {
  29. using namespace clipp;
  30. active m;
  31. auto cli = (
  32. option("a").set(m.a),
  33. option("b").set(m.b) & (
  34. option("c").set(m.c) & (
  35. option("d").set(m.d) & option("e").set(m.e)
  36. )
  37. ),
  38. option("f").set(m.f)
  39. );
  40. run_wrapped_variants({ __FILE__, lineNo }, args, cli,
  41. [&]{ m = active{}; },
  42. [&]{ return m == matches; });
  43. }
  44. //-------------------------------------------------------------------
  45. int main()
  46. {
  47. try {
  48. test(__LINE__, {""}, active{});
  49. test(__LINE__, {"a"}, active{1, 0,0,0,0, 0});
  50. test(__LINE__, {"f"}, active{0, 0,0,0,0, 1});
  51. test(__LINE__, {"b"}, active{0, 1,0,0,0, 0});
  52. test(__LINE__, {"b", "c"}, active{0, 1,1,0,0, 0});
  53. test(__LINE__, {"b", "c", "d"}, active{0, 1,1,1,0, 0});
  54. test(__LINE__, {"b", "c", "d", "e"}, active{0, 1,1,1,1, 0});
  55. test(__LINE__, {"a", "b"}, active{1, 1,0,0,0, 0});
  56. test(__LINE__, {"a", "b", "c"}, active{1, 1,1,0,0, 0});
  57. test(__LINE__, {"a", "b", "c", "d"}, active{1, 1,1,1,0, 0});
  58. test(__LINE__, {"a", "b", "c", "d", "e"}, active{1, 1,1,1,1, 0});
  59. test(__LINE__, {"a", "b", "f"}, active{1, 1,0,0,0, 1});
  60. test(__LINE__, {"a", "b", "c", "f"}, active{1, 1,1,0,0, 1});
  61. test(__LINE__, {"a", "b", "c", "d", "f"}, active{1, 1,1,1,0, 1});
  62. test(__LINE__, {"a", "b", "c", "d", "e", "f"}, active{1, 1,1,1,1, 1});
  63. test(__LINE__, {"f", "b", "a"}, active{1, 1,0,0,0, 1});
  64. test(__LINE__, {"f", "b", "c", "a"}, active{1, 1,1,0,0, 1});
  65. test(__LINE__, {"f", "b", "c", "d", "a"}, active{1, 1,1,1,0, 1});
  66. test(__LINE__, {"f", "b", "c", "d", "e", "a"}, active{1, 1,1,1,1, 1});
  67. test(__LINE__, {"c"}, active{0, 0,0,0,0, 0});
  68. test(__LINE__, {"d"}, active{0, 0,0,0,0, 0});
  69. test(__LINE__, {"e"}, active{0, 0,0,0,0, 0});
  70. test(__LINE__, {"b", "d"}, active{0, 1,0,0,0, 0});
  71. test(__LINE__, {"b", "e"}, active{0, 1,0,0,0, 0});
  72. test(__LINE__, {"b", "c", "e"}, active{0, 1,1,0,0, 0});
  73. }
  74. catch(std::exception& e) {
  75. std::cerr << e.what() << std::endl;
  76. return 1;
  77. }
  78. }