replace_filename.pass.cpp 1.7 KB

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