@@ -47,13 +47,20 @@ struct PathCompareTest {
47
47
int expect;
48
48
};
49
49
50
- #define LONGA " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
51
- #define LONGB " BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
52
- #define LONGC " CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
53
- #define LONGD " DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
54
- const PathCompareTest CompareTestCases[] =
55
- {
56
- {" " , " " , 0 },
50
+ #define LONGA \
51
+ " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" \
52
+ " AAAAAAAA"
53
+ #define LONGB \
54
+ " BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" \
55
+ " BBBBBBBB"
56
+ #define LONGC \
57
+ " CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" \
58
+ " CCCCCCCC"
59
+ #define LONGD \
60
+ " DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD" \
61
+ " DDDDDDDD"
62
+ const PathCompareTest CompareTestCases[] = {
63
+ {" " , " " , 0 },
57
64
{" a" , " " , 1 },
58
65
{" " , " a" , -1 },
59
66
{" a/b/c" , " a/b/c" , 0 },
@@ -62,14 +69,19 @@ const PathCompareTest CompareTestCases[] =
62
69
{" a/b" , " a/b/c" , -1 },
63
70
{" a/b/c" , " a/b" , 1 },
64
71
{" a/b/" , " a/b/." , -1 },
65
- {" a/b/" , " a/b" , 1 },
72
+ {" a/b/" , " a/b" , 1 },
66
73
{" a/b//////" , " a/b/////." , -1 },
67
74
{" a/.././b" , " a///..//.////b" , 0 },
68
75
{" //foo//bar///baz////" , " //foo/bar/baz/" , 0 }, // duplicate separators
69
- {" ///foo/bar" , " /foo/bar" , 0 }, // "///" is not a root directory
70
- {" /foo/bar/" , " /foo/bar" , 1 }, // trailing separator
76
+ {" ///foo/bar" , " /foo/bar" , 0 }, // "///" is not a root directory
77
+ {" /foo/bar/" , " /foo/bar" , 1 }, // trailing separator
71
78
{" foo" , " /foo" , -1 }, // if !this->has_root_directory() and p.has_root_directory(), a value less than 0.
72
- {" /foo" , " foo" , 1 }, // if this->has_root_directory() and !p.has_root_directory(), a value greater than 0.
79
+ {" /foo" , " foo" , 1 }, // if this->has_root_directory() and !p.has_root_directory(), a value greater than 0.
80
+ #ifdef _WIN32
81
+ {" C:/a" , " C:\\ a" , 0 },
82
+ #else
83
+ {" C:/a" , " C:\\ a" , -1 },
84
+ #endif
73
85
{(" //" LONGA " ////" LONGB " /" LONGC " ///" LONGD), (" //" LONGA " /" LONGB " /" LONGC " /" LONGD), 0 },
74
86
{(LONGA " /" LONGB " /" LONGC), (LONGA " /" LONGB " /" LONGB), 1 }
75
87
@@ -79,23 +91,19 @@ const PathCompareTest CompareTestCases[] =
79
91
#undef LONGC
80
92
#undef LONGD
81
93
82
- static inline int normalize_ret (int ret)
83
- {
84
- return ret < 0 ? -1 : (ret > 0 ? 1 : 0 );
85
- }
94
+ static inline int normalize_ret (int ret) { return ret < 0 ? -1 : (ret > 0 ? 1 : 0 ); }
86
95
87
- void test_compare_basic ()
88
- {
96
+ void test_compare_basic () {
89
97
using namespace fs ;
90
- for (auto const & TC : CompareTestCases) {
98
+ for (auto const & TC : CompareTestCases) {
91
99
const path p1 (TC.LHS );
92
100
const path p2 (TC.RHS );
93
101
std::string RHS (TC.RHS );
94
102
const path::string_type R (RHS.begin (), RHS.end ());
95
103
const std::basic_string_view<path::value_type> RV (R);
96
- const path::value_type * Ptr = R.c_str ();
97
- const int E = TC.expect ;
98
- { // compare(...) functions
104
+ const path::value_type* Ptr = R.c_str ();
105
+ const int E = TC.expect ;
106
+ { // compare(...) functions
99
107
DisableAllocationGuard g; // none of these operations should allocate
100
108
101
109
// check runtime results
@@ -113,7 +121,7 @@ void test_compare_basic()
113
121
// check signatures
114
122
ASSERT_NOEXCEPT (p1.compare (p2));
115
123
}
116
- { // comparison operators
124
+ { // comparison operators
117
125
DisableAllocationGuard g; // none of these operations should allocate
118
126
119
127
// check signatures
@@ -180,14 +188,14 @@ void test_compare_elements() {
180
188
181
189
auto BuildPath = [](std::vector<std::string> const & Elems) {
182
190
fs::path p;
183
- for (auto & E : Elems)
191
+ for (auto & E : Elems)
184
192
p /= E;
185
193
return p;
186
194
};
187
195
188
- for (auto & TC : TestCases) {
189
- fs::path LHS = BuildPath (TC.LHSElements );
190
- fs::path RHS = BuildPath (TC.RHSElements );
196
+ for (auto & TC : TestCases) {
197
+ fs::path LHS = BuildPath (TC.LHSElements );
198
+ fs::path RHS = BuildPath (TC.RHSElements );
191
199
const int ExpectCmp = CompareElements (TC.LHSElements , TC.RHSElements );
192
200
assert (ExpectCmp == TC.Expect );
193
201
const int GotCmp = normalize_ret (LHS.compare (RHS));
0 commit comments