File: BoostOptionTypeTest.cpp

package info (click to toggle)
cli11 2.4.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,120 kB
  • sloc: cpp: 23,299; python: 129; sh: 64; makefile: 11; ruby: 7
file content (126 lines) | stat: -rw-r--r-- 3,886 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) 2017-2024, University of Cincinnati, developed by Henry Schreiner
// under NSF AWARD 1414736 and by the respective contributors.
// All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause

#include "app_helper.hpp"
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/container/slist.hpp>
#include <boost/container/small_vector.hpp>
#include <boost/container/stable_vector.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/container/vector.hpp>
#include <string>
#include <vector>

using namespace boost::container;

TEMPLATE_TEST_CASE("Boost container single",
                   "[boost][optional]",
                   (small_vector<int, 2>),
                   (small_vector<int, 3>),
                   flat_set<int>,
                   stable_vector<int>,
                   slist<int>) {
    TApp tapp;
    TestType cv;
    CLI::Option *opt = tapp.app.add_option("-v", cv);

    tapp.args = {"-v", "1", "-1", "-v", "3", "-v", "-976"};
    tapp.run();
    CHECK(tapp.app.count("-v") == 4u);
    CHECK(cv.size() == 4u);
    opt->check(CLI::PositiveNumber.application_index(0));
    opt->check((!CLI::PositiveNumber).application_index(1));
    CHECK_NOTHROW(tapp.run());
    CHECK(cv.size() == 4u);
    // v[3] would be negative
    opt->check(CLI::PositiveNumber.application_index(3));
    CHECK_THROWS_AS(tapp.run(), CLI::ValidationError);
}

using isp = std::pair<int, std::string>;

TEMPLATE_TEST_CASE("Boost container pair",
                   "[boost][optional]",
                   stable_vector<isp>,
                   (small_vector<isp, 2>),
                   flat_set<isp>,
                   slist<isp>,
                   vector<isp>,
                   (flat_map<int, std::string>)) {

    TApp tapp;
    TestType cv;

    tapp.app.add_option("--dict", cv);

    tapp.args = {"--dict", "1", "str1", "--dict", "3", "str3"};

    tapp.run();
    CHECK(2u == cv.size());

    tapp.args = {"--dict", "1", "str1", "--dict", "3", "--dict", "-1", "str4"};
    tapp.run();
    CHECK(3u == cv.size());
}

using tup_obj = std::tuple<int, std::string, double>;

TEMPLATE_TEST_CASE("Boost container tuple",
                   "[boost][optional]",
                   (small_vector<tup_obj, 3>),
                   stable_vector<tup_obj>,
                   flat_set<tup_obj>,
                   slist<tup_obj>) {
    TApp tapp;
    TestType cv;

    tapp.app.add_option("--dict", cv);

    tapp.args = {"--dict", "1", "str1", "4.3", "--dict", "3", "str3", "2.7"};

    tapp.run();
    CHECK(2u == cv.size());

    tapp.args = {"--dict", "1", "str1", "4.3", "--dict", "3", "str3", "2.7", "--dict", "-1", "str4", "-1.87"};
    tapp.run();
    CHECK(3u == cv.size());
}

using icontainer1 = vector<int>;
using icontainer2 = flat_set<int>;
using icontainer3 = slist<int>;

TEMPLATE_TEST_CASE("Boost container container",
                   "[boost][optional]",
                   std::vector<icontainer1>,
                   slist<icontainer1>,
                   flat_set<icontainer1>,
                   (small_vector<icontainer1, 2>),
                   std::vector<icontainer2>,
                   slist<icontainer2>,
                   flat_set<icontainer2>,
                   stable_vector<icontainer2>,
                   (static_vector<icontainer2, 10>),
                   slist<icontainer3>,
                   flat_set<icontainer3>,
                   (static_vector<icontainer3, 10>)) {

    TApp tapp;
    TestType cv;

    tapp.app.add_option("--dict", cv);

    tapp.args = {"--dict", "1", "2", "4", "--dict", "3", "1"};

    tapp.run();
    CHECK(2u == cv.size());

    tapp.args = {"--dict", "1", "2", "4", "--dict", "3", "1", "--dict", "3", "--dict",
                 "3",      "3", "3", "3", "3",      "3", "3", "3",      "3", "-3"};
    tapp.run();
    CHECK(4u == cv.size());
}