24 EXPECT_EQ(
"empty path", err);
26 path =
"foo.h"; err =
"";
28 EXPECT_EQ(
"foo.h", path);
32 EXPECT_EQ(
"foo.h", path);
34 path =
"./foo/./bar.h";
36 EXPECT_EQ(
"foo/bar.h", path);
38 path =
"./x/foo/../bar.h";
40 EXPECT_EQ(
"x/bar.h", path);
42 path =
"./x/foo/../../bar.h";
44 EXPECT_EQ(
"bar.h", path);
48 EXPECT_EQ(
"foo/bar", path);
50 path =
"foo//.//..///bar";
52 EXPECT_EQ(
"bar", path);
54 path =
"./x/../foo/../../bar.h";
56 EXPECT_EQ(
"../bar.h", path);
60 EXPECT_EQ(
"foo", path);
64 EXPECT_EQ(
"foo", path);
66 path =
"foo/.hidden_bar";
68 EXPECT_EQ(
"foo/.hidden_bar", path);
72 EXPECT_EQ(
"/foo", path);
77 EXPECT_EQ(
"//foo", path);
79 EXPECT_EQ(
"/foo", path);
92 EXPECT_EQ(
"empty path", err);
96 EXPECT_EQ(
"path canonicalizes to the empty path", err);
100 EXPECT_EQ(
"path canonicalizes to the empty path", err);
105 path =
"../../foo/bar.h";
107 EXPECT_EQ(
"../../foo/bar.h", path);
109 path =
"test/../../foo/bar.h";
111 EXPECT_EQ(
"../foo/bar.h", path);
115 string path =
"/usr/include/stdio.h";
118 EXPECT_EQ(
"/usr/include/stdio.h", path);
126 path =
"foo/. bar/.";
127 len = strlen(
"foo/.");
129 EXPECT_EQ(strlen(
"foo"), len);
130 EXPECT_EQ(
"foo/. bar/.",
string(path));
132 path =
"foo/../file bar/.";
133 len = strlen(
"foo/../file");
135 EXPECT_EQ(strlen(
"file"), len);
136 EXPECT_EQ(
"file ./file bar/.",
string(path));
139 TEST(PathEscaping, TortureTest) {
143 EXPECT_EQ(
"\"foo bar\\\\\\\"'$@d!st!c'\\path'\\\\\"", result);
147 EXPECT_EQ(
"'foo bar\"/'\\''$@d!st!c'\\''/path'\\'''", result);
150 TEST(PathEscaping, SensiblePathsAreNotNeedlesslyEscaped) {
151 const char* path =
"some/sensible/path/without/crazy/characters.c++";
155 EXPECT_EQ(path, result);
159 EXPECT_EQ(path, result);
162 TEST(PathEscaping, SensibleWin32PathsAreNotNeedlesslyEscaped) {
163 const char* path =
"some\\sensible\\path\\without\\crazy\\characters.c++";
167 EXPECT_EQ(path, result);
172 EXPECT_EQ(
"foo", stripped);
175 EXPECT_EQ(
"foo", stripped);
180 string input =
"\33[1maffixmgr.cxx:286:15: \33[0m\33[0;1;35mwarning: "
181 "\33[0m\33[1musing the result... [-Wparentheses]\33[0m";
183 EXPECT_EQ(
"affixmgr.cxx:286:15: warning: using the result... [-Wparentheses]",
188 string input =
"Nothing to elide in this short string.";
193 string input =
"01234567890123456789";
195 EXPECT_EQ(
"012...789", elided);
void GetWin32EscapedString(const string &input, string *result)
void GetShellEscapedString(const string &input, string *result)
Appends |input| to |*result|, escaping according to the whims of either Bash, or Win32's CommandLineT...
bool CanonicalizePath(string *path, string *err)
Canonicalize a path like "foo/../bar.h" into just "bar.h".
TEST(CanonicalizePath, PathSamples)
string StripAnsiEscapeCodes(const string &in)
Removes all Ansi escape codes (http://www.termsys.demon.co.uk/vtansi.htm).
string ElideMiddle(const string &str, size_t width)
Elide the given string str with '...' in the middle if the length exceeds width.