when processing quoted strings, the quotes need to be removed

This commit is contained in:
Axel Kohlmeyer
2020-07-17 10:08:46 -04:00
parent a0bfe932b5
commit cdbcacffce
2 changed files with 28 additions and 12 deletions

View File

@ -21,13 +21,14 @@
#include <vector>
using namespace LAMMPS_NS;
using ::testing::Eq;
using ::testing::EndsWith;
using ::testing::Eq;
using ::testing::StrEq;
TEST(Utils, trim_comment)
{
auto trimmed = utils::trim_comment("some text # comment");
ASSERT_THAT(trimmed, Eq("some text "));
ASSERT_THAT(trimmed, StrEq("some text "));
}
TEST(Utils, count_words)
@ -59,24 +60,36 @@ TEST(Utils, split_words_simple)
{
std::vector<std::string> list = utils::split_words("one two three");
ASSERT_EQ(list.size(), 3);
ASSERT_THAT(list[0], StrEq("one"));
ASSERT_THAT(list[1], StrEq("two"));
ASSERT_THAT(list[2], StrEq("three"));
}
TEST(Utils, split_words_quoted)
{
std::vector<std::string> list = utils::split_words("one 'two' \"three\"");
ASSERT_EQ(list.size(), 3);
ASSERT_THAT(list[0], StrEq("one"));
ASSERT_THAT(list[1], StrEq("two"));
ASSERT_THAT(list[2], StrEq("three"));
}
TEST(Utils, split_words_escaped)
{
std::vector<std::string> list = utils::split_words("1\\' '\"two\"' 3\\\"");
ASSERT_EQ(list.size(), 3);
ASSERT_THAT(list[0], StrEq("1\\'"));
ASSERT_THAT(list[1], StrEq("\"two\""));
ASSERT_THAT(list[2], StrEq("3\\\""));
}
TEST(Utils, split_words_quote_in_quoted)
{
std::vector<std::string> list = utils::split_words("one 't\\'wo' \"th\\\"ree\"");
ASSERT_EQ(list.size(), 3);
ASSERT_THAT(list[0], StrEq("one"));
ASSERT_THAT(list[1], StrEq("t\\'wo"));
ASSERT_THAT(list[2], StrEq("th\\\"ree"));
}
TEST(Utils, valid_integer1)
@ -334,13 +347,13 @@ TEST(Utils, strmatch_whitespace_nonwhitespace)
TEST(Utils, guesspath)
{
char buf[256];
FILE *fp = fopen("test_guesspath.txt","w");
FILE *fp = fopen("test_guesspath.txt", "w");
#if defined(__linux__)
const char *path = utils::guesspath(buf,sizeof(buf),fp);
ASSERT_THAT(path,EndsWith("test_guesspath.txt"));
const char *path = utils::guesspath(buf, sizeof(buf), fp);
ASSERT_THAT(path, EndsWith("test_guesspath.txt"));
#else
const char *path = utils::guesspath(buf,sizeof(buf),fp);
ASSERT_THAT(path,EndsWith("(unknown)"));
const char *path = utils::guesspath(buf, sizeof(buf), fp);
ASSERT_THAT(path, EndsWith("(unknown)"));
#endif
fclose(fp);
}