#include #include "gtest/gtest.h" #include #include #include "UserOpt.hpp" TEST(UserOpt, compress) { using namespace xwim; // clang-format off char* args[] = { const_cast("xwim"), const_cast("-c"), const_cast("mandator_paths"), nullptr}; // clang-format on UserOpt uo = UserOpt{3, args}; ASSERT_TRUE(uo.compress); ASSERT_FALSE(uo.extract); } TEST(UserOpt, exclusive_actions) { using namespace xwim; // clang-format off char* args[] = { const_cast("xwim"), const_cast("-c"), const_cast("-x"), const_cast("mandatory_paths"), nullptr}; // clang-format on UserOpt uo = UserOpt{4, args}; ASSERT_TRUE(uo.compress); ASSERT_TRUE(uo.extract); } TEST(UserOpt, whitespace_in_path) { using namespace xwim; // clang-format off char* args[] = { const_cast("xwim"), const_cast("-c"), const_cast("/foo/bar baz/a file"), nullptr}; // clang-format on UserOpt uo = UserOpt{3, args}; ASSERT_TRUE(uo.paths.find(std::filesystem::path("/foo/bar baz/a file")) != uo.paths.end()); } TEST(UserOpt, mixed_output_and_paths) { using namespace xwim; // clang-format off char* args[] = { const_cast("xwim"), const_cast("-o"), const_cast("/foo/bar baz/output"), const_cast("/foo/bar baz/a path"), const_cast("/foo/bar baz/another path"), nullptr}; // clang-format on UserOpt uo = UserOpt{5, args}; ASSERT_TRUE(uo.paths.find(std::filesystem::path("/foo/bar baz/a path")) != uo.paths.end()); ASSERT_TRUE(uo.paths.find(std::filesystem::path("/foo/bar baz/another path")) != uo.paths.end()); ASSERT_TRUE(uo.out == std::filesystem::path("/foo/bar baz/output")); } TEST(UserOpt, output_defaults_to_nullopt) { using namespace xwim; // clang-format off char* args[] = { const_cast("xwim"), const_cast("/foo/bar"), nullptr}; // clang-format on UserOpt uo = UserOpt{2, args}; ASSERT_FALSE(uo.out); }