|
| 1 | +#include "../NppExec/src/NppExecHelpers.h" |
| 2 | +#include <cassert> |
| 3 | + |
| 4 | +namespace |
| 5 | +{ |
| 6 | + void test_GetFileNamePart() |
| 7 | + { |
| 8 | + using namespace NppExecHelpers; |
| 9 | + |
| 10 | + const tstr empty = tstr(); |
| 11 | + |
| 12 | + tstr path = _T("C"); |
| 13 | + assert( GetFileNamePart(path, fnpDrive) == empty ); |
| 14 | + assert( GetFileNamePart(path, fnpDirPath) == empty ); |
| 15 | + assert( GetFileNamePart(path, fnpNameExt) == _T("C") ); |
| 16 | + assert( GetFileNamePart(path, fnpName) == _T("C") ); |
| 17 | + assert( GetFileNamePart(path, fnpExt) == empty ); |
| 18 | + |
| 19 | + path = _T("C:"); |
| 20 | + assert( GetFileNamePart(path, fnpDrive) == _T("C") ); |
| 21 | + assert( GetFileNamePart(path, fnpDirPath) == _T("C:") ); |
| 22 | + assert( GetFileNamePart(path, fnpNameExt) == empty ); |
| 23 | + assert( GetFileNamePart(path, fnpName) == empty ); |
| 24 | + assert( GetFileNamePart(path, fnpExt) == empty ); |
| 25 | + |
| 26 | + path = _T("C:\\"); |
| 27 | + assert( GetFileNamePart(path, fnpDrive) == _T("C") ); |
| 28 | + assert( GetFileNamePart(path, fnpDirPath) == _T("C:\\") ); |
| 29 | + assert( GetFileNamePart(path, fnpNameExt) == empty ); |
| 30 | + assert( GetFileNamePart(path, fnpName) == empty ); |
| 31 | + assert( GetFileNamePart(path, fnpExt) == empty ); |
| 32 | + |
| 33 | + path = _T("C:/"); |
| 34 | + assert( GetFileNamePart(path, fnpDrive) == _T("C") ); |
| 35 | + assert( GetFileNamePart(path, fnpDirPath) == _T("C:/") ); |
| 36 | + assert( GetFileNamePart(path, fnpNameExt) == empty ); |
| 37 | + assert( GetFileNamePart(path, fnpName) == empty ); |
| 38 | + assert( GetFileNamePart(path, fnpExt) == empty ); |
| 39 | + |
| 40 | + path = _T(".C:"); |
| 41 | + assert( GetFileNamePart(path, fnpDrive) == empty ); |
| 42 | + assert( GetFileNamePart(path, fnpDirPath) == empty ); |
| 43 | + assert( GetFileNamePart(path, fnpNameExt) == _T(".C:") ); |
| 44 | + assert( GetFileNamePart(path, fnpName) == _T(".C:") ); |
| 45 | + assert( GetFileNamePart(path, fnpExt) == _T(".C:") ); |
| 46 | + |
| 47 | + path = _T("\\\\"); |
| 48 | + assert( GetFileNamePart(path, fnpDrive) == empty ); |
| 49 | + assert( GetFileNamePart(path, fnpDirPath) == _T("\\\\") ); |
| 50 | + assert( GetFileNamePart(path, fnpNameExt) == empty ); |
| 51 | + assert( GetFileNamePart(path, fnpName) == empty ); |
| 52 | + assert( GetFileNamePart(path, fnpExt) == empty ); |
| 53 | + |
| 54 | + path = _T("\\\\f.n"); |
| 55 | + assert( GetFileNamePart(path, fnpDrive) == empty ); |
| 56 | + assert( GetFileNamePart(path, fnpDirPath) == _T("\\\\") ); |
| 57 | + assert( GetFileNamePart(path, fnpNameExt) == _T("f.n") ); |
| 58 | + assert( GetFileNamePart(path, fnpName) == _T("f") ); |
| 59 | + assert( GetFileNamePart(path, fnpExt) == _T(".n") ); |
| 60 | + |
| 61 | + path = _T("C:\\.n"); |
| 62 | + assert( GetFileNamePart(path, fnpDrive) == _T("C") ); |
| 63 | + assert( GetFileNamePart(path, fnpDirPath) == _T("C:\\") ); |
| 64 | + assert( GetFileNamePart(path, fnpNameExt) == _T(".n") ); |
| 65 | + assert( GetFileNamePart(path, fnpName) == _T(".n") ); |
| 66 | + assert( GetFileNamePart(path, fnpExt) == _T(".n") ); |
| 67 | + |
| 68 | + path = _T("C:\\d\\f.n"); |
| 69 | + assert( GetFileNamePart(path, fnpDrive) == _T("C") ); |
| 70 | + assert( GetFileNamePart(path, fnpDirPath) == _T("C:\\d\\") ); |
| 71 | + assert( GetFileNamePart(path, fnpNameExt) == _T("f.n") ); |
| 72 | + assert( GetFileNamePart(path, fnpName) == _T("f") ); |
| 73 | + assert( GetFileNamePart(path, fnpExt) == _T(".n") ); |
| 74 | + |
| 75 | + path = _T("C:\\d.e\\f"); |
| 76 | + assert( GetFileNamePart(path, fnpDrive) == _T("C") ); |
| 77 | + assert( GetFileNamePart(path, fnpDirPath) == _T("C:\\d.e\\") ); |
| 78 | + assert( GetFileNamePart(path, fnpNameExt) == _T("f") ); |
| 79 | + assert( GetFileNamePart(path, fnpName) == _T("f") ); |
| 80 | + assert( GetFileNamePart(path, fnpExt) == empty ); |
| 81 | + |
| 82 | + path = _T("C:\\d.e\\.n"); |
| 83 | + assert( GetFileNamePart(path, fnpDrive) == _T("C") ); |
| 84 | + assert( GetFileNamePart(path, fnpDirPath) == _T("C:\\d.e\\") ); |
| 85 | + assert( GetFileNamePart(path, fnpNameExt) == _T(".n") ); |
| 86 | + assert( GetFileNamePart(path, fnpName) == _T(".n") ); |
| 87 | + assert( GetFileNamePart(path, fnpExt) == _T(".n") ); |
| 88 | + |
| 89 | + path = _T("f.n"); |
| 90 | + assert( GetFileNamePart(path, fnpDrive) == empty ); |
| 91 | + assert( GetFileNamePart(path, fnpDirPath) == empty ); |
| 92 | + assert( GetFileNamePart(path, fnpNameExt) == _T("f.n") ); |
| 93 | + assert( GetFileNamePart(path, fnpName) == _T("f") ); |
| 94 | + assert( GetFileNamePart(path, fnpExt) == _T(".n") ); |
| 95 | + } |
| 96 | + |
| 97 | + void test_IsFullLocalPath() |
| 98 | + { |
| 99 | + using namespace NppExecHelpers; |
| 100 | + |
| 101 | + assert( IsFullLocalPath(_T("")) == false ); |
| 102 | + assert( IsFullLocalPath(_T("\\")) == false ); |
| 103 | + assert( IsFullLocalPath(_T("/")) == false ); |
| 104 | + assert( IsFullLocalPath(_T("\\.")) == false ); |
| 105 | + assert( IsFullLocalPath(_T("/.")) == false ); |
| 106 | + assert( IsFullLocalPath(_T("\\\\")) == false ); |
| 107 | + assert( IsFullLocalPath(_T("//")) == false ); |
| 108 | + assert( IsFullLocalPath(_T("\\\\X")) == false ); |
| 109 | + assert( IsFullLocalPath(_T("//X")) == false ); |
| 110 | + assert( IsFullLocalPath(_T("\\\\X:")) == false ); |
| 111 | + assert( IsFullLocalPath(_T("//X:")) == false ); |
| 112 | + assert( IsFullLocalPath(_T("\\\\\\")) == false ); |
| 113 | + assert( IsFullLocalPath(_T("///")) == false ); |
| 114 | + assert( IsFullLocalPath(_T("\\\\.")) == false ); |
| 115 | + assert( IsFullLocalPath(_T("//.")) == false ); |
| 116 | + assert( IsFullLocalPath(_T("\\\\.\\")) == false ); |
| 117 | + assert( IsFullLocalPath(_T("//./")) == false ); |
| 118 | + assert( IsFullLocalPath(_T("\\\\.\\X")) == false ); |
| 119 | + assert( IsFullLocalPath(_T("//./X")) == false ); |
| 120 | + assert( IsFullLocalPath(_T("\\\\.\\X:")) == true ); |
| 121 | + assert( IsFullLocalPath(_T("//./X:")) == true ); |
| 122 | + assert( IsFullLocalPath(_T("\\\\.\\X:\\")) == true ); |
| 123 | + assert( IsFullLocalPath(_T("//./X:/")) == true ); |
| 124 | + assert( IsFullLocalPath(_T("\\\\.\\X:/")) == true ); |
| 125 | + assert( IsFullLocalPath(_T("//./X:\\")) == true ); |
| 126 | + assert( IsFullLocalPath(_T("\\\\.\\X:\\abc")) == true ); |
| 127 | + assert( IsFullLocalPath(_T("//./X:/abc")) == true ); |
| 128 | + assert( IsFullLocalPath(_T("\\\\.\\X:/abc")) == true ); |
| 129 | + assert( IsFullLocalPath(_T("//./X:\\abc")) == true ); |
| 130 | + assert( IsFullLocalPath(_T("\\:")) == false ); |
| 131 | + assert( IsFullLocalPath(_T("/:")) == false ); |
| 132 | + assert( IsFullLocalPath(_T("\\:\\")) == false ); |
| 133 | + assert( IsFullLocalPath(_T("/:/")) == false ); |
| 134 | + assert( IsFullLocalPath(_T("X:")) == true ); |
| 135 | + assert( IsFullLocalPath(_T("X:\\")) == true ); |
| 136 | + assert( IsFullLocalPath(_T("X:/")) == true ); |
| 137 | + assert( IsFullLocalPath(_T("X:\\abc")) == true ); |
| 138 | + assert( IsFullLocalPath(_T("X:/abc")) == true ); |
| 139 | + assert( IsFullLocalPath(_T("abc")) == false ); |
| 140 | + assert( IsFullLocalPath(_T("a:bc")) == false ); |
| 141 | + assert( IsFullLocalPath(_T("\abc")) == false ); |
| 142 | + assert( IsFullLocalPath(_T("/abc")) == false ); |
| 143 | + assert( IsFullLocalPath(_T("\\abc")) == false ); |
| 144 | + assert( IsFullLocalPath(_T("//abc")) == false ); |
| 145 | + } |
| 146 | + |
| 147 | + void tests() |
| 148 | + { |
| 149 | + test_GetFileNamePart(); |
| 150 | + test_IsFullLocalPath(); |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +int main() |
| 155 | +{ |
| 156 | + tests(); |
| 157 | + return 0; |
| 158 | +} |
0 commit comments