summaryrefslogtreecommitdiffstats
path: root/tools/slang-test/unit-test-path.cpp
blob: 35462f70391bd8b8276ff7017c921203f122113b (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 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::getParentDirectory(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_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\\.\\"));


    }
}

SLANG_UNIT_TEST("Path", pathUnitTest);