remove_filename.pass.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03
  9. // <filesystem>
  10. // class path
  11. // path& remove_filename()
  12. #include "filesystem_include.hpp"
  13. #include <type_traits>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. #include "test_iterators.h"
  17. #include "count_new.hpp"
  18. #include "filesystem_test_helper.hpp"
  19. #include "verbose_assert.h"
  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/bar", "foo/"}
  35. , {"foo/", "foo/"}
  36. , {"//foo", "//"}
  37. , {"//foo/", "//foo/"}
  38. , {"//foo///", "//foo///"}
  39. , {"///foo", "///"}
  40. , {"///foo/", "///foo/"}
  41. , {"/foo/", "/foo/"}
  42. , {"/foo/.", "/foo/"}
  43. , {"/foo/..", "/foo/"}
  44. , {"/foo/////", "/foo/////"}
  45. , {"/foo\\\\", "/"}
  46. , {"/foo//\\/", "/foo//\\/"}
  47. , {"///foo", "///"}
  48. , {"file.txt", ""}
  49. , {"bar/../baz/./file.txt", "bar/../baz/./"}
  50. };
  51. int main(int, char**)
  52. {
  53. using namespace fs;
  54. for (auto const & TC : TestCases) {
  55. path const p_orig(TC.value);
  56. path p(p_orig);
  57. assert(p == TC.value);
  58. path& Ref = (p.remove_filename());
  59. ASSERT_EQ(p, TC.expect) << DISPLAY(p_orig);
  60. assert(&Ref == &p);
  61. assert(!p.has_filename());
  62. }
  63. return 0;
  64. }