diff options
Diffstat (limited to 'tools/slang-unit-test/unit-test-path.cpp')
| -rw-r--r-- | tools/slang-unit-test/unit-test-path.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tools/slang-unit-test/unit-test-path.cpp b/tools/slang-unit-test/unit-test-path.cpp new file mode 100644 index 000000000..c27feee9c --- /dev/null +++ b/tools/slang-unit-test/unit-test-path.cpp @@ -0,0 +1,62 @@ +// unit-test-path.cpp + +#include "../../source/core/slang-io.h" + +#include "tools/unit-test/slang-unit-test.h" + +using namespace Slang; + +SLANG_UNIT_TEST(path) +{ +#if SLANG_WINDOWS_FAMILY + // Disable for now on non windows has some problems on *some* Linux based CI. + { + String path; + SlangResult res = Path::getCanonical("source/slang", path); + SLANG_CHECK(SLANG_SUCCEEDED(res)); + + String parentPath; + res = Path::getCanonical("source", parentPath); + SLANG_CHECK(SLANG_SUCCEEDED(res)); + + String parentPath2 = Path::getParentDirectory(path); + SLANG_CHECK(parentPath == parentPath2); + } +#endif + // Test the paths + { + SLANG_CHECK(Path::simplify(".") == "."); + SLANG_CHECK(Path::simplify("..") == ".."); + SLANG_CHECK(Path::simplify("blah/..") == "."); + + SLANG_CHECK(Path::simplify("blah/.././a") == "a"); + + SLANG_CHECK(Path::simplify("a:/what/.././../is/./../this/.") == "a:/../this"); + + SLANG_CHECK(Path::simplify("a:/what/.././../is/./../this/./") == "a:/../this"); + + SLANG_CHECK(Path::simplify("a:\\what\\..\\.\\..\\is\\.\\..\\this\\.\\") == "a:/../this"); + + SLANG_CHECK(Path::simplify("tests/preprocessor/.\\pragma-once-a.h") == "tests/preprocessor/pragma-once-a.h"); + + + SLANG_CHECK(Path::hasRelativeElement(".")); + SLANG_CHECK(Path::hasRelativeElement("..")); + SLANG_CHECK(Path::hasRelativeElement("blah/..")); + + SLANG_CHECK(Path::hasRelativeElement("blah/.././a")); + SLANG_CHECK(Path::hasRelativeElement("a") == false); + SLANG_CHECK(Path::hasRelativeElement("blah/a") == false); + SLANG_CHECK(Path::hasRelativeElement("a:\\blah/a") == false); + + + SLANG_CHECK(Path::hasRelativeElement("a:/what/.././../is/./../this/.")); + + SLANG_CHECK(Path::hasRelativeElement("a:/what/.././../is/./../this/./")); + + SLANG_CHECK(Path::hasRelativeElement("a:\\what\\..\\.\\..\\is\\.\\..\\this\\.\\")); + + + } +} + |
