remove_filename.pass.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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& remove_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 "verbose_assert.h"
  21. struct RemoveFilenameTestcase {
  22. const char* value;
  23. const char* expect;
  24. };
  25. const RemoveFilenameTestcase TestCases[] =
  26. {
  27. {"", ""}
  28. , {"/", "/"}
  29. , {"//", "//"}
  30. , {"///", "///"}
  31. , {"\\", ""}
  32. , {".", ""}
  33. , {"..", ""}
  34. , {"/foo", "/"}
  35. , {"foo/bar", "foo/"}
  36. , {"foo/", "foo/"}
  37. , {"//foo", "//"}
  38. , {"//foo/", "//foo/"}
  39. , {"//foo///", "//foo///"}
  40. , {"///foo", "///"}
  41. , {"///foo/", "///foo/"}
  42. , {"/foo/", "/foo/"}
  43. , {"/foo/.", "/foo/"}
  44. , {"/foo/..", "/foo/"}
  45. , {"/foo/////", "/foo/////"}
  46. , {"/foo\\\\", "/"}
  47. , {"/foo//\\/", "/foo//\\/"}
  48. , {"///foo", "///"}
  49. , {"file.txt", ""}
  50. , {"bar/../baz/./file.txt", "bar/../baz/./"}
  51. };
  52. int main()
  53. {
  54. using namespace fs;
  55. for (auto const & TC : TestCases) {
  56. path const p_orig(TC.value);
  57. path p(p_orig);
  58. assert(p == TC.value);
  59. path& Ref = (p.remove_filename());
  60. ASSERT_EQ(p, TC.expect) << DISPLAY(p_orig);
  61. assert(&Ref == &p);
  62. assert(!p.has_filename());
  63. }
  64. }