replace_filename.pass.cpp 1.7 KB

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