summaryrefslogtreecommitdiff
path: root/tools/slang-test/unit-test-path.cpp
blob: e9cfbe2e30e7ae0e7141bb5913427f5bffe628d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// unit-test-path.cpp

#include "../../source/core/slang-io.h"


#include "test-context.h"

using namespace Slang;

static void pathUnitTest()
{
    {
        String path;
        SlangResult res = Path::GetCanonical(".", path);
        SLANG_CHECK(SLANG_SUCCEEDED(res));

        String parentPath;
        res = Path::GetCanonical("..", parentPath);
        SLANG_CHECK(SLANG_SUCCEEDED(res));

        String parentPath2 = Path::GetDirectoryName(path);
        SLANG_CHECK(parentPath == parentPath2);
    }
    // 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_UNIT_TEST("Path", pathUnitTest);