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.

98 lines
3.2 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. //don't include anything else before the test subject
  11. #include "testing.h"
  12. //-------------------------------------------------------------------
  13. struct active {
  14. active() = default;
  15. explicit
  16. active(bool a_, bool b_, bool c_, bool d_, bool e_, bool f_) :
  17. a{a_}, b{b_}, c{c_}, d{d_}, e{e_}, f{f_}
  18. {}
  19. bool a = false, b = false, c = false, d = false, e = false, f = false;
  20. friend bool operator == (const active& x, const active& y) noexcept {
  21. return (x.a == y.a && x.b == y.b && x.c == y.c && x.d == y.d &&
  22. x.e == y.e && x.f == y.f);
  23. }
  24. };
  25. //-------------------------------------------------------------------
  26. void test(int lineNo,
  27. const std::initializer_list<const char*> args,
  28. const active& matches)
  29. {
  30. using namespace clipp;
  31. active m;
  32. auto cli = (
  33. option("a").set(m.a),
  34. (
  35. option("b").set(m.b) |
  36. command("c").set(m.c) |
  37. command("d").set(m.d) |
  38. option("e").set(m.e)
  39. ),
  40. option("f").set(m.f)
  41. );
  42. run_test({ __FILE__, lineNo }, args, cli, [&]{ 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__, {"b"}, active{0, 1,0,0,0, 0});
  51. test(__LINE__, {"c"}, active{0, 0,1,0,0, 0});
  52. test(__LINE__, {"d"}, active{0, 0,0,1,0, 0});
  53. test(__LINE__, {"e"}, active{0, 0,0,0,1, 0});
  54. test(__LINE__, {"f"}, active{0, 0,0,0,0, 1});
  55. test(__LINE__, {"a", "b"}, active{1, 1,0,0,0, 0});
  56. test(__LINE__, {"a", "c"}, active{1, 0,1,0,0, 0});
  57. test(__LINE__, {"a", "d"}, active{1, 0,0,1,0, 0});
  58. test(__LINE__, {"a", "e"}, active{1, 0,0,0,1, 0});
  59. test(__LINE__, {"a", "f"}, active{1, 0,0,0,0, 1});
  60. test(__LINE__, {"a", "b", "f"}, active{1, 1,0,0,0, 1});
  61. test(__LINE__, {"a", "c", "f"}, active{1, 0,1,0,0, 1});
  62. test(__LINE__, {"a", "d", "f"}, active{1, 0,0,1,0, 1});
  63. test(__LINE__, {"a", "e", "f"}, active{1, 0,0,0,1, 1});
  64. test(__LINE__, {"f", "b"}, active{0, 1,0,0,0, 1});
  65. test(__LINE__, {"f", "c"}, active{0, 0,1,0,0, 1});
  66. test(__LINE__, {"f", "d"}, active{0, 0,0,1,0, 1});
  67. test(__LINE__, {"f", "e"}, active{0, 0,0,0,1, 1});
  68. test(__LINE__, {"b", "f"}, active{0, 1,0,0,0, 1});
  69. test(__LINE__, {"c", "f"}, active{0, 0,1,0,0, 1});
  70. test(__LINE__, {"d", "f"}, active{0, 0,0,1,0, 1});
  71. test(__LINE__, {"e", "f"}, active{0, 0,0,0,1, 1});
  72. test(__LINE__, {"b", "f", "a"}, active{1, 1,0,0,0, 1});
  73. test(__LINE__, {"c", "f", "a"}, active{0, 0,1,0,0, 1});
  74. test(__LINE__, {"d", "f", "a"}, active{0, 0,0,1,0, 1});
  75. test(__LINE__, {"e", "f", "a"}, active{1, 0,0,0,1, 1});
  76. }
  77. catch(std::exception& e) {
  78. std::cerr << e.what() << std::endl;
  79. return 1;
  80. }
  81. }