remove_filename.pass.cpp 1.6 KB

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