<commit_before>#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>

#include <nitro/broken_options/parser.hpp>

TEST_CASE("argument class works as intended")
{
    SECTION("double dash gets parsed correctly")
    {
        nitro::broken_options::argument arg("--");

        REQUIRE(arg.is_double_dash());
    }

    SECTION("double dash does not get confised with a named argument")
    {
        nitro::broken_options::argument arg("--not-a-double-dash");

        REQUIRE(!arg.is_double_dash());
    }

    SECTION("double dash does not get confised with a short")
    {
        nitro::broken_options::argument arg("-v");

        REQUIRE(!arg.is_double_dash());
    }

    SECTION("Values get parsed as such")
    {
        nitro::broken_options::argument arg("some_value");
        REQUIRE(arg.is_value());
        REQUIRE(arg.value() == "some_value");
        REQUIRE_THROWS_AS(arg.name(), nitro::broken_options::parser_error);
    }

    SECTION("Values get not confused with named arguments")
    {
        nitro::broken_options::argument arg("--some-arg");
        REQUIRE(!arg.is_value());
    }

    SECTION("Values get not confused with short list")
    {
        nitro::broken_options::argument arg("-abcd");
        REQUIRE(!arg.is_value());
    }

    SECTION("short arguments get recognized properly")
    {
        REQUIRE(nitro::broken_options::argument("-a").is_short());
        REQUIRE(nitro::broken_options::argument("-ab").is_short());
        REQUIRE(!nitro::broken_options::argument("--ab").is_short());
        REQUIRE(!nitro::broken_options::argument("ab").is_short());
        REQUIRE(!nitro::broken_options::argument("--").is_short());
    }

    SECTION("named arguments get recognized properly")
    {
        REQUIRE(!nitro::broken_options::argument("-a").is_named());
        REQUIRE(!nitro::broken_options::argument("-ab").is_named());
        REQUIRE(nitro::broken_options::argument("--ab").is_named());
        REQUIRE(!nitro::broken_options::argument("ab").is_named());
        REQUIRE(!nitro::broken_options::argument("--").is_named());
    }

    SECTION("arguments get recognized properly")
    {
        REQUIRE(nitro::broken_options::argument("-a").is_argument());
        REQUIRE(nitro::broken_options::argument("-ab").is_argument());
        REQUIRE(nitro::broken_options::argument("--ab").is_argument());
        REQUIRE(!nitro::broken_options::argument("ab").is_argument());
        REQUIRE(!nitro::broken_options::argument("--").is_argument());
    }

    SECTION("arguments get properly parsed")
    {
        nitro::broken_options::argument short_arg("-a");
        REQUIRE(short_arg.is_argument());
        REQUIRE(short_arg.is_short());
        REQUIRE(!short_arg.is_named());
        REQUIRE(!short_arg.has_value());
        REQUIRE(short_arg.name() == "-a");
        REQUIRE_THROWS_AS(short_arg.as_named(), nitro::broken_options::parser_error);
        REQUIRE(short_arg.as_short_list().size() == 1);
        REQUIRE(short_arg.as_short_list().count("a") == 1);

        nitro::broken_options::argument named_arg("--ab");
        REQUIRE(named_arg.is_argument());
        REQUIRE(!named_arg.is_short());
        REQUIRE(named_arg.is_named());
        REQUIRE(!named_arg.has_value());
        REQUIRE(named_arg.name() == "--ab");
        REQUIRE(named_arg.as_named() == "ab");
        REQUIRE_THROWS_AS(named_arg.as_short_list(), nitro::broken_options::parser_error);

        nitro::broken_options::argument short_list("-ab");
        REQUIRE(short_list.is_argument());
        REQUIRE(short_list.is_short());
        REQUIRE(!short_list.is_named());
        REQUIRE(!short_list.has_value());
        REQUIRE(short_list.name() == "-ab");
        REQUIRE_THROWS_AS(short_list.as_named(), nitro::broken_options::parser_error);
        REQUIRE(short_list.as_short_list().size() == 2);
        REQUIRE(short_list.as_short_list().count("a") == 1);
        REQUIRE(short_list.as_short_list().count("b") == 1);
    }

    SECTION("arguments with values get properly parsed")
    {
        nitro::broken_options::argument short_arg("-a=5");
        REQUIRE(short_arg.is_argument());
        REQUIRE(short_arg.is_short());
        REQUIRE(!short_arg.is_named());
        REQUIRE(short_arg.has_value());
        REQUIRE(short_arg.value() == "5");
        REQUIRE(short_arg.name() == "-a");
        REQUIRE(short_arg.data() == "-a=5");

        nitro::broken_options::argument named_arg("--ab=5");
        REQUIRE(named_arg.is_argument());
        REQUIRE(!named_arg.is_short());
        REQUIRE(named_arg.is_named());
        REQUIRE(named_arg.has_value());
        REQUIRE(named_arg.value() == "5");
        REQUIRE(named_arg.name() == "--ab");
        REQUIRE(named_arg.data() == "--ab=5");
    }

    SECTION("Trying to break with edge cases")
    {
        nitro::broken_options::argument without_value("--ab=");

        REQUIRE(without_value.has_value());
        REQUIRE(without_value.value() == "");
        REQUIRE(without_value.as_named() == "ab");

        REQUIRE_THROWS_AS(nitro::broken_options::argument("--="),
                          nitro::broken_options::parsing_error);
    }
}

TEST_CASE("Using argc, argv from main does compile")<commit_msg>Even more edge cases in argument<commit_after>#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>

#include <nitro/broken_options/parser.hpp>

TEST_CASE("argument class works as intended")
{
    SECTION("double dash gets parsed correctly")
    {
        nitro::broken_options::argument arg("--");

        REQUIRE(arg.is_double_dash());
    }

    SECTION("double dash does not get confised with a named argument")
    {
        nitro::broken_options::argument arg("--not-a-double-dash");

        REQUIRE(!arg.is_double_dash());
    }

    SECTION("double dash does not get confised with a short")
    {
        nitro::broken_options::argument arg("-v");

        REQUIRE(!arg.is_double_dash());
    }

    SECTION("Values get parsed as such")
    {
        nitro::broken_options::argument arg("some_value");
        REQUIRE(arg.is_value());
        REQUIRE(arg.value() == "some_value");
        REQUIRE_THROWS_AS(arg.name(), nitro::broken_options::parser_error);
    }

    SECTION("Values get not confused with named arguments")
    {
        nitro::broken_options::argument arg("--some-arg");
        REQUIRE(!arg.is_value());
    }

    SECTION("Values get not confused with short list")
    {
        nitro::broken_options::argument arg("-abcd");
        REQUIRE(!arg.is_value());
    }

    SECTION("short arguments get recognized properly")
    {
        REQUIRE(nitro::broken_options::argument("-a").is_short());
        REQUIRE(nitro::broken_options::argument("-ab").is_short());
        REQUIRE(!nitro::broken_options::argument("--ab").is_short());
        REQUIRE(!nitro::broken_options::argument("ab").is_short());
        REQUIRE(!nitro::broken_options::argument("--").is_short());
    }

    SECTION("named arguments get recognized properly")
    {
        REQUIRE(!nitro::broken_options::argument("-a").is_named());
        REQUIRE(!nitro::broken_options::argument("-ab").is_named());
        REQUIRE(nitro::broken_options::argument("--ab").is_named());
        REQUIRE(!nitro::broken_options::argument("ab").is_named());
        REQUIRE(!nitro::broken_options::argument("--").is_named());
    }

    SECTION("arguments get recognized properly")
    {
        REQUIRE(nitro::broken_options::argument("-a").is_argument());
        REQUIRE(nitro::broken_options::argument("-ab").is_argument());
        REQUIRE(nitro::broken_options::argument("--ab").is_argument());
        REQUIRE(!nitro::broken_options::argument("ab").is_argument());
        REQUIRE(!nitro::broken_options::argument("--").is_argument());
    }

    SECTION("arguments get properly parsed")
    {
        nitro::broken_options::argument short_arg("-a");
        REQUIRE(short_arg.is_argument());
        REQUIRE(short_arg.is_short());
        REQUIRE(!short_arg.is_named());
        REQUIRE(!short_arg.has_value());
        REQUIRE(short_arg.name() == "-a");
        REQUIRE_THROWS_AS(short_arg.as_named(), nitro::broken_options::parser_error);
        REQUIRE(short_arg.as_short_list().size() == 1);
        REQUIRE(short_arg.as_short_list().count("a") == 1);

        nitro::broken_options::argument named_arg("--ab");
        REQUIRE(named_arg.is_argument());
        REQUIRE(!named_arg.is_short());
        REQUIRE(named_arg.is_named());
        REQUIRE(!named_arg.has_value());
        REQUIRE(named_arg.name() == "--ab");
        REQUIRE(named_arg.as_named() == "ab");
        REQUIRE_THROWS_AS(named_arg.as_short_list(), nitro::broken_options::parser_error);

        nitro::broken_options::argument short_list("-ab");
        REQUIRE(short_list.is_argument());
        REQUIRE(short_list.is_short());
        REQUIRE(!short_list.is_named());
        REQUIRE(!short_list.has_value());
        REQUIRE(short_list.name() == "-ab");
        REQUIRE_THROWS_AS(short_list.as_named(), nitro::broken_options::parser_error);
        REQUIRE(short_list.as_short_list().size() == 2);
        REQUIRE(short_list.as_short_list().count("a") == 1);
        REQUIRE(short_list.as_short_list().count("b") == 1);
    }

    SECTION("arguments with values get properly parsed")
    {
        nitro::broken_options::argument short_arg("-a=5");
        REQUIRE(short_arg.is_argument());
        REQUIRE(short_arg.is_short());
        REQUIRE(!short_arg.is_named());
        REQUIRE(short_arg.has_value());
        REQUIRE(short_arg.value() == "5");
        REQUIRE(short_arg.name() == "-a");
        REQUIRE(short_arg.data() == "-a=5");

        nitro::broken_options::argument named_arg("--ab=5");
        REQUIRE(named_arg.is_argument());
        REQUIRE(!named_arg.is_short());
        REQUIRE(named_arg.is_named());
        REQUIRE(named_arg.has_value());
        REQUIRE(named_arg.value() == "5");
        REQUIRE(named_arg.name() == "--ab");
        REQUIRE(named_arg.data() == "--ab=5");
    }

    SECTION("Trying to break with edge cases")
    {
        nitro::broken_options::argument without_value("--ab=");

        REQUIRE(without_value.has_value());
        REQUIRE(without_value.value() == "");
        REQUIRE(without_value.as_named() == "ab");

        REQUIRE_THROWS_AS(nitro::broken_options::argument("-="),
                          nitro::broken_options::parsing_error);
        REQUIRE_THROWS_AS(nitro::broken_options::argument("--="),
                          nitro::broken_options::parsing_error);
        REQUIRE_THROWS_AS(nitro::broken_options::argument("---="),
                          nitro::broken_options::parsing_error);
        REQUIRE_THROWS_AS(nitro::broken_options::argument("---ab="),
                          nitro::broken_options::parsing_error);
        REQUIRE_THROWS_AS(nitro::broken_options::argument("---a=b"),
                          nitro::broken_options::parsing_error);
        REQUIRE_THROWS_AS(nitro::broken_options::argument("---=ab"),
                          nitro::broken_options::parsing_error);
        REQUIRE_THROWS_AS(nitro::broken_options::argument("--=ab"),
                          nitro::broken_options::parsing_error);
        REQUIRE_THROWS_AS(nitro::broken_options::argument("-=ab"),
                          nitro::broken_options::parsing_error);
    }
}

TEST_CASE("Using argc, argv from main does compile")
{'fraction_non_alphanumeric': 0.17150651179162266, 'fraction_numerical': 0.0021119324181626186, 'mean_word_length': 3.3180091185410334, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4486756', 'n_tokens_mistral': 3892, 'n_tokens_neox': 3642, 'n_words': 422}