#pragma GCC diagnostic ignored "-Wwrite-strings"

#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <myapp/cmdargs/options.h>
#include <myapp/cmdargs/errors.h>

using namespace ::testing;
using namespace myapp::cmdargs;

extern const char *__progname;

class OptionsTests : public Test
{

};

TEST_F(OptionsTests, ShowHelp)
{
    auto help = options::list_all();
    EXPECT_THAT(help, ContainsRegex("\\s+(-C)\\s+"));
    EXPECT_THAT(help, ContainsRegex("\\s+(-f)\\s+"));
}

TEST_F(OptionsTests, ValidConfiguration_SetsOptionsConfig)
{
    char* argv[] = {
        const_cast<char*>(__progname),
        "-C", "/dev/null",
    };

    auto options = options::parse_arguments(std::size(argv), argv);

    ASSERT_THAT(options.config, StrEq("/dev/null"));
}

TEST_F(OptionsTests, NonExistingConfiguration_Throws)
{
    char* argv[] = {
        const_cast<char*>(__progname),
        "-C", "/dev/nonexistent",
    };

    ASSERT_THROW({
        options::parse_arguments(std::size(argv), argv);
    }, reading_file);
}

TEST_F(OptionsTests, MissingConfigurationValue_Throws)
{
    char* argv[] = {
        const_cast<char*>(__progname),
        "-C",
    };

    ASSERT_THROW({
        options::parse_arguments(std::size(argv), argv);
    }, invalid_option_value);
}

TEST_F(OptionsTests, UnknownParameter_Throws)
{
    char* argv[] = {
        const_cast<char*>(__progname),
        "-\\",
    };

    ASSERT_THROW({
        options::parse_arguments(std::size(argv), argv);
    }, unknown_option);
}
