From c9dfa286a265552db504adf7121537c99c17ff3b Mon Sep 17 00:00:00 2001 From: lazysegtree <59679977+lazysegtree@users.noreply.github.com> Date: Mon, 12 Jan 2026 20:21:06 +0530 Subject: [PATCH] feat: Add test for Ordering of multiple long options --- test/options.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/options.cpp b/test/options.cpp index 6df4972..6faa438 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -1191,3 +1191,34 @@ TEST_CASE("No Options help", "[options]") CHECK_NOTHROW(options.parse(argc, argv)); CHECK(options.help().find("test ...") != std::string::npos); } + +TEST_CASE("Ordering of multiple long options", "[help]") +{ + cxxopts::Options options("test", "Ordering of multiple long options"); + options.add_options() + ("x,alphax,betax,gammax,deltax", "Multiple names x", cxxopts::value()) + ("deltay,gammay,y,betay,alphay", "Multiple names y", cxxopts::value()) + ("alphaz,betaz,z", "Multiple names z", cxxopts::value()) + ("alphaw,w", "Multiple names w", cxxopts::value()) + ("beta,gamma,alpha,delta", "Without short name", cxxopts::value()); + + auto opts = options.group_help("").options; + + // Veryfiy ordering + REQUIRE(opts.size()==5); + CHECK(opts[0].l == std::vector{"alphax", "betax", "gammax", "deltax"}); + CHECK(opts[1].l == std::vector{"deltay", "gammay", "betay", "alphay"}); + CHECK(opts[2].l == std::vector{"alphaz", "betaz"}); + CHECK(opts[3].l == std::vector{"alphaw"}); + CHECK(opts[4].l == std::vector{"beta", "gamma", "alpha", "delta"}); + + + std::string help = options.help(); + + // Verify first long options are always present in help output + CHECK(help.find("--alphax") != std::string::npos); + CHECK(help.find("--deltay") != std::string::npos); + CHECK(help.find("--alphaz") != std::string::npos); + CHECK(help.find("--alphaw") != std::string::npos); + CHECK(help.find("--beta") != std::string::npos); +}