37 path =
"foo.h"; err =
"";
45 path =
"./foo/./bar.h";
49 path =
"./x/foo/../bar.h";
53 path =
"./x/foo/../../bar.h";
61 path =
"foo//.//..///bar";
65 path =
"./x/../foo/../../bar.h";
77 path =
"foo/.hidden_bar";
122 path =
"foo.h"; err =
"";
130 path =
".\\foo\\.\\bar.h";
134 path =
".\\x\\foo\\..\\bar.h";
138 path =
".\\x\\foo\\..\\..\\bar.h";
146 path =
"foo\\\\.\\\\..\\\\\\bar";
150 path =
".\\x\\..\\foo\\..\\..\\bar.h";
158 path =
"foo\\bar\\..";
162 path =
"foo\\.hidden_bar";
184 path =
"foo.h"; err =
"";
194 path =
"a/bcd/efh\\foo.h";
199 path =
"a\\bcd/efh\\foo.h";
204 path =
"a\\bcd\\efh\\foo.h";
209 path =
"a/bcd/efh/foo.h";
214 path =
"a\\./efh\\foo.h";
219 path =
"a\\../efh\\foo.h";
224 path =
"a\\b\\c\\d\\e\\f\\g\\foo.h";
229 path =
"a\\b\\c\\..\\..\\..\\g\\foo.h";
234 path =
"a\\b/c\\../../..\\g\\foo.h";
239 path =
"a\\b/c\\./../..\\g\\foo.h";
244 path =
"a\\b/c\\./../..\\g/foo.h";
249 path =
"a\\\\\\foo.h";
254 path =
"a/\\\\foo.h";
267 char buf[] =
"foo/bar\\baz.h\\";
272 EXPECT_EQ(0, strncmp(
"foo/bar/baz.h", buf, size));
282 path =
"a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./" 283 "a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./x.h";
289 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\" 290 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\" 291 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\" 292 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\x.h";
299 path =
"a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./" 300 "a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./x/y.h";
307 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\" 308 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\" 309 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\" 310 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\x\\y.h";
317 path =
"a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/" 318 "a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/x/y.h";
319 EXPECT_EQ(58, std::count(path.begin(), path.end(),
'/'));
326 "a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\" 327 "a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\" 328 "a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\" 329 "a\\a\\a\\a\\a\\a\\a\\a\\a\\x\\y.h";
330 EXPECT_EQ(58, std::count(path.begin(), path.end(),
'\\'));
332 EXPECT_EQ(slash_bits, 0x3ffffffffffffff);
338 path =
"../../foo/bar.h";
342 path =
"test/../../foo/bar.h";
348 string path =
"/usr/include/stdio.h";
360 path =
"foo/. bar/.";
361 len = strlen(
"foo/.");
366 path =
"foo/../file bar/.";
367 len = strlen(
"foo/../file");
370 EXPECT_EQ(
"file ./file bar/.",
string(path));
373 TEST(PathEscaping, TortureTest) {
377 EXPECT_EQ(
"\"foo bar\\\\\\\"'$@d!st!c'\\path'\\\\\"", result);
381 EXPECT_EQ(
"'foo bar\"/'\\''$@d!st!c'\\''/path'\\'''", result);
384 TEST(PathEscaping, SensiblePathsAreNotNeedlesslyEscaped) {
385 const char* path =
"some/sensible/path/without/crazy/characters.c++";
396 TEST(PathEscaping, SensibleWin32PathsAreNotNeedlesslyEscaped) {
397 const char* path =
"some\\sensible\\path\\without\\crazy\\characters.c++";
414 string input =
"\33[1maffixmgr.cxx:286:15: \33[0m\33[0;1;35mwarning: " 415 "\33[0m\33[1musing the result... [-Wparentheses]\33[0m";
417 EXPECT_EQ(
"affixmgr.cxx:286:15: warning: using the result... [-Wparentheses]",
422 string input =
"Nothing to elide in this short string.";
432 string input =
"01234567890123456789";
bool CanonicalizePath(string *path, uint64_t *slash_bits, string *err)
void GetWin32EscapedString(const string &input, string *result)
void GetShellEscapedString(const string &input, string *result)
TEST(CanonicalizePath, PathSamples)
string StripAnsiEscapeCodes(const string &in)
unsigned long long uint64_t
string ElideMiddle(const string &str, size_t width)