File: normalize_path.cpp

package info (click to toggle)
pd-vstplugin 0.6.1-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 2,008 kB
  • sloc: cpp: 22,783; lisp: 2,860; makefile: 37; sh: 26
file content (41 lines) | stat: -rw-r--r-- 1,780 bytes parent folder | download | duplicates (2)
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
#include "FileUtils.h"
#include "Log.h"

#include <cstdlib>
#include <vector>

std::vector<std::pair<std::string, std::string>> pathList = {
    { "C:/Foo/Bar/test.exe", "C:/Foo/Bar/test.exe" },
    { "C:/Foo/Bar/./test.exe", "C:/Foo/Bar/test.exe" },
    { "C:/Foo/../Bar/./test.exe", "C:/Bar/test.exe" },
    { "C:/../Foo/Bar/./test.exe", "C:/Foo/Bar/test.exe" },
    { "C:/../../Foo/Bar/./test.exe", "C:/Foo/Bar/test.exe" },
    { "C://Foo///Bar/////test.exe", "C:/Foo/Bar/test.exe" },
    { "C:/Foo//Bar/////test.exe", "C:/Foo/Bar/test.exe" },
    { "C:/Foo/././Bar/././././test.exe", "C:/Foo/Bar/test.exe" },
    { "C:/./Foo/././Bar/./test.exe", "C:/Foo/Bar/test.exe" },
    { "/Foo/Bar/./test.exe", "/Foo/Bar/test.exe" },
    { "/Foo/./Bar/./test.exe", "/Foo/Bar/test.exe" },
    { "/Foo/../Bar/./test.exe", "/Bar/test.exe" },
    { "/../Foo/Bar/./test.exe", "/Foo/Bar/test.exe" },
    { "/../../Foo/Bar/./test.exe", "/Foo/Bar/test.exe" },
    { "/Foo/../../Bar/./test.exe", "/Bar/test.exe" },
    { "/Foo/Bar/Baz/../../test.exe", "/Foo/test.exe" },
    { "/Foo/Bar/Baz/../../../test.exe", "/test.exe" },
    { "//Foo///Bar/////test.exe", "/Foo/Bar/test.exe" },
    { "/Foo//Bar/////test.exe", "/Foo/Bar/test.exe" },
    { "/./Foo/././Bar/././././test.exe", "/Foo/Bar/test.exe" },
    { "/Foo/././Bar/././././test.exe", "/Foo/Bar/test.exe" }
};

int main(int argc, const char *argv[]) {
    for (auto& [test, expected] : pathList) {
        auto normalized = vst::normalizePath(test);
        if (normalized != expected) {
            LOG_ERROR("path " << normalized << " (normalized from "
                      << test << ") does not match " << expected);
            return EXIT_FAILURE;
        }
    }
    return EXIT_SUCCESS;
}