85 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// <filesystem>12 13// class path14 15// path& remove_filename()16 17#include <filesystem>18#include <type_traits>19#include <cassert>20 21#include "test_iterators.h"22#include "count_new.h"23namespace fs = std::filesystem;24 25struct RemoveFilenameTestcase {26 const char* value;27 const char* expect;28};29 30const RemoveFilenameTestcase TestCases[] =31 {32 {"", ""}33 , {"/", "/"}34 , {"//", "//"}35 , {"///", "///"}36#ifdef _WIN3237 , {"\\", "\\"}38#else39 , {"\\", ""}40#endif41 , {".", ""}42 , {"..", ""}43 , {"/foo", "/"}44 , {"foo/bar", "foo/"}45 , {"foo/", "foo/"}46#ifdef _WIN3247 , {"//foo", "//foo"}48#else49 , {"//foo", "//"}50#endif51 , {"//foo/", "//foo/"}52 , {"//foo///", "//foo///"}53 , {"///foo", "///"}54 , {"///foo/", "///foo/"}55 , {"/foo/", "/foo/"}56 , {"/foo/.", "/foo/"}57 , {"/foo/..", "/foo/"}58 , {"/foo/////", "/foo/////"}59#ifdef _WIN3260 , {"/foo\\\\", "/foo\\\\"}61#else62 , {"/foo\\\\", "/"}63#endif64 , {"/foo//\\/", "/foo//\\/"}65 , {"///foo", "///"}66 , {"file.txt", ""}67 , {"bar/../baz/./file.txt", "bar/../baz/./"}68 };69 70int main(int, char**)71{72 using namespace fs;73 for (auto const & TC : TestCases) {74 path const p_orig(TC.value);75 path p(p_orig);76 assert(p == TC.value);77 path& Ref = (p.remove_filename());78 assert(p == TC.expect);79 assert(&Ref == &p);80 assert(!p.has_filename());81 }82 83 return 0;84}85