diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/folder/pathsplit_ut.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/folder/pathsplit_ut.cpp')
-rw-r--r-- | util/folder/pathsplit_ut.cpp | 362 |
1 files changed, 181 insertions, 181 deletions
diff --git a/util/folder/pathsplit_ut.cpp b/util/folder/pathsplit_ut.cpp index 0e97afd0d0..ef014be7a9 100644 --- a/util/folder/pathsplit_ut.cpp +++ b/util/folder/pathsplit_ut.cpp @@ -3,129 +3,129 @@ #ifndef PS_INCLUDED // Outer part - #include "pathsplit.h" - - #include <library/cpp/testing/unittest/registar.h> - - #define VAR(NAME) Y_CAT(NAME, __LINE__) - - #define PS_CHECK(input, ...) \ - const char* VAR(model)[] = {"", __VA_ARGS__}; \ - UNIT_ASSERT_EQUAL(input.size(), sizeof(VAR(model)) / sizeof(const char*) - 1); \ - for (size_t n = 0; n < input.size(); ++n) { \ - UNIT_ASSERT_STRINGS_EQUAL(input[n], VAR(model)[n + 1]); \ - } - - #define PS_INCLUDED - - #define PSUF(NAME) NAME - #define PSUF_LOCAL(NAME) NAME##Local - #include __FILE__ - #undef PSUF - #undef PSUF_LOCAL - - #define PSUF(NAME) NAME##Unix - #define PSUF_LOCAL(NAME) PSUF(NAME) - #ifdef _win_ - #undef _win_ - #define REVERT_WIN - #endif - #include __FILE__ - #ifdef REVERT_WIN - #define _win_ - #undef REVERT_WIN - #endif - #undef PSUF - #undef PSUF_LOCAL - - #define PSUF(NAME) NAME##Windows - #define PSUF_LOCAL(NAME) PSUF(NAME) - #ifndef _win_ - #define _win_ - #define REVERT_WIN - #endif - #include __FILE__ - #ifdef REVERT_WIN - #undef _win_ - #undef REVERT_WIN - #endif - #undef PSUF - #undef PSUF_LOCAL - - #undef PS_INCLUDED + #include "pathsplit.h" + + #include <library/cpp/testing/unittest/registar.h> + + #define VAR(NAME) Y_CAT(NAME, __LINE__) + + #define PS_CHECK(input, ...) \ + const char* VAR(model)[] = {"", __VA_ARGS__}; \ + UNIT_ASSERT_EQUAL(input.size(), sizeof(VAR(model)) / sizeof(const char*) - 1); \ + for (size_t n = 0; n < input.size(); ++n) { \ + UNIT_ASSERT_STRINGS_EQUAL(input[n], VAR(model)[n + 1]); \ + } + + #define PS_INCLUDED + + #define PSUF(NAME) NAME + #define PSUF_LOCAL(NAME) NAME##Local + #include __FILE__ + #undef PSUF + #undef PSUF_LOCAL + + #define PSUF(NAME) NAME##Unix + #define PSUF_LOCAL(NAME) PSUF(NAME) + #ifdef _win_ + #undef _win_ + #define REVERT_WIN + #endif + #include __FILE__ + #ifdef REVERT_WIN + #define _win_ + #undef REVERT_WIN + #endif + #undef PSUF + #undef PSUF_LOCAL + + #define PSUF(NAME) NAME##Windows + #define PSUF_LOCAL(NAME) PSUF(NAME) + #ifndef _win_ + #define _win_ + #define REVERT_WIN + #endif + #include __FILE__ + #ifdef REVERT_WIN + #undef _win_ + #undef REVERT_WIN + #endif + #undef PSUF + #undef PSUF_LOCAL + + #undef PS_INCLUDED #else // Inner part - #ifdef _win_ - #define TRUE_ONLY_WIN true - #else - #define TRUE_ONLY_WIN false - #endif + #ifdef _win_ + #define TRUE_ONLY_WIN true + #else + #define TRUE_ONLY_WIN false + #endif Y_UNIT_TEST_SUITE(PSUF(PathSplit)) { Y_UNIT_TEST(Empty) { - PSUF(TPathSplit) - ps; + PSUF(TPathSplit) + ps; PS_CHECK(ps); UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); } Y_UNIT_TEST(Relative) { - PSUF(TPathSplit) - ps("some/usual/path"); + PSUF(TPathSplit) + ps("some/usual/path"); PS_CHECK(ps, "some", "usual", "path"); UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); } Y_UNIT_TEST(Absolute) { - PSUF(TPathSplit) - ps("/some/usual/path"); + PSUF(TPathSplit) + ps("/some/usual/path"); PS_CHECK(ps, "some", "usual", "path"); UNIT_ASSERT_EQUAL(ps.IsAbsolute, true); } Y_UNIT_TEST(Self) { - PSUF(TPathSplit) - ps("."); + PSUF(TPathSplit) + ps("."); PS_CHECK(ps, "."); UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); } Y_UNIT_TEST(Parent) { - PSUF(TPathSplit) - ps(".."); + PSUF(TPathSplit) + ps(".."); PS_CHECK(ps, ".."); UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); } Y_UNIT_TEST(Root) { - PSUF(TPathSplit) - ps("/"); + PSUF(TPathSplit) + ps("/"); PS_CHECK(ps); UNIT_ASSERT_EQUAL(ps.IsAbsolute, true); } Y_UNIT_TEST(Reconstruct) { - PSUF(TPathSplit) - ps("some/usual/path/../../other/././//path"); - #ifdef _win_ - UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "some\\other\\path"); - #else - UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "some/other/path"); - #endif - - ps = PSUF(TPathSplit)("/some/usual/path/../../other/././//path"); - #ifdef _win_ - UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "\\some\\other\\path"); - #else - UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "/some/other/path"); - #endif + PSUF(TPathSplit) + ps("some/usual/path/../../other/././//path"); + #ifdef _win_ + UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "some\\other\\path"); + #else + UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "some/other/path"); + #endif + + ps = PSUF(TPathSplit)("/some/usual/path/../../other/././//path"); + #ifdef _win_ + UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "\\some\\other\\path"); + #else + UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "/some/other/path"); + #endif } Y_UNIT_TEST(ParseFirstPart) { - PSUF(TPathSplit) - ps; + PSUF(TPathSplit) + ps; ps.ParseFirstPart("some/usual/path"); PS_CHECK(ps, "some", "usual", "path"); UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); @@ -137,8 +137,8 @@ Y_UNIT_TEST_SUITE(PSUF(PathSplit)) { } Y_UNIT_TEST(ParsePart) { - PSUF(TPathSplit) - ps("some/usual/path"); + PSUF(TPathSplit) + ps("some/usual/path"); ps.ParsePart("sub/path"); PS_CHECK(ps, "some", "usual", "path", "sub", "path"); UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); @@ -150,8 +150,8 @@ Y_UNIT_TEST_SUITE(PSUF(PathSplit)) { } Y_UNIT_TEST(ParsePartSelf) { - PSUF(TPathSplit) - ps("some/usual/path"); + PSUF(TPathSplit) + ps("some/usual/path"); ps.ParsePart("."); PS_CHECK(ps, "some", "usual", "path"); @@ -161,8 +161,8 @@ Y_UNIT_TEST_SUITE(PSUF(PathSplit)) { } Y_UNIT_TEST(ParsePartParent) { - PSUF(TPathSplit) - ps("some/usual/path"); + PSUF(TPathSplit) + ps("some/usual/path"); ps.ParsePart(".."); PS_CHECK(ps, "some", "usual"); @@ -182,8 +182,8 @@ Y_UNIT_TEST_SUITE(PSUF(PathSplit)) { } Y_UNIT_TEST(ParsePartOverflow) { - PSUF(TPathSplit) - ps("some/usual/path"); + PSUF(TPathSplit) + ps("some/usual/path"); ps.ParsePart("../../../../.."); PS_CHECK(ps, "..", ".."); UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); @@ -195,131 +195,131 @@ Y_UNIT_TEST_SUITE(PSUF(PathSplit)) { } Y_UNIT_TEST(WinRelative) { - PSUF(TPathSplit) - ps("some\\usual\\path"); - #ifdef _win_ + PSUF(TPathSplit) + ps("some\\usual\\path"); + #ifdef _win_ PS_CHECK(ps, "some", "usual", "path"); - #else + #else PS_CHECK(ps, "some\\usual\\path"); - #endif + #endif UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); } Y_UNIT_TEST(WinAbsolute) { - PSUF(TPathSplit) - ps("\\some\\usual\\path"); - #ifdef _win_ + PSUF(TPathSplit) + ps("\\some\\usual\\path"); + #ifdef _win_ PS_CHECK(ps, "some", "usual", "path"); - #else + #else PS_CHECK(ps, "\\some\\usual\\path"); - #endif + #endif UNIT_ASSERT_EQUAL(ps.IsAbsolute, TRUE_ONLY_WIN); - PSUF(TPathSplit) - psDrive("C:\\some\\usual\\path"); - #ifdef _win_ + PSUF(TPathSplit) + psDrive("C:\\some\\usual\\path"); + #ifdef _win_ PS_CHECK(psDrive, "some", "usual", "path"); UNIT_ASSERT_EQUAL(psDrive.Drive, "C:"); - #else + #else PS_CHECK(psDrive, "C:\\some\\usual\\path"); - #endif + #endif UNIT_ASSERT_EQUAL(psDrive.IsAbsolute, TRUE_ONLY_WIN); - PSUF(TPathSplit) - psDrive2("C:/some/usual/path"); - #ifdef _win_ + PSUF(TPathSplit) + psDrive2("C:/some/usual/path"); + #ifdef _win_ PS_CHECK(psDrive2, "some", "usual", "path"); UNIT_ASSERT_EQUAL(psDrive2.Drive, "C:"); - #else + #else PS_CHECK(psDrive2, "C:", "some", "usual", "path"); - #endif + #endif UNIT_ASSERT_EQUAL(psDrive2.IsAbsolute, TRUE_ONLY_WIN); } Y_UNIT_TEST(WinRoot) { - PSUF(TPathSplit) - ps("\\"); - #ifdef _win_ + PSUF(TPathSplit) + ps("\\"); + #ifdef _win_ PS_CHECK(ps); - #else + #else PS_CHECK(ps, "\\"); - #endif + #endif UNIT_ASSERT_EQUAL(ps.IsAbsolute, TRUE_ONLY_WIN); - PSUF(TPathSplit) - psDrive("C:"); - #ifdef _win_ + PSUF(TPathSplit) + psDrive("C:"); + #ifdef _win_ PS_CHECK(psDrive); UNIT_ASSERT_EQUAL(psDrive.Drive, "C:"); - #else + #else PS_CHECK(psDrive, "C:"); - #endif + #endif UNIT_ASSERT_EQUAL(psDrive.IsAbsolute, TRUE_ONLY_WIN); } Y_UNIT_TEST(WinReconstruct) { - PSUF(TPathSplit) - ps("some\\usual\\path\\..\\..\\other\\.\\.\\\\\\path"); - #ifdef _win_ + PSUF(TPathSplit) + ps("some\\usual\\path\\..\\..\\other\\.\\.\\\\\\path"); + #ifdef _win_ UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "some\\other\\path"); - #else + #else UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "some\\usual\\path\\..\\..\\other\\.\\.\\\\\\path"); - #endif + #endif ps = PSUF(TPathSplit)("\\some\\usual\\path\\..\\..\\other\\.\\.\\\\\\path"); - #ifdef _win_ + #ifdef _win_ UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "\\some\\other\\path"); - #else + #else UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "\\some\\usual\\path\\..\\..\\other\\.\\.\\\\\\path"); - #endif + #endif } Y_UNIT_TEST(WinParseFirstPart) { - PSUF(TPathSplit) - ps; + PSUF(TPathSplit) + ps; ps.ParseFirstPart("some\\usual\\path"); - #ifdef _win_ + #ifdef _win_ PS_CHECK(ps, "some", "usual", "path"); - #else + #else PS_CHECK(ps, "some\\usual\\path"); - #endif + #endif UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); ps = PSUF(TPathSplit)(); ps.ParseFirstPart("\\some\\usual\\path"); - #ifdef _win_ + #ifdef _win_ PS_CHECK(ps, "some", "usual", "path"); - #else + #else PS_CHECK(ps, "\\some\\usual\\path"); - #endif + #endif UNIT_ASSERT_EQUAL(ps.IsAbsolute, TRUE_ONLY_WIN); } Y_UNIT_TEST(WinParsePart) { - PSUF(TPathSplit) - ps("some\\usual\\path"); + PSUF(TPathSplit) + ps("some\\usual\\path"); ps.ParsePart("sub\\path"); - #ifdef _win_ + #ifdef _win_ PS_CHECK(ps, "some", "usual", "path", "sub", "path"); - #else + #else PS_CHECK(ps, "some\\usual\\path", "sub\\path"); - #endif + #endif UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); ps = PSUF(TPathSplit)("some\\usual\\path"); ps.ParsePart("\\sub\\path"); - #ifdef _win_ + #ifdef _win_ PS_CHECK(ps, "some", "usual", "path", "sub", "path"); - #else + #else PS_CHECK(ps, "some\\usual\\path", "\\sub\\path"); - #endif + #endif UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); } - #ifdef _win_ + #ifdef _win_ Y_UNIT_TEST(WinParsePartSelf) { - PSUF(TPathSplit) - ps("some\\usual\\path"); + PSUF(TPathSplit) + ps("some\\usual\\path"); ps.ParsePart("."); PS_CHECK(ps, "some", "usual", "path"); @@ -329,8 +329,8 @@ Y_UNIT_TEST_SUITE(PSUF(PathSplit)) { } Y_UNIT_TEST(WinParsePartParent) { - PSUF(TPathSplit) - ps("some\\usual\\path"); + PSUF(TPathSplit) + ps("some\\usual\\path"); ps.ParsePart(".."); PS_CHECK(ps, "some", "usual"); @@ -356,8 +356,8 @@ Y_UNIT_TEST_SUITE(PSUF(PathSplit)) { } Y_UNIT_TEST(WinParsePartOverflow) { - PSUF(TPathSplit) - ps("some\\usual\\path"); + PSUF(TPathSplit) + ps("some\\usual\\path"); ps.ParsePart("..\\..\\..\\..\\.."); PS_CHECK(ps, "..", ".."); UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); @@ -373,69 +373,69 @@ Y_UNIT_TEST_SUITE(PSUF(PathSplit)) { UNIT_ASSERT_EQUAL(ps.IsAbsolute, true); UNIT_ASSERT_EQUAL(ps.Drive, "C:"); } - #endif + #endif Y_UNIT_TEST(WinMixed) { - PSUF(TPathSplit) - ps("some\\usual/path"); - #ifdef _win_ + PSUF(TPathSplit) + ps("some\\usual/path"); + #ifdef _win_ PS_CHECK(ps, "some", "usual", "path"); - #else + #else PS_CHECK(ps, "some\\usual", "path"); - #endif + #endif UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); } Y_UNIT_TEST(WinParsePartMixed) { - PSUF(TPathSplit) - ps("some\\usual/path"); + PSUF(TPathSplit) + ps("some\\usual/path"); ps.ParsePart("sub/sub\\path"); - #ifdef _win_ + #ifdef _win_ PS_CHECK(ps, "some", "usual", "path", "sub", "sub", "path"); - #else + #else PS_CHECK(ps, "some\\usual", "path", "sub", "sub\\path"); - #endif + #endif UNIT_ASSERT_EQUAL(ps.IsAbsolute, false); } Y_UNIT_TEST(BeginWithSelf) { - PSUF(TPathSplit) - ps("./some/usual/path"); + PSUF(TPathSplit) + ps("./some/usual/path"); PS_CHECK(ps, "some", "usual", "path"); - #ifdef _win_ + #ifdef _win_ UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "some\\usual\\path"); - #else + #else UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "some/usual/path"); - #endif + #endif } Y_UNIT_TEST(BeginWithParent) { - PSUF(TPathSplit) - ps("../some/usual/path"); + PSUF(TPathSplit) + ps("../some/usual/path"); PS_CHECK(ps, "..", "some", "usual", "path"); - #ifdef _win_ + #ifdef _win_ UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "..\\some\\usual\\path"); - #else + #else UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "../some/usual/path"); - #endif + #endif } Y_UNIT_TEST(InOut) { - PSUF(TPathSplit) - ps("path/.."); + PSUF(TPathSplit) + ps("path/.."); PS_CHECK(ps); UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), ""); } Y_UNIT_TEST(OutIn) { - PSUF(TPathSplit) - ps("../path"); + PSUF(TPathSplit) + ps("../path"); PS_CHECK(ps, "..", "path"); - #ifdef _win_ + #ifdef _win_ UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "..\\path"); - #else + #else UNIT_ASSERT_STRINGS_EQUAL(ps.Reconstruct(), "../path"); - #endif + #endif } } @@ -477,6 +477,6 @@ Y_UNIT_TEST_SUITE(PSUF(PathSplitTraits)) { } } - #undef TRUE_ONLY_WIN + #undef TRUE_ONLY_WIN #endif |