blob: 84cdd52142944e2a760cde54b08ac302d10289a3 [file] [log] [blame]
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// UNSUPPORTED: c++98, c++03
11
12// <experimental/filesystem>
13
14// class path
15
16// path& remove_filename()
17
Eric Fiselierf1471a32018-03-26 05:46:57 +000018#include "filesystem_include.hpp"
Eric Fiselier6e9a6942016-06-17 19:46:40 +000019#include <type_traits>
20#include <cassert>
21
22#include "test_macros.h"
23#include "test_iterators.h"
24#include "count_new.hpp"
25#include "filesystem_test_helper.hpp"
26
Eric Fiselier6e9a6942016-06-17 19:46:40 +000027
28struct RemoveFilenameTestcase {
29 const char* value;
30 const char* expect;
31};
32
33const RemoveFilenameTestcase TestCases[] =
34 {
35 {"", ""}
36 , {"/", ""}
Eric Fiselier620a9a52016-10-15 22:37:42 +000037 , {"//", ""}
38 , {"///", ""}
Eric Fiselier6e9a6942016-06-17 19:46:40 +000039 , {"\\", ""}
40 , {".", ""}
41 , {"..", ""}
42 , {"/foo", "/"}
Eric Fiselier620a9a52016-10-15 22:37:42 +000043 , {"//foo", ""}
44 , {"//foo/", ""}
45 , {"//foo///", ""}
46 , {"///foo", "/"}
47 , {"///foo/", "///foo"}
Eric Fiselier6e9a6942016-06-17 19:46:40 +000048 , {"/foo/", "/foo"}
49 , {"/foo/.", "/foo"}
50 , {"/foo/..", "/foo"}
51 , {"/foo/////", "/foo"}
52 , {"/foo\\\\", "/"}
53 , {"/foo//\\/", "/foo//\\"}
Eric Fiselier620a9a52016-10-15 22:37:42 +000054 , {"///foo", "/"}
Eric Fiselier6e9a6942016-06-17 19:46:40 +000055 , {"file.txt", ""}
56 , {"bar/../baz/./file.txt", "bar/../baz/."}
57 };
58
59int main()
60{
61 using namespace fs;
62 for (auto const & TC : TestCases) {
63 path const p_orig(TC.value);
64 path p(p_orig);
65 assert(p == TC.value);
66 path& Ref = (p.remove_filename());
67 assert(p == TC.expect);
68 assert(&Ref == &p);
69 {
70 const path parentp = p_orig.parent_path();
71 if (parentp == p_orig.root_name()) {
72
73 assert(p.empty());
74 } else {
75 assert(p == parentp);
76 }
77 }
78 }
79}