1 /* 2 Copyright 2020-2021 Max Ferger 3 Copyright 2020-2022 René Ferdinand Rivera Morell 4 Distributed under the Boost Software License, Version 1.0. 5 (See accompanying file LICENSE.txt or copy at 6 http://www.boost.org/LICENSE_1_0.txt) 7 */ 8 9 #include "mini_test.hpp" 10 #include <lyra/lyra.hpp> 11 #include <sstream> 12 #include <string> 13 main()14int main() 15 { 16 using namespace lyra; 17 bfg::mini_test::scope test; 18 19 { 20 int i = -1; 21 bool show_help = false; 22 auto opt_i_parser = opt(i, "dummy")["-i"]; 23 test(REQUIRE(opt_i_parser.hint() == "dummy")); 24 25 opt_i_parser.hint("integer"); // DUT 26 27 test(REQUIRE(opt_i_parser.hint() == "integer")); 28 29 auto cli = lyra::cli() | opt_i_parser | help(show_help); 30 31 { 32 std::ostringstream help_text; 33 auto result = cli.parse({ "TestApp", "-?" }); 34 help_text << cli; 35 test(REQUIRE(result)); 36 test(REQUIRE(help_text.str().find("dummy") == std::string::npos)); 37 test(REQUIRE(help_text.str().find("integer") != std::string::npos)); 38 } 39 40 { 41 auto result = cli.parse({ "TestApp", "-i=42" }); 42 test(REQUIRE(result)); 43 44 test(REQUIRE(i == 42)); 45 46 int i_via_name = static_cast<int>(cli["-i"]); 47 test(REQUIRE(i_via_name == 42)); 48 49 int i_via_hint = static_cast<int>(cli["integer"]); 50 test(REQUIRE(i_via_hint == 42)); 51 52 int i_via_dummy = static_cast<int>(cli["dummy"]); 53 test(REQUIRE(i_via_dummy == 0)); // also, not -1 54 } 55 } 56 57 return test; 58 } 59