MainSpaceParser class has been renamed to MainOptionsParser

pull/4/head
Tomasz Sowa 2 years ago
parent 96e60c526f
commit ad4e8078ae

@ -36,7 +36,7 @@
*/
#include "mainspaceparser.h"
#include "mainoptionsparser.h"
#include "utf8/utf8.h"
#include <string.h>
@ -47,7 +47,7 @@ namespace PT
MainSpaceParser::MainSpaceParser()
MainOptionsParser::MainOptionsParser()
{
space = 0;
arguments_required_space = 0;
@ -58,36 +58,36 @@ MainSpaceParser::MainSpaceParser()
MainSpaceParser::~MainSpaceParser()
MainOptionsParser::~MainOptionsParser()
{
}
void MainSpaceParser::use_utf8(bool utf8)
void MainOptionsParser::use_utf8(bool utf8)
{
should_use_utf8 = utf8;
}
void MainSpaceParser::set_non_options_arguments_name(const wchar_t * name)
void MainOptionsParser::set_non_options_arguments_name(const wchar_t * name)
{
non_option_arguments_name = name;
}
void MainSpaceParser::set_non_options_arguments_name(const std::wstring & name)
void MainOptionsParser::set_non_options_arguments_name(const std::wstring & name)
{
non_option_arguments_name = name;
}
std::wstring & MainSpaceParser::get_wrong_option()
std::wstring & MainOptionsParser::get_wrong_option()
{
return last_error_option;
}
MainSpaceParser::Status MainSpaceParser::parse(int argc, const char ** argv, Space & out_space)
MainOptionsParser::Status MainOptionsParser::parse(int argc, const char ** argv, Space & out_space)
{
space = &out_space;
arguments_required_space = nullptr;
@ -96,7 +96,7 @@ MainSpaceParser::Status MainSpaceParser::parse(int argc, const char ** argv, Spa
}
MainSpaceParser::Status MainSpaceParser::parse(int argc, const char ** argv, Space & out_space, const Space & arguments)
MainOptionsParser::Status MainOptionsParser::parse(int argc, const char ** argv, Space & out_space, const Space & arguments)
{
space = &out_space;
arguments_required_space = &arguments;;
@ -105,7 +105,7 @@ MainSpaceParser::Status MainSpaceParser::parse(int argc, const char ** argv, Spa
}
MainSpaceParser::Status MainSpaceParser::parse(int argc, const char ** argv)
MainOptionsParser::Status MainOptionsParser::parse(int argc, const char ** argv)
{
last_status = status_ok;
last_error_option.clear();
@ -125,7 +125,7 @@ MainSpaceParser::Status MainSpaceParser::parse(int argc, const char ** argv)
}
void MainSpaceParser::parse(size_t argc, const char ** argv, size_t & argv_index)
void MainOptionsParser::parse(size_t argc, const char ** argv, size_t & argv_index)
{
const char * pchar = argv[argv_index];
@ -161,7 +161,7 @@ void MainSpaceParser::parse(size_t argc, const char ** argv, size_t & argv_index
}
void MainSpaceParser::convert_str(const char * src, std::wstring & dst)
void MainOptionsParser::convert_str(const char * src, std::wstring & dst)
{
if( should_use_utf8 )
{
@ -177,7 +177,7 @@ void MainSpaceParser::convert_str(const char * src, std::wstring & dst)
}
void MainSpaceParser::convert_str(const char * src, size_t len, std::wstring & dst)
void MainOptionsParser::convert_str(const char * src, size_t len, std::wstring & dst)
{
if( should_use_utf8 )
{
@ -193,7 +193,7 @@ void MainSpaceParser::convert_str(const char * src, size_t len, std::wstring & d
}
void MainSpaceParser::convert_str(const std::wstring & src, Space & space)
void MainOptionsParser::convert_str(const std::wstring & src, Space & space)
{
if( should_use_utf8 )
{
@ -213,7 +213,7 @@ void MainSpaceParser::convert_str(const std::wstring & src, Space & space)
}
void MainSpaceParser::parse_short_option(size_t argc, const char ** argv, size_t & argv_index)
void MainOptionsParser::parse_short_option(size_t argc, const char ** argv, size_t & argv_index)
{
convert_str(argv[argv_index] + 1, options);
const wchar_t * options_pchar = options.c_str();
@ -247,7 +247,7 @@ void MainSpaceParser::parse_short_option(size_t argc, const char ** argv, size_t
}
void MainSpaceParser::parse_long_option(size_t argc, const char ** argv, size_t & argv_index)
void MainOptionsParser::parse_long_option(size_t argc, const char ** argv, size_t & argv_index)
{
const char * option_begin = argv[argv_index] + 2; // skip first two hyphens --
const char * option_end = option_begin;
@ -312,7 +312,7 @@ void MainSpaceParser::parse_long_option(size_t argc, const char ** argv, size_t
}
void MainSpaceParser::parse_arguments(size_t argc, const char ** argv, size_t & argv_index, size_t args_len)
void MainOptionsParser::parse_arguments(size_t argc, const char ** argv, size_t & argv_index, size_t args_len)
{
for( ; args_len > 0 && argv_index < argc ; --args_len, ++argv_index)
{
@ -329,7 +329,7 @@ void MainSpaceParser::parse_arguments(size_t argc, const char ** argv, size_t &
void MainSpaceParser::parse_non_option_arguments(size_t argc, const char ** argv, size_t & argv_index)
void MainOptionsParser::parse_non_option_arguments(size_t argc, const char ** argv, size_t & argv_index)
{
Space * table_with_args = new Space();
table_with_args->set_empty_table();
@ -344,7 +344,7 @@ void MainSpaceParser::parse_non_option_arguments(size_t argc, const char ** argv
}
void MainSpaceParser::add_option_to_space(const std::wstring & option, const std::vector<std::wstring> & arguments)
void MainOptionsParser::add_option_to_space(const std::wstring & option, const std::vector<std::wstring> & arguments)
{
Space * option_table = space->get_object_field(option);
@ -372,7 +372,7 @@ void MainSpaceParser::add_option_to_space(const std::wstring & option, const std
size_t MainSpaceParser::how_many_arguments_required(const std::wstring & arg)
size_t MainOptionsParser::how_many_arguments_required(const std::wstring & arg)
{
size_t res = 0;

@ -35,8 +35,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef headerfile_picotools_mainspaceparser_mainparser
#define headerfile_picotools_mainspaceparser_mainparser
#ifndef headerfile_picotools_mainoptions_mainoptionsparser
#define headerfile_picotools_mainoptions_mainoptionsparser
#include "space/space.h"
#include <string>
@ -52,12 +52,12 @@ namespace PT
*
*
*/
class MainSpaceParser
class MainOptionsParser
{
public:
MainSpaceParser();
~MainSpaceParser();
MainOptionsParser();
~MainOptionsParser();
/*

@ -36,7 +36,7 @@
*/
#include "convert.h"
#include "mainargsparser.h"
#include "mainoptionsparser.h"
#include <iostream>
@ -52,7 +52,7 @@ const char * test_msg = nullptr;
int main(int argc, const char ** argv)
{
pt::pt_convert_tests::make_tests();
pt::pt_mainargsparser_tests::make_tests();
pt::pt_mainoptions_tests::make_tests();
if( pt::was_error )
{

@ -36,9 +36,9 @@
*/
#include <iostream>
#include "mainargsparser.h"
#include "mainoptionsparser.h"
#include "test.h"
#include "mainspaceparser/mainspaceparser.h"
#include "mainoptions/mainoptionsparser.h"
#include "utf8/utf8.h"
#include "convert/convert.h"
@ -49,32 +49,32 @@ namespace pt
using namespace PT;
namespace pt_mainargsparser_tests
namespace pt_mainoptions_tests
{
struct MainSpaceParserOutputTest
struct MainOptionsParserOutputTest
{
MainSpaceParser::Status status;
MainOptionsParser::Status status;
const char * option_err;
const char * json;
};
void print_status(MainSpaceParser::Status status)
void print_status(MainOptionsParser::Status status)
{
if( status == MainSpaceParser::status_ok )
if( status == MainOptionsParser::status_ok )
{
std::cout << "MainSpaceParser::status_ok";
std::cout << "MainOptionsParser::status_ok";
}
else
if( status == MainSpaceParser::status_argument_not_provided )
if( status == MainOptionsParser::status_argument_not_provided )
{
std::cout << "MainSpaceParser::status_argument_not_provided";
std::cout << "MainOptionsParser::status_argument_not_provided";
}
else
if( status == MainSpaceParser::status_argument_provided )
if( status == MainOptionsParser::status_argument_provided )
{
std::cout << "MainSpaceParser::status_argument_provided";
std::cout << "MainOptionsParser::status_argument_provided";
}
}
@ -115,12 +115,12 @@ void print_args(int to_index, const char ** argv)
void test_mainargsparser(size_t len, const char ** argv, const Space & arguments_required, MainSpaceParserOutputTest * output)
void test_mainoptionsparser(size_t len, const char ** argv, const Space & arguments_required, MainOptionsParserOutputTest * output)
{
reset_test_counter("mainargsparser");
reset_test_counter("mainoptionsparser");
std::cout << "Testing MainArgsParser" << std::endl;
MainSpaceParser parser;
MainOptionsParser parser;
Space space;
/*
@ -133,7 +133,7 @@ void test_mainargsparser(size_t len, const char ** argv, const Space & arguments
if( !prepare_tests )
print_args(i, argv);
MainSpaceParser::Status status = parser.parse(i + 1, argv, space, arguments_required);
MainOptionsParser::Status status = parser.parse(i + 1, argv, space, arguments_required);
std::wstring & err_wstr = parser.get_wrong_option();
std::string err_str;
@ -158,7 +158,7 @@ void test_mainargsparser(size_t len, const char ** argv, const Space & arguments
void test_mainargsparser1()
void test_mainoptionsparser1()
{
const char * argv[] = {
"program_name",
@ -191,35 +191,35 @@ void test_mainargsparser1()
"non-option-argument3",
};
MainSpaceParserOutputTest output[] = {
{MainSpaceParser::status_ok, "", R"json({})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[]],"c":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "d", R"json({"a":[[]],"b":[[]],"c":[[]],"d":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[]],"c":[[]],"d":[["argument for d"]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"c":[[]],"d":[["argument for d"]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"c":[[]],"d":[["argument for d"]],"long":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "foo", R"json({"a":[[]],"b":[[],[]],"c":[[]],"d":[["argument for d"]],"foo":[[]],"long":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "foo", R"json({"a":[[]],"b":[[],[]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one"]],"long":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "bar", R"json({"a":[[]],"b":[[],[]],"bar":[[]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "bar", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "bar", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"x":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"x":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy3":[[]],"x":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "bar", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"],[]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy3":[[]],"x":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "bar", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy3":[[]],"x":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "bar", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy3":[[]],"x":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2","xbar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy3":[[]],"x":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2","xbar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy2 another_option_for_piggy2":[[]],"piggy3":[[]],"x":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"args":[],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2","xbar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy2 another_option_for_piggy2":[[]],"piggy3":[[]],"x":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"args":["non-option-argument1"],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2","xbar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy2 another_option_for_piggy2":[[]],"piggy3":[[]],"x":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"args":["non-option-argument1","non-option-argument2"],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2","xbar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy2 another_option_for_piggy2":[[]],"piggy3":[[]],"x":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"args":["non-option-argument1","non-option-argument2","non-option-argument3"],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2","xbar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy2 another_option_for_piggy2":[[]],"piggy3":[[]],"x":[[]]})json"},
MainOptionsParserOutputTest output[] = {
{MainOptionsParser::status_ok, "", R"json({})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[]],"c":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "d", R"json({"a":[[]],"b":[[]],"c":[[]],"d":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[]],"c":[[]],"d":[["argument for d"]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"c":[[]],"d":[["argument for d"]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"c":[[]],"d":[["argument for d"]],"long":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "foo", R"json({"a":[[]],"b":[[],[]],"c":[[]],"d":[["argument for d"]],"foo":[[]],"long":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "foo", R"json({"a":[[]],"b":[[],[]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one"]],"long":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "bar", R"json({"a":[[]],"b":[[],[]],"bar":[[]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "bar", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "bar", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"x":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"x":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy3":[[]],"x":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "bar", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"],[]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy3":[[]],"x":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "bar", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy3":[[]],"x":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "bar", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy3":[[]],"x":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2","xbar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy3":[[]],"x":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2","xbar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy2 another_option_for_piggy2":[[]],"piggy3":[[]],"x":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"args":[],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2","xbar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy2 another_option_for_piggy2":[[]],"piggy3":[[]],"x":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"args":["non-option-argument1"],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2","xbar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy2 another_option_for_piggy2":[[]],"piggy3":[[]],"x":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"args":["non-option-argument1","non-option-argument2"],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2","xbar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy2 another_option_for_piggy2":[[]],"piggy3":[[]],"x":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"args":["non-option-argument1","non-option-argument2","non-option-argument3"],"b":[[],[]],"bar":[["bar1","bar2","bar3"],["xbar1","xbar2","xbar3"]],"c":[[]],"d":[["argument for d"]],"foo":[["foo-one","foo-two"]],"long":[[]],"long-option":[[]],"piggy2":[["option_for_piggy2"]],"piggy2 another_option_for_piggy2":[[]],"piggy3":[[]],"x":[[]]})json"},
};
Space arguments_required;
@ -230,12 +230,12 @@ void test_mainargsparser1()
arguments_required.add(L"piggy2", 1);
size_t len = sizeof(argv) / sizeof(const char *);
test_mainargsparser(len, argv, arguments_required, output);
test_mainoptionsparser(len, argv, arguments_required, output);
}
void test_mainargsparser2()
void test_mainoptionsparser2()
{
const char * argv[] = {
"program_name",
@ -259,26 +259,26 @@ void test_mainargsparser2()
"non-option-argument4",
};
MainSpaceParserOutputTest output[] = {
{MainSpaceParser::status_ok, "", R"json({})json"},
{MainSpaceParser::status_ok, "", R"json({"long1":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"long1":[[]],"long2":[["with-argument"]]})json"},
{MainSpaceParser::status_ok, "", R"json({"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"a":[[]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "b", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[[]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "b", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"c":[[]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainSpaceParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "xxx", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[[]]})json"},
{MainSpaceParser::status_argument_not_provided, "xxx", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1"]]})json"},
{MainSpaceParser::status_argument_not_provided, "xxx", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1","arg 2"]]})json"},
{MainSpaceParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1","arg 2","arg 3"]]})json"},
{MainSpaceParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"args":["-"],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1","arg 2","arg 3"]]})json"},
{MainSpaceParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"args":["-","non-option-argument2"],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1","arg 2","arg 3"]]})json"},
{MainSpaceParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"args":["-","non-option-argument2","non-option-argument3"],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1","arg 2","arg 3"]]})json"},
{MainSpaceParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"args":["-","non-option-argument2","non-option-argument3","non-option-argument4"],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1","arg 2","arg 3"]]})json"},
MainOptionsParserOutputTest output[] = {
{MainOptionsParser::status_ok, "", R"json({})json"},
{MainOptionsParser::status_ok, "", R"json({"long1":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"long1":[[]],"long2":[["with-argument"]]})json"},
{MainOptionsParser::status_ok, "", R"json({"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"a":[[]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "b", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[[]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "b", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"c":[[]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainOptionsParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "xxx", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[[]]})json"},
{MainOptionsParser::status_argument_not_provided, "xxx", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1"]]})json"},
{MainOptionsParser::status_argument_not_provided, "xxx", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1","arg 2"]]})json"},
{MainOptionsParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1","arg 2","arg 3"]]})json"},
{MainOptionsParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"args":["-"],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1","arg 2","arg 3"]]})json"},
{MainOptionsParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"args":["-","non-option-argument2"],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1","arg 2","arg 3"]]})json"},
{MainOptionsParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"args":["-","non-option-argument2","non-option-argument3"],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1","arg 2","arg 3"]]})json"},
{MainOptionsParser::status_ok, "", R"json({"":[["option-for-empty-argument"]],"a":[[]],"args":["-","non-option-argument2","non-option-argument3","non-option-argument4"],"b":[["arg b 1","arg b 2"]],"c":[[]],"f":[[" file-name with spaces"]],"long1":[[]],"long2":[["with-argument"]],"long3":[[]],"xxx":[["arg 1","arg 2","arg 3"]]})json"},
};
Space arguments_required;
@ -289,12 +289,12 @@ void test_mainargsparser2()
arguments_required.add(L"", 1);
size_t len = sizeof(argv) / sizeof(const char *);
test_mainargsparser(len, argv, arguments_required, output);
test_mainoptionsparser(len, argv, arguments_required, output);
}
void test_mainargsparser3()
void test_mainoptionsparser3()
{
const char * argv[] = {
"program_name",
@ -303,18 +303,18 @@ void test_mainargsparser3()
"--long3",
};
MainSpaceParserOutputTest output[] = {
{MainSpaceParser::status_ok, "", R"json({})json"},
{MainSpaceParser::status_ok, "", R"json({"long1":[[]]})json"},
{MainSpaceParser::status_argument_provided, "long2", R"json({"long1":[[]]})json"},
{MainSpaceParser::status_argument_provided, "long2", R"json({"long1":[[]]})json"},
MainOptionsParserOutputTest output[] = {
{MainOptionsParser::status_ok, "", R"json({})json"},
{MainOptionsParser::status_ok, "", R"json({"long1":[[]]})json"},
{MainOptionsParser::status_argument_provided, "long2", R"json({"long1":[[]]})json"},
{MainOptionsParser::status_argument_provided, "long2", R"json({"long1":[[]]})json"},
};
Space arguments_required;
arguments_required.add(L"non-existing", 1);
size_t len = sizeof(argv) / sizeof(const char *);
test_mainargsparser(len, argv, arguments_required, output);
test_mainoptionsparser(len, argv, arguments_required, output);
}
@ -322,9 +322,9 @@ void test_mainargsparser3()
void make_tests()
{
test_mainargsparser1();
test_mainargsparser2();
test_mainargsparser3();
test_mainoptionsparser1();
test_mainoptionsparser2();
test_mainoptionsparser3();
}

@ -35,14 +35,14 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef headerfile_picotools_tests_mainargsparser
#define headerfile_picotools_tests_mainargsparser
#ifndef headerfile_picotools_tests_mainoptionsparser
#define headerfile_picotools_tests_mainoptionsparser
namespace pt
{
namespace pt_mainargsparser_tests
namespace pt_mainoptions_tests
{

Loading…
Cancel
Save