<commit_before>#include "test/test.hpp"
#include "program/options.hpp"
#include <queue>
#include <string>
#include <boost/format.hpp>

class options_test_fixture : public test::fixture {
public:
    gorc::options opts;
};

begin_suite_fixture(options_test, options_test_fixture);

test_case(load_empty_options_empty_argv)
{
    std::vector<std::string> arg_list;

    opts.load_from_arg_list(arg_list);

    assert_log_empty();
}

test_case(unknown_option_argv)
{
    std::vector<std::string> arg_list { "--bad-option" };

    assert_throws_logged(opts.load_from_arg_list(arg_list));

    assert_log_message(gorc::log_level::error,
                       "Unrecognized option --bad-option");
    assert_log_empty();
}

test_case(option_redefinition)
{
    bool a, b;
    opts.emplace<gorc::switch_option>("redefined-option", a);

    assert_throws_logged(opts.emplace<gorc::switch_option>("redefined-option", b));

    assert_log_message(gorc::log_level::error,
                       "Option redefined-option has already been defined");
    assert_log_empty();
}

test_case(name_contains_space)
{
    bool a;
    assert_throws_logged(opts.emplace<gorc::switch_option>("spaced option", a));

    assert_log_message(gorc::log_level::error,
                       "Option spaced option name cannot contain whitespace");
    assert_log_empty();
}

test_case(switch_type_set_unset)
{
    bool a;
    opts.emplace<gorc::switch_option>("user-option", a);

    assert_true(!opts.has_value("user-option"));

    std::vector<std::string> arg_list_1 { };

    opts.load_from_arg_list(arg_list_1);

    assert_true(!opts.has_value("user-option"));

    std::vector<std::string> arg_list_2 { "--user-option" };

    opts.load_from_arg_list(arg_list_2);

    assert_true(opts.has_value("user-option"));

    assert_log_empty();
}

test_case(switch_type_set_twice)
{
    bool a;
    opts.emplace<gorc::switch_option>("user-option", a);
    std::vector<std::string> arg_list { "--user-option", "--user-option" };
    opts.load_from_arg_list(arg_list);

    assert_log_message(gorc::log_level::warning,
                       "Option user-option is already set");
    assert_log_empty();
}

test_case(switch_type_get_switch)
{
    bool a;
    opts.emplace<gorc::switch_option>("user-option", a);

    auto const &sw = opts.get_option<gorc::switch_option>("user-option");
    assert_true(!sw.has_value());

    std::vector<std::string> arg_list { "--user-option" };

    opts.load_from_arg_list(arg_list);

    assert_true(sw.has_value());

    assert_log_empty();
}

test_case(switch_type_reset)
{
    bool a;
    opts.emplace<gorc::switch_option>("user-option", a);

    std::vector<std::string> arg_list_1 { "--user-option" };
    opts.load_from_arg_list(arg_list_1);
    assert_true(opts.has_value("user-option"));

    std::vector<std::string> arg_list_2;
    opts.load_from_arg_list(arg_list_2);<commit_msg>Fixing test failures due to uninitialized variables<commit_after>#include "test/test.hpp"
#include "program/options.hpp"
#include <queue>
#include <string>
#include <boost/format.hpp>

class options_test_fixture : public test::fixture {
public:
    gorc::options opts;
};

begin_suite_fixture(options_test, options_test_fixture);

test_case(load_empty_options_empty_argv)
{
    std::vector<std::string> arg_list;

    opts.load_from_arg_list(arg_list);

    assert_log_empty();
}

test_case(unknown_option_argv)
{
    std::vector<std::string> arg_list { "--bad-option" };

    assert_throws_logged(opts.load_from_arg_list(arg_list));

    assert_log_message(gorc::log_level::error,
                       "Unrecognized option --bad-option");
    assert_log_empty();
}

test_case(option_redefinition)
{
    bool a = false, b = false;
    opts.emplace<gorc::switch_option>("redefined-option", a);

    assert_throws_logged(opts.emplace<gorc::switch_option>("redefined-option", b));

    assert_log_message(gorc::log_level::error,
                       "Option redefined-option has already been defined");
    assert_log_empty();
}

test_case(name_contains_space)
{
    bool a = false;
    assert_throws_logged(opts.emplace<gorc::switch_option>("spaced option", a));

    assert_log_message(gorc::log_level::error,
                       "Option spaced option name cannot contain whitespace");
    assert_log_empty();
}

test_case(switch_type_set_unset)
{
    bool a;
    opts.emplace<gorc::switch_option>("user-option", a);

    std::vector<std::string> arg_list_1 { };

    opts.load_from_arg_list(arg_list_1);

    assert_true(!opts.has_value("user-option"));

    std::vector<std::string> arg_list_2 { "--user-option" };

    opts.load_from_arg_list(arg_list_2);

    assert_true(opts.has_value("user-option"));

    assert_log_empty();
}

test_case(switch_type_orig_false)
{
    bool a = false;
    opts.emplace<gorc::switch_option>("user-option", a);

    assert_true(!opts.has_value("user-option"));
}

test_case(switch_type_overrides_true)
{
    bool a = true;
    opts.emplace<gorc::switch_option>("user-option", a);

    assert_true(opts.has_value("user-option"));

    std::vector<std::string> arg_list { };

    opts.load_from_arg_list(arg_list);

    assert_true(!opts.has_value("user-option"));
    assert_log_empty();
}

test_case(switch_type_set_twice)
{
    bool a = false;
    opts.emplace<gorc::switch_option>("user-option", a);
    std::vector<std::string> arg_list { "--user-option", "--user-option" };
    opts.load_from_arg_list(arg_list);

    assert_log_message(gorc::log_level::warning,
                       "Option user-option is already set");
    assert_log_empty();
}

test_case(switch_type_get_switch)
{
    bool a = false;
    opts.emplace<gorc::switch_option>("user-option", a);

    auto const &sw = opts.get_option<gorc::switch_option>("user-option");
    assert_true(!sw.has_value());

    std::vector<std::string> arg_list { "--user-option" };

    opts.load_from_arg_list(arg_list);

    assert_true(sw.has_value());

    assert_log_empty();
}

test_case(switch_type_reset)
{
    bool a;
    opts.emplace<gorc::switch_option>("user-option", a);

    std::vector<std::string> arg_list_1 { "--user-option" };
    opts.load_from_arg_list(arg_list_1);
    assert_true(opts.has_value("user-option"));

    std::vector<std::string> arg_list_2;
    opts.load_from_arg_list(arg_list_2);
{'fraction_non_alphanumeric': 0.14702154626108999, 'fraction_numerical': 0.0025348542458808617, 'mean_word_length': 4.414236706689537, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1358986', 'n_tokens_mistral': 2255, 'n_tokens_neox': 2212, 'n_words': 284}