summaryrefslogtreecommitdiffstats
path: root/src/util_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/util_test.cc')
-rw-r--r--src/util_test.cc33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/util_test.cc b/src/util_test.cc
index 23d4b83..4776546 100644
--- a/src/util_test.cc
+++ b/src/util_test.cc
@@ -66,6 +66,22 @@ TEST(CanonicalizePath, PathSamples) {
path = "foo/.hidden_bar";
EXPECT_TRUE(CanonicalizePath(&path, &err));
EXPECT_EQ("foo/.hidden_bar", path);
+
+ path = "/foo";
+ EXPECT_TRUE(CanonicalizePath(&path, &err));
+ EXPECT_EQ("/foo", path);
+
+ path = "//foo";
+ EXPECT_TRUE(CanonicalizePath(&path, &err));
+#ifdef _WIN32
+ EXPECT_EQ("//foo", path);
+#else
+ EXPECT_EQ("/foo", path);
+#endif
+
+ path = "/";
+ EXPECT_TRUE(CanonicalizePath(&path, &err));
+ EXPECT_EQ("", path);
}
TEST(CanonicalizePath, EmptyResult) {
@@ -105,18 +121,18 @@ TEST(CanonicalizePath, AbsolutePath) {
TEST(CanonicalizePath, NotNullTerminated) {
string path;
string err;
- int len;
+ size_t len;
path = "foo/. bar/.";
len = strlen("foo/."); // Canonicalize only the part before the space.
EXPECT_TRUE(CanonicalizePath(&path[0], &len, &err));
- EXPECT_EQ(strlen("foo"), static_cast<size_t>(len));
+ EXPECT_EQ(strlen("foo"), len);
EXPECT_EQ("foo/. bar/.", string(path));
path = "foo/../file bar/.";
len = strlen("foo/../file");
EXPECT_TRUE(CanonicalizePath(&path[0], &len, &err));
- EXPECT_EQ(strlen("file"), static_cast<size_t>(len));
+ EXPECT_EQ(strlen("file"), len);
EXPECT_EQ("file ./file bar/.", string(path));
}
@@ -136,3 +152,14 @@ TEST(StripAnsiEscapeCodes, StripColors) {
EXPECT_EQ("affixmgr.cxx:286:15: warning: using the result... [-Wparentheses]",
stripped);
}
+
+TEST(ElideMiddle, NothingToElide) {
+ string input = "Nothing to elide in this short string.";
+ EXPECT_EQ(input, ElideMiddle(input, 80));
+}
+
+TEST(ElideMiddle, ElideInTheMiddle) {
+ string input = "01234567890123456789";
+ string elided = ElideMiddle(input, 10);
+ EXPECT_EQ("012...789", elided);
+}