// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef TEST_STD_INPUT_OUTPUT_FILESYSTEMS_CLASS_PATH_PATH_HELPER_H
#define TEST_STD_INPUT_OUTPUT_FILESYSTEMS_CLASS_PATH_PATH_HELPER_H
#include <cstddef>
#include <iterator>
#include <filesystem>
#include "make_string.h"
namespace fs = std::filesystem;
// Testing the allocation behavior of the code_cvt functions requires
// *knowing* that the allocation was not done by "path::__str_".
// This hack forces path to allocate enough memory.
inline void PathReserve(fs::path& p, std::size_t N) {
auto const& native_ref = p.native();
const_cast<fs::path::string_type&>(native_ref).reserve(N);
}
inline bool PathEq(fs::path const& LHS, fs::path const& RHS) {
return LHS.native() == RHS.native();
}
inline bool PathEqIgnoreSep(fs::path LHS, fs::path RHS) {
LHS.make_preferred();
RHS.make_preferred();
return LHS.native() == RHS.native();
}
template <class Iter>
Iter IterEnd(Iter B) {
using VT = typename std::iterator_traits<Iter>::value_type;
for (; *B != VT{}; ++B)
;
return B;
}
template <class CharT>
const CharT* StrEnd(CharT const* P) {
return IterEnd(P);
}
template <class CharT>
std::size_t StrLen(CharT const* P) {
return StrEnd(P) - P;
}
const MultiStringType PathList[] = {
MKSTR(""),
MKSTR(" "),
MKSTR("//"),
MKSTR("."),
MKSTR(".."),
MKSTR("foo"),
MKSTR("/"),
MKSTR("/foo"),
MKSTR("foo/"),
MKSTR("/foo/"),
MKSTR("foo/bar"),
MKSTR("/foo/bar"),
MKSTR("//net"),
MKSTR("//net/foo"),
MKSTR("///foo///"),
MKSTR("///foo///bar"),
MKSTR("/."),
MKSTR("./"),
MKSTR("/.."),
MKSTR("../"),
MKSTR("foo/."),
MKSTR("foo/.."),
MKSTR("foo/./"),
MKSTR("foo/./bar"),
MKSTR("foo/../"),
MKSTR("foo/../bar"),
MKSTR("c:"),
MKSTR("c:/"),
MKSTR("c:foo"),
MKSTR("c:/foo"),
MKSTR("c:foo/"),
MKSTR("c:/foo/"),
MKSTR("c:/foo/bar"),
MKSTR("prn:"),
MKSTR("c:\\"),
MKSTR("c:\\foo"),
MKSTR("c:foo\\"),
MKSTR("c:\\foo\\"),
MKSTR("c:\\foo/"),
MKSTR("c:/foo\\bar"),
MKSTR("//"),
MKSTR("/finally/we/need/one/really/really/really/really/really/really/really/long/string")
};
const unsigned PathListSize = sizeof(PathList) / sizeof(MultiStringType);
#endif // TEST_STD_INPUT_OUTPUT_FILESYSTEMS_CLASS_PATH_PATH_HELPER_H