1 /*
2 Copyright 2019-2022 René Ferdinand Rivera Morell
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt)
6 */
7 
8 #include "mini_test.hpp"
9 #include <lyra/lyra.hpp>
10 
main()11 int main()
12 {
13 	using namespace lyra;
14 	bfg::mini_test::scope test;
15 	bool a = false, b = false, c = false;
16 	int x = 10;
17 	float y = 3.14f;
18 	bool sdf = false;
19 	auto cli = opt(a)["-a"]["--flag-a"] | opt(b)["-b"]["--flag-b"]
20 		| opt(c)["-c"]["--flag-c"] | opt(x, "int-x")["-x"]["--int-x"]
21 		| opt(y, "float-y")["-y"]["--float-y"]
22 		| opt(sdf)["-sdf"];
23 
24 	a = false, b = false, c = false;
25 	test(REQUIRE(
26 		cli.parse({ "TestApp", "-a", "-b", "-c", "-x", "3", "-y", "6.6" })));
27 	test(REQUIRE(a))(REQUIRE(b))(REQUIRE(c));
28 	a = false, b = false, c = false;
29 	test(REQUIRE(cli.parse({ "TestApp", "-abc", "-x", "3", "-y", "6.6" })));
30 	test(REQUIRE(a))(REQUIRE(b))(REQUIRE(c));
31 	x = 0;
32 	test(REQUIRE(cli.parse({ "TestApp", "-x", "3" })));
33 	test(REQUIRE(x == 3));
34 	x = 0;
35 	test(REQUIRE(cli.parse({ "TestApp", "-x=3" })));
36 	test(REQUIRE(x == 3));
37 	x = 0;
38 	test(REQUIRE(cli.parse({ "TestApp", "-x3" })));
39 	test(REQUIRE(x == 3));
40 	x = 0;
41 	test(REQUIRE(cli.parse({ "TestApp", "--int-x", "3" })));
42 	test(REQUIRE(x == 3));
43 	x = 0;
44 	test(REQUIRE(cli.parse({ "TestApp", "--int-x=3" })));
45 	test(REQUIRE(x == 3));
46 	x = 0;
47 	test(REQUIRE(!cli.parse({ "TestApp", "--int-x3" })));
48 	test(REQUIRE(x == 0));
49 	x = 0;
50 	test(REQUIRE(!cli.parse({ "TestApp", "-x3garbage" })));
51 	test(REQUIRE(x == 0));
52 	x = 0;
53 	test(REQUIRE(!cli.parse({ "TestApp", "-x=3garbage" })));
54 	test(REQUIRE(x == 0));
55 	x = 0;
56 	test(REQUIRE(!cli.parse({ "TestApp", "-x", "3garbage" })));
57 	test(REQUIRE(x == 0));
58 	test(REQUIRE(cli.parse({ "TestApp", "-s" })));
59 	test(REQUIRE(cli.parse({ "TestApp", "-d" })));
60 	test(REQUIRE(cli.parse({ "TestApp", "-f" })));
61 
62 	return test;
63 }
64