diff options
author | dobrokot <dobrokot@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
commit | 25d83bf841d8b3ce3886525078f1964ac3c293c5 (patch) | |
tree | bd52fa16c8dd727890b2ef9d87d1a402bd0d3a9a /library/cpp/getopt | |
parent | 1d2e8a8e9976488ea69a7e4763aa749244f82612 (diff) | |
download | ydb-25d83bf841d8b3ce3886525078f1964ac3c293c5.tar.gz |
Restoring authorship annotation for <dobrokot@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/getopt')
-rw-r--r-- | library/cpp/getopt/small/opt.h | 6 | ||||
-rw-r--r-- | library/cpp/getopt/ut/opt_ut.cpp | 48 |
2 files changed, 27 insertions, 27 deletions
diff --git a/library/cpp/getopt/small/opt.h b/library/cpp/getopt/small/opt.h index ecb57439bc..6bd81e62cb 100644 --- a/library/cpp/getopt/small/opt.h +++ b/library/cpp/getopt/small/opt.h @@ -94,9 +94,9 @@ public: } TVector<TString> GetFreeArgs() const { - return NLastGetopt::TOptsParseResult(&*Opts_, GetArgC(), GetArgV()).GetFreeArgs(); - } - + return NLastGetopt::TOptsParseResult(&*Opts_, GetArgC(), GetArgV()).GetFreeArgs(); + } + // obsolete, use GetArg() instead char* Arg; /* option argument if any or NULL */ diff --git a/library/cpp/getopt/ut/opt_ut.cpp b/library/cpp/getopt/ut/opt_ut.cpp index 441aa493a0..0148831799 100644 --- a/library/cpp/getopt/ut/opt_ut.cpp +++ b/library/cpp/getopt/ut/opt_ut.cpp @@ -1,7 +1,7 @@ #include <library/cpp/getopt/opt.h> #include <library/cpp/testing/unittest/registar.h> -#include <util/string/vector.h> +#include <util/string/vector.h> Y_UNIT_TEST_SUITE(OptTest) { Y_UNIT_TEST(TestSimple) { @@ -15,38 +15,38 @@ Y_UNIT_TEST_SUITE(OptTest) { UNIT_ASSERT_VALUES_EQUAL(EOF, opt.Get()); UNIT_ASSERT_VALUES_EQUAL(EOF, opt.Get()); } - + Y_UNIT_TEST(TestFreeArguments) { - Opt::Ion options[] = { + Opt::Ion options[] = { {"some-option", Opt::WithArg, nullptr, 123}, {nullptr, Opt::WithoutArg, nullptr, 0}}; const char* argv[] = {"cmd", "ARG1", "-some-option", "ARG2", "ARG3", nullptr}; - int argc = 5; - Opt opts(argc, argv, "", options); - + int argc = 5; + Opt opts(argc, argv, "", options); + UNIT_ASSERT_VALUES_EQUAL(JoinStrings(opts.GetFreeArgs(), ", "), "ARG1, ARG3"); - } - + } + Y_UNIT_TEST(TestLongOption) { - const int SOME_OPTION_ID = 12345678; - Opt::Ion options[] = { + const int SOME_OPTION_ID = 12345678; + Opt::Ion options[] = { {"some-option", Opt::WithArg, nullptr, SOME_OPTION_ID}, {nullptr, Opt::WithoutArg, nullptr, 0}}; - for (int doubleDash = 0; doubleDash <= 1; ++doubleDash) { + for (int doubleDash = 0; doubleDash <= 1; ++doubleDash) { const char* argv[] = {"cmd", "ARG1", (doubleDash ? "--some-option" : "-some-option"), "ARG2", "ARG3", nullptr}; - int argc = 5; - Opt opts(argc, argv, "", options); - + int argc = 5; + Opt opts(argc, argv, "", options); + TString optionValue = ""; - int optlet = 0; - while ((optlet = opts.Get()) != EOF) { - if (optlet == SOME_OPTION_ID) { - optionValue = opts.GetArg(); + int optlet = 0; + while ((optlet = opts.Get()) != EOF) { + if (optlet == SOME_OPTION_ID) { + optionValue = opts.GetArg(); } else { - UNIT_FAIL("don't expected any options, except -some-option"); - } - } - UNIT_ASSERT_VALUES_EQUAL(optionValue, "ARG2"); - } - } + UNIT_FAIL("don't expected any options, except -some-option"); + } + } + UNIT_ASSERT_VALUES_EQUAL(optionValue, "ARG2"); + } + } } |