replace_filename.pass.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // UNSUPPORTED: c++98, c++03
  10. // <experimental/filesystem>
  11. // class path
  12. // path& replace_filename()
  13. #include <experimental/filesystem>
  14. #include <type_traits>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. #include "test_iterators.h"
  18. #include "count_new.hpp"
  19. #include "filesystem_test_helper.hpp"
  20. namespace fs = std::experimental::filesystem;
  21. struct ReplaceFilenameTestcase {
  22. const char* value;
  23. const char* expect;
  24. const char* filename;
  25. };
  26. const ReplaceFilenameTestcase TestCases[] =
  27. {
  28. {"/foo", "/bar", "bar"}
  29. , {"/foo", "/", ""}
  30. , {"foo", "bar", "bar"}
  31. , {"/", "bar", "bar"}
  32. , {"\\", "bar", "bar"}
  33. , {"///", "bar", "bar"}
  34. , {"\\\\", "bar", "bar"}
  35. , {"\\/\\", "\\/bar", "bar"}
  36. , {".", "bar", "bar"}
  37. , {"..", "bar", "bar"}
  38. , {"/foo\\baz/bong/", "/foo\\baz/bong/bar", "bar"}
  39. , {"/foo\\baz/bong", "/foo\\baz/bar", "bar"}
  40. };
  41. int main()
  42. {
  43. using namespace fs;
  44. for (auto const & TC : TestCases) {
  45. path p(TC.value);
  46. assert(p == TC.value);
  47. path& Ref = (p.replace_filename(TC.filename));
  48. assert(p == TC.expect);
  49. assert(&Ref == &p);
  50. // Tests Effects "as-if": remove_filename() append(filename)
  51. {
  52. path p2(TC.value);
  53. path replace(TC.filename);
  54. p2.remove_filename();
  55. p2 /= replace;
  56. assert(p2 == p);
  57. }
  58. }
  59. }