Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / utility / tests / stringutil.cpp
index ac3942738c1cebd76ea4649700735508193fcb8c..dcdc5cba0c7553cf641afc1faf01f724e97c482f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_utility
  */
+#include "gmxpre.h"
+
+#include "gromacs/utility/stringutil.h"
+
 #include <string>
 #include <vector>
 
+#include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
-#include "gromacs/utility/stringutil.h"
-
 #include "testutils/refdata.h"
 #include "testutils/stringtest.h"
 
@@ -60,7 +63,7 @@ namespace
  * Tests for simple string utilities
  */
 
-TEST(StringUtilityTest, StartsWithWorks)
+TEST(StringUtilityTest, StartsWith)
 {
     EXPECT_TRUE(gmx::startsWith("foobar", "foo"));
     EXPECT_TRUE(gmx::startsWith("foobar", ""));
@@ -76,7 +79,7 @@ TEST(StringUtilityTest, StartsWithWorks)
     EXPECT_FALSE(gmx::startsWith(std::string("foobar"), "oob"));
 }
 
-TEST(StringUtilityTest, EndsWithWorks)
+TEST(StringUtilityTest, EndsWith)
 {
     EXPECT_TRUE(gmx::endsWith("foobar", "bar"));
     EXPECT_TRUE(gmx::endsWith("foobar", NULL));
@@ -98,6 +101,29 @@ TEST(StringUtilityTest, StripSuffixIfPresent)
     EXPECT_EQ("foobar", gmx::stripSuffixIfPresent("foobar", "foofoobar"));
 }
 
+TEST(StringUtilityTest, StripString)
+{
+    EXPECT_EQ("", gmx::stripString(""));
+    EXPECT_EQ("foo", gmx::stripString("foo"));
+    EXPECT_EQ("foo", gmx::stripString("  foo"));
+    EXPECT_EQ("foo", gmx::stripString("foo "));
+    EXPECT_EQ("f o o", gmx::stripString(" f o o  "));
+}
+
+TEST(StringUtilityTest, SplitString)
+{
+    using ::testing::ElementsAre;
+    using ::testing::IsEmpty;
+    using ::testing::Matcher;
+    Matcher<std::vector<std::string> > matcher = ElementsAre("foo", "bar");
+    EXPECT_THAT(gmx::splitString("foo bar"), matcher);
+    EXPECT_THAT(gmx::splitString("  foo bar"), matcher);
+    EXPECT_THAT(gmx::splitString("foo bar  "), matcher);
+    EXPECT_THAT(gmx::splitString(" foo \t bar  "), matcher);
+    EXPECT_THAT(gmx::splitString(""), IsEmpty());
+    EXPECT_THAT(gmx::splitString("   "), IsEmpty());
+}
+
 /********************************************************************
  * Tests for formatString()
  */