mirror of
https://github.com/CLIUtils/CLI11.git
synced 2026-01-19 04:52:08 +00:00
add tests and fixes for array options (#1136)
Fixes #1135. Adds enable check to certain to_string functions as some std::array operations were ambiguous. The addition of the capability to convert tuples to strings created an ambiguity in the case std::array, which acts like a tuple and a container. So it worked with the container conversion before, but could also work with the new tuple conversion. And we didn't have any tests to catch this. This PR resolves the ambiguity, and adds some tests to check that array is handled well. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <cmath>
|
||||
#include <complex>
|
||||
@@ -912,6 +913,50 @@ TEST_CASE_METHOD(TApp, "vectorPairTypeRange", "[optiontype]") {
|
||||
CHECK("str4" == custom_opt[2].second);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TApp, "ArrayTriple", "[optiontype]") {
|
||||
|
||||
using TY = std::array<int, 3>;
|
||||
TY custom_opt;
|
||||
|
||||
app.add_option("posit", custom_opt);
|
||||
|
||||
args = {"12", "1", "5"};
|
||||
|
||||
run();
|
||||
CHECK(12 == custom_opt[0]);
|
||||
CHECK(1 == custom_opt[1]);
|
||||
CHECK(5 == custom_opt[2]);
|
||||
|
||||
// enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
|
||||
// !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value >= 2,
|
||||
// detail::enabler>>
|
||||
|
||||
CHECK(!std::is_convertible<TY, std::string>::value);
|
||||
CHECK(!std::is_constructible<std::string, TY>::value);
|
||||
CHECK(!CLI::detail::is_ostreamable<TY>::value);
|
||||
auto ts = std::tuple_size<typename std::decay<TY>::type>::value;
|
||||
CHECK(ts == 3);
|
||||
|
||||
auto vb = CLI::detail::type_count_base<TY>::value;
|
||||
CHECK(vb >= 2);
|
||||
CHECK(!CLI::detail::is_complex<TY>::value);
|
||||
CHECK(CLI::detail::is_tuple_like<TY>::value);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TApp, "ArrayPair", "[optiontype]") {
|
||||
|
||||
using TY = std::array<int, 2>;
|
||||
TY custom_opt;
|
||||
|
||||
app.add_option("posit", custom_opt);
|
||||
|
||||
args = {"12", "1"};
|
||||
|
||||
run();
|
||||
CHECK(12 == custom_opt[0]);
|
||||
CHECK(1 == custom_opt[1]);
|
||||
}
|
||||
|
||||
// now with independent type sizes and expected this is possible
|
||||
TEST_CASE_METHOD(TApp, "vectorTuple", "[optiontype]") {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user