replace_filename.pass.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "filesystem_include.hpp"
  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. struct ReplaceFilenameTestcase {
  21. const char* value;
  22. const char* expect;
  23. const char* filename;
  24. };
  25. const ReplaceFilenameTestcase TestCases[] =
  26. {
  27. {"/foo", "/bar", "bar"}
  28. , {"/foo", "/", ""}
  29. , {"foo", "bar", "bar"}
  30. , {"/", "bar", "bar"}
  31. , {"\\", "bar", "bar"}
  32. , {"///", "bar", "bar"}
  33. , {"\\\\", "bar", "bar"}
  34. , {"\\/\\", "\\/bar", "bar"}
  35. , {".", "bar", "bar"}
  36. , {"..", "bar", "bar"}
  37. , {"/foo\\baz/bong/", "/foo\\baz/bong/bar", "bar"}
  38. , {"/foo\\baz/bong", "/foo\\baz/bar", "bar"}
  39. };
  40. int main()
  41. {
  42. using namespace fs;
  43. for (auto const & TC : TestCases) {
  44. path p(TC.value);
  45. assert(p == TC.value);
  46. path& Ref = (p.replace_filename(TC.filename));
  47. assert(p == TC.expect);
  48. assert(&Ref == &p);
  49. // Tests Effects "as-if": remove_filename() append(filename)
  50. {
  51. path p2(TC.value);
  52. path replace(TC.filename);
  53. p2.remove_filename();
  54. p2 /= replace;
  55. assert(p2 == p);
  56. }
  57. }
  58. }