35 path =
"foo.h"; err =
"";
43 path =
"./foo/./bar.h";
47 path =
"./x/foo/../bar.h";
51 path =
"./x/foo/../../bar.h";
59 path =
"foo//.//..///bar";
63 path =
"./x/../foo/../../bar.h";
75 path =
"foo/.hidden_bar";
120 path =
"foo.h"; err =
"";
128 path =
".\\foo\\.\\bar.h";
132 path =
".\\x\\foo\\..\\bar.h";
136 path =
".\\x\\foo\\..\\..\\bar.h";
144 path =
"foo\\\\.\\\\..\\\\\\bar";
148 path =
".\\x\\..\\foo\\..\\..\\bar.h";
156 path =
"foo\\bar\\..";
160 path =
"foo\\.hidden_bar";
182 path =
"foo.h"; err =
"";
192 path =
"a/bcd/efh\\foo.h";
197 path =
"a\\bcd/efh\\foo.h";
202 path =
"a\\bcd\\efh\\foo.h";
207 path =
"a/bcd/efh/foo.h";
212 path =
"a\\./efh\\foo.h";
217 path =
"a\\../efh\\foo.h";
222 path =
"a\\b\\c\\d\\e\\f\\g\\foo.h";
227 path =
"a\\b\\c\\..\\..\\..\\g\\foo.h";
232 path =
"a\\b/c\\../../..\\g\\foo.h";
237 path =
"a\\b/c\\./../..\\g\\foo.h";
242 path =
"a\\b/c\\./../..\\g/foo.h";
247 path =
"a\\\\\\foo.h";
252 path =
"a/\\\\foo.h";
265 char buf[] =
"foo/bar\\baz.h\\";
270 EXPECT_EQ(0, strncmp(
"foo/bar/baz.h", buf, size));
280 path =
"a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./" 281 "a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./x.h";
287 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\" 288 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\" 289 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\" 290 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\x.h";
297 path =
"a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./" 298 "a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./a/./x/y.h";
305 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\" 306 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\" 307 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\" 308 "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\x\\y.h";
315 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/" 316 "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";
317 EXPECT_EQ(58, std::count(path.begin(), path.end(),
'/'));
324 "a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\" 325 "a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\" 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\\x\\y.h";
328 EXPECT_EQ(58, std::count(path.begin(), path.end(),
'\\'));
330 EXPECT_EQ(slash_bits, 0x3ffffffffffffff);
336 path =
"../../foo/bar.h";
340 path =
"test/../../foo/bar.h";
346 string path =
"/usr/include/stdio.h";
358 path =
"foo/. bar/.";
359 len = strlen(
"foo/.");
364 path =
"foo/../file bar/.";
365 len = strlen(
"foo/../file");
368 EXPECT_EQ(
"file ./file bar/.",
string(path));
371 TEST(PathEscaping, TortureTest) {
375 EXPECT_EQ(
"\"foo bar\\\\\\\"'$@d!st!c'\\path'\\\\\"", result);
379 EXPECT_EQ(
"'foo bar\"/'\\''$@d!st!c'\\''/path'\\'''", result);
382 TEST(PathEscaping, SensiblePathsAreNotNeedlesslyEscaped) {
383 const char* path =
"some/sensible/path/without/crazy/characters.c++";
394 TEST(PathEscaping, SensibleWin32PathsAreNotNeedlesslyEscaped) {
395 const char* path =
"some\\sensible\\path\\without\\crazy\\characters.c++";
412 string input =
"\33[1maffixmgr.cxx:286:15: \33[0m\33[0;1;35mwarning: " 413 "\33[0m\33[1musing the result... [-Wparentheses]\33[0m";
415 EXPECT_EQ(
"affixmgr.cxx:286:15: warning: using the result... [-Wparentheses]",
420 string input =
"Nothing to elide in this short string.";
426 string input =
"01234567890123456789";
bool CanonicalizePath(string *path, uint64_t *slash_bits, string *err)
Canonicalize a path like "foo/../bar.h" into just "bar.h".
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...
TEST(CanonicalizePath, PathSamples)
string StripAnsiEscapeCodes(const string &in)
Removes all Ansi escape codes (http://www.termsys.demon.co.uk/vtansi.htm).
unsigned long long uint64_t
string ElideMiddle(const string &str, size_t width)
Elide the given string str with '...' in the middle if the length exceeds width.