1 //===----------------------------------------------------------------------===//
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& replace_filename()
17
18 #include <experimental/filesystem>
19 #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
27 namespace fs = std::experimental::filesystem;
28
29 struct ReplaceFilenameTestcase {
30 const char* value;
31 const char* expect;
32 const char* filename;
33 };
34
35 const ReplaceFilenameTestcase TestCases[] =
36 {
37 {"/foo", "/bar", "bar"}
38 , {"/foo", "/", ""}
39 , {"foo", "bar", "bar"}
40 , {"/", "bar", "bar"}
41 , {"\\", "bar", "bar"}
42 , {"///", "bar", "bar"}
43 , {"\\\\", "bar", "bar"}
44 , {"\\/\\", "\\/bar", "bar"}
45 , {".", "bar", "bar"}
46 , {"..", "bar", "bar"}
47 , {"/foo\\baz/bong/", "/foo\\baz/bong/bar", "bar"}
48 , {"/foo\\baz/bong", "/foo\\baz/bar", "bar"}
49 };
50
main()51 int main()
52 {
53 using namespace fs;
54 for (auto const & TC : TestCases) {
55 path p(TC.value);
56 assert(p == TC.value);
57 path& Ref = (p.replace_filename(TC.filename));
58 assert(p == TC.expect);
59 assert(&Ref == &p);
60 // Tests Effects "as-if": remove_filename() append(filename)
61 {
62 path p2(TC.value);
63 path replace(TC.filename);
64 p2.remove_filename();
65 p2 /= replace;
66 assert(p2 == p);
67 }
68 }
69 }
70