blob: ec885f15c8c988ff763372e53c32fac6bf62a569 [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"
Eric Fiselier1e34c762018-04-02 23:03:41 +000026#include "verbose_assert.h"
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 {"", ""}
Eric Fiselier1e34c762018-04-02 23:03:41 +000036 , {"/", "/"}
37 , {"//", "//"}
38 , {"///", "///"}
Eric Fiselier6e9a6942016-06-17 19:46:40 +000039 , {"\\", ""}
40 , {".", ""}
41 , {"..", ""}
42 , {"/foo", "/"}
Eric Fiselier1e34c762018-04-02 23:03:41 +000043 , {"foo/bar", "foo/"}
44 , {"foo/", "foo/"}
45 , {"//foo", "//"}
46 , {"//foo/", "//foo/"}
47 , {"//foo///", "//foo///"}
48 , {"///foo", "///"}
49 , {"///foo/", "///foo/"}
50 , {"/foo/", "/foo/"}
51 , {"/foo/.", "/foo/"}
52 , {"/foo/..", "/foo/"}
53 , {"/foo/////", "/foo/////"}
Eric Fiselier6e9a6942016-06-17 19:46:40 +000054 , {"/foo\\\\", "/"}
Eric Fiselier1e34c762018-04-02 23:03:41 +000055 , {"/foo//\\/", "/foo//\\/"}
56 , {"///foo", "///"}
Eric Fiselier6e9a6942016-06-17 19:46:40 +000057 , {"file.txt", ""}
Eric Fiselier1e34c762018-04-02 23:03:41 +000058 , {"bar/../baz/./file.txt", "bar/../baz/./"}
Eric Fiselier6e9a6942016-06-17 19:46:40 +000059 };
60
61int main()
62{
63 using namespace fs;
64 for (auto const & TC : TestCases) {
65 path const p_orig(TC.value);
66 path p(p_orig);
67 assert(p == TC.value);
68 path& Ref = (p.remove_filename());
Eric Fiselier1e34c762018-04-02 23:03:41 +000069 ASSERT_EQ(p, TC.expect) << DISPLAY(p_orig);
Eric Fiselier6e9a6942016-06-17 19:46:40 +000070 assert(&Ref == &p);
Eric Fiselier1e34c762018-04-02 23:03:41 +000071 assert(!p.has_filename());
Eric Fiselier6e9a6942016-06-17 19:46:40 +000072 }
73}