apply utils::is_type() to labelmap command

This commit is contained in:
Axel Kohlmeyer
2022-09-03 23:26:56 -04:00
parent ca6222c12b
commit 389c87ab7e
2 changed files with 8 additions and 7 deletions

View File

@ -142,9 +142,8 @@ void LabelMap::modify_lmap(int narg, char **arg)
if ((itype < 1) || (itype > ntypes)) if ((itype < 1) || (itype > ntypes))
error->all(FLERR, "Labelmap {} type {} must be within 1-{}", tlabel, itype, ntypes); error->all(FLERR, "Labelmap {} type {} must be within 1-{}", tlabel, itype, ntypes);
std::string slabel = utils::trim(arg[iarg++]); std::string slabel = utils::trim(arg[iarg++]);
if (isdigit(slabel[0]) || (slabel[0] == '#') || (slabel[0] == '*')) if (utils::is_type(slabel) != 1)
error->all(FLERR, "Label {} for {} type {} must not start with a number, a '#', or a '*'", error->all(FLERR, "Type label string {} for {} type {} is invalid", slabel, tlabel, itype);
slabel, tlabel, itype);
int found = search(slabel, (*labels_map)); int found = search(slabel, (*labels_map));
if ((found != -1) && (found != itype)) if ((found != -1) && (found != itype))
error->all(FLERR, "The {} type label {} is already in use for type {}", tlabel, slabel, error->all(FLERR, "The {} type label {} is already in use for type {}", tlabel, slabel,

View File

@ -105,7 +105,7 @@ TEST_F(SetTest, NoBoxAtoms)
ASSERT_FALSE(atom->lmap->is_complete(Atom::ATOM)); ASSERT_FALSE(atom->lmap->is_complete(Atom::ATOM));
BEGIN_HIDE_OUTPUT(); BEGIN_HIDE_OUTPUT();
command("labelmap atom 1 C1 2 N2 3 'O#' 1 C1 4 H# 2 N3"); // second '#' starts comment command("labelmap atom 1 C1 2 N2 3 ' O#' 1 C1 4 H# 2 N3"); // second '#' starts comment
END_HIDE_OUTPUT(); END_HIDE_OUTPUT();
ASSERT_TRUE(atom->lmap->is_complete(Atom::ATOM)); ASSERT_TRUE(atom->lmap->is_complete(Atom::ATOM));
ASSERT_EQ(atom->lmap->find("C1", Atom::ATOM), 1); ASSERT_EQ(atom->lmap->find("C1", Atom::ATOM), 1);
@ -117,11 +117,13 @@ TEST_F(SetTest, NoBoxAtoms)
command("labelmap atom 0 C1");); command("labelmap atom 0 C1"););
TEST_FAILURE(".*ERROR: Labelmap atom type 5 must be within 1-4.*", TEST_FAILURE(".*ERROR: Labelmap atom type 5 must be within 1-4.*",
command("labelmap atom 5 C1");); command("labelmap atom 5 C1"););
TEST_FAILURE(".*ERROR: Label 1C for atom type 1 must not start with a number.*", TEST_FAILURE(".*ERROR: Type label string 1C for atom type 1 is invalid.*",
command("labelmap atom 1 1C");); command("labelmap atom 1 1C"););
TEST_FAILURE(".*ERROR: Label #C for atom type 1 must not start with a number, a '#', or.*", TEST_FAILURE(".*ERROR: Type label string #C for atom type 1 is invalid.*",
command("labelmap atom 1 '#C'");); command("labelmap atom 1 '#C'"););
TEST_FAILURE(".*ERROR: Label \\*C for atom type 1 must not start with a number, a '#', or.*", TEST_FAILURE(".*ERROR: Type label string CA CB for atom type 1 is invalid.*",
command("labelmap atom 1 ' CA CB '"););
TEST_FAILURE(".*ERROR: Type label string \\*C for atom type 1 is invalid.*",
command("labelmap atom 1 *C");); command("labelmap atom 1 *C"););
TEST_FAILURE(".*ERROR: The atom type label N2 is already in use for type 2.*", TEST_FAILURE(".*ERROR: The atom type label N2 is already in use for type 2.*",
command("labelmap atom 1 N2");); command("labelmap atom 1 N2"););