1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 20:23:55 +00:00
CLI11/tests/StringParseTest.cpp
Henry Schreiner f932b51374
Touchupwin (#189)
* Move lambda funtion to real function

* Fix some warnings when compiling in LLVM

* Adding one test back in

* Adding details to changelog
2019-01-11 11:58:00 +01:00

76 lines
2.1 KiB
C++

#include "app_helper.hpp"
#include "gmock/gmock.h"
#include <cstdio>
#include <sstream>
TEST_F(TApp, ExistingExeCheck) {
TempFile tmpexe{"existingExe.out"};
std::string str, str2, str3;
app.add_option("-s,--string", str);
app.add_option("-t,--tstr", str2);
app.add_option("-m,--mstr", str3);
{
std::ofstream out{tmpexe};
out << "useless string doesn't matter" << std::endl;
}
app.parse(std::string("./") + std::string(tmpexe) +
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
true);
EXPECT_EQ(str, "this is my quoted string");
EXPECT_EQ(str2, "qstring 2");
EXPECT_EQ(str3, "\"quoted string\"");
}
TEST_F(TApp, ExistingExeCheckWithSpace) {
TempFile tmpexe{"Space File.out"};
std::string str, str2, str3;
app.add_option("-s,--string", str);
app.add_option("-t,--tstr", str2);
app.add_option("-m,--mstr", str3);
{
std::ofstream out{tmpexe};
out << "useless string doesn't matter" << std::endl;
}
app.parse(std::string("./") + std::string(tmpexe) +
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
true);
EXPECT_EQ(str, "this is my quoted string");
EXPECT_EQ(str2, "qstring 2");
EXPECT_EQ(str3, "\"quoted string\"");
EXPECT_EQ(app.get_name(), std::string("./") + std::string(tmpexe));
}
TEST_F(TApp, ExistingExeCheckWithLotsOfSpace) {
TempFile tmpexe{"this is a weird file.exe"};
std::string str, str2, str3;
app.add_option("-s,--string", str);
app.add_option("-t,--tstr", str2);
app.add_option("-m,--mstr", str3);
{
std::ofstream out{tmpexe};
out << "useless string doesn't matter" << std::endl;
}
app.parse(std::string("./") + std::string(tmpexe) +
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
true);
EXPECT_EQ(str, "this is my quoted string");
EXPECT_EQ(str2, "qstring 2");
EXPECT_EQ(str3, "\"quoted string\"");
EXPECT_EQ(app.get_name(), std::string("./") + std::string(tmpexe));
}