remove_filename.pass.cpp 1.7 KB

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