@@ -1256,6 +1256,71 @@ void simplifyPath()
12561256 ASSERT_EQUALS (" ../1.c" , simplecpp::simplifyPath (" ../a/../1.c" ));
12571257 ASSERT_EQUALS (" /../1.c" , simplecpp::simplifyPath (" /../1.c" ));
12581258 ASSERT_EQUALS (" /../1.c" , simplecpp::simplifyPath (" /../a/../1.c" ));
1259+
1260+ ASSERT_EQUALS (" a/..b/1.c" , simplecpp::simplifyPath (" a/..b/1.c" ));
1261+ ASSERT_EQUALS (" ../../1.c" , simplecpp::simplifyPath (" ../../1.c" ));
1262+ ASSERT_EQUALS (" ../../../1.c" , simplecpp::simplifyPath (" ../../../1.c" ));
1263+ ASSERT_EQUALS (" ../../../1.c" , simplecpp::simplifyPath (" ../../../a/../1.c" ));
1264+ ASSERT_EQUALS (" ../../1.c" , simplecpp::simplifyPath (" a/../../../1.c" ));
1265+ }
1266+
1267+ // tests transferred from cppcheck
1268+ // https://github.com/danmar/cppcheck/blob/d3e79b71b5ec6e641ca3e516cfced623b27988af/test/testpath.cpp#L43
1269+ void simplifyPath_cppcheck ()
1270+ {
1271+ ASSERT_EQUALS (" index.h" , simplecpp::simplifyPath (" index.h" ));
1272+ ASSERT_EQUALS (" index.h" , simplecpp::simplifyPath (" ./index.h" ));
1273+ ASSERT_EQUALS (" index.h" , simplecpp::simplifyPath (" .//index.h" ));
1274+ ASSERT_EQUALS (" index.h" , simplecpp::simplifyPath (" .///index.h" ));
1275+ ASSERT_EQUALS (" /index.h" , simplecpp::simplifyPath (" /index.h" ));
1276+ ASSERT_EQUALS (" /path/" , simplecpp::simplifyPath (" /path/" ));
1277+ ASSERT_EQUALS (" /" , simplecpp::simplifyPath (" /" ));
1278+ ASSERT_EQUALS (" /" , simplecpp::simplifyPath (" /." ));
1279+ ASSERT_EQUALS (" /" , simplecpp::simplifyPath (" /./" ));
1280+ ASSERT_EQUALS (" /index.h" , simplecpp::simplifyPath (" /./index.h" ));
1281+ ASSERT_EQUALS (" /" , simplecpp::simplifyPath (" /.//" ));
1282+ ASSERT_EQUALS (" /index.h" , simplecpp::simplifyPath (" /.//index.h" ));
1283+ ASSERT_EQUALS (" ../index.h" , simplecpp::simplifyPath (" ../index.h" ));
1284+ ASSERT_EQUALS (" /index.h" , simplecpp::simplifyPath (" /path/../index.h" ));
1285+ ASSERT_EQUALS (" index.h" , simplecpp::simplifyPath (" ./path/../index.h" ));
1286+ ASSERT_EQUALS (" index.h" , simplecpp::simplifyPath (" path/../index.h" ));
1287+ ASSERT_EQUALS (" /index.h" , simplecpp::simplifyPath (" /path//../index.h" ));
1288+ ASSERT_EQUALS (" index.h" , simplecpp::simplifyPath (" ./path//../index.h" ));
1289+ ASSERT_EQUALS (" index.h" , simplecpp::simplifyPath (" path//../index.h" ));
1290+ ASSERT_EQUALS (" /index.h" , simplecpp::simplifyPath (" /path/..//index.h" ));
1291+ ASSERT_EQUALS (" index.h" , simplecpp::simplifyPath (" ./path/..//index.h" ));
1292+ ASSERT_EQUALS (" index.h" , simplecpp::simplifyPath (" path/..//index.h" ));
1293+ ASSERT_EQUALS (" /index.h" , simplecpp::simplifyPath (" /path//..//index.h" ));
1294+ ASSERT_EQUALS (" index.h" , simplecpp::simplifyPath (" ./path//..//index.h" ));
1295+ ASSERT_EQUALS (" index.h" , simplecpp::simplifyPath (" path//..//index.h" ));
1296+ ASSERT_EQUALS (" /index.h" , simplecpp::simplifyPath (" /path/../other/../index.h" ));
1297+ ASSERT_EQUALS (" /index.h" , simplecpp::simplifyPath (" /path/../other///././../index.h" ));
1298+ ASSERT_EQUALS (" /index.h" , simplecpp::simplifyPath (" /path/../other/././..///index.h" ));
1299+ ASSERT_EQUALS (" /index.h" , simplecpp::simplifyPath (" /path/../other///././..///index.h" ));
1300+ ASSERT_EQUALS (" ../path/index.h" , simplecpp::simplifyPath (" ../path/other/../index.h" ));
1301+ ASSERT_EQUALS (" a/index.h" , simplecpp::simplifyPath (" a/../a/index.h" ));
1302+ ASSERT_EQUALS (" ." , simplecpp::simplifyPath (" a/.." ));
1303+ ASSERT_EQUALS (" ." , simplecpp::simplifyPath (" ./a/.." ));
1304+ ASSERT_EQUALS (" ../../src/test.cpp" , simplecpp::simplifyPath (" ../../src/test.cpp" ));
1305+ ASSERT_EQUALS (" ../../../src/test.cpp" , simplecpp::simplifyPath (" ../../../src/test.cpp" ));
1306+ ASSERT_EQUALS (" src/test.cpp" , simplecpp::simplifyPath (" .//src/test.cpp" ));
1307+ ASSERT_EQUALS (" src/test.cpp" , simplecpp::simplifyPath (" .///src/test.cpp" ));
1308+ ASSERT_EQUALS (" test.cpp" , simplecpp::simplifyPath (" ./././././test.cpp" ));
1309+ ASSERT_EQUALS (" src/" , simplecpp::simplifyPath (" src/abc/.." ));
1310+ ASSERT_EQUALS (" src/" , simplecpp::simplifyPath (" src/abc/../" ));
1311+
1312+ // Handling of UNC paths on Windows
1313+ ASSERT_EQUALS (" //src/test.cpp" , simplecpp::simplifyPath (" //src/test.cpp" ));
1314+ ASSERT_EQUALS (" //src/test.cpp" , simplecpp::simplifyPath (" ///src/test.cpp" ));
1315+ }
1316+
1317+ void simplifyPath_New ()
1318+ {
1319+ ASSERT_EQUALS (" " , simplecpp::simplifyPath (" " ));
1320+ ASSERT_EQUALS (" /" , simplecpp::simplifyPath (" /" ));
1321+ ASSERT_EQUALS (" //" , simplecpp::simplifyPath (" //" ));
1322+ ASSERT_EQUALS (" //" , simplecpp::simplifyPath (" ///" ));
1323+ ASSERT_EQUALS (" /" , simplecpp::simplifyPath (" \\ " ));
12591324}
12601325
12611326
@@ -1379,6 +1444,8 @@ int main(int argc, char **argv)
13791444
13801445 // utility functions.
13811446 TEST_CASE (simplifyPath);
1447+ TEST_CASE (simplifyPath_cppcheck);
1448+ TEST_CASE (simplifyPath_New);
13821449
13831450 return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
13841451}
0 commit comments