replace_extension.pass.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_extension(path const& p = path())
  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. struct ReplaceExtensionTestcase {
  20. const char* value;
  21. const char* expect;
  22. const char* extension;
  23. };
  24. const ReplaceExtensionTestcase TestCases[] =
  25. {
  26. {"", "", ""}
  27. , {"foo.cpp", "foo", ""}
  28. , {"foo.cpp", "foo.", "."}
  29. , {"foo..cpp", "foo..txt", "txt"}
  30. , {"", ".txt", "txt"}
  31. , {"", ".txt", ".txt"}
  32. , {"/foo", "/foo.txt", ".txt"}
  33. , {"/foo", "/foo.txt", "txt"}
  34. , {"/foo.cpp", "/foo.txt", ".txt"}
  35. , {"/foo.cpp", "/foo.txt", "txt"}
  36. };
  37. const ReplaceExtensionTestcase NoArgCases[] =
  38. {
  39. {"", "", ""}
  40. , {"foo", "foo", ""}
  41. , {"foo.cpp", "foo", ""}
  42. , {"foo..cpp", "foo.", ""}
  43. };
  44. int main(int, char**)
  45. {
  46. using namespace fs;
  47. for (auto const & TC : TestCases) {
  48. path p(TC.value);
  49. assert(p == TC.value);
  50. path& Ref = (p.replace_extension(TC.extension));
  51. assert(p == TC.expect);
  52. assert(&Ref == &p);
  53. }
  54. for (auto const& TC : NoArgCases) {
  55. path p(TC.value);
  56. assert(p == TC.value);
  57. path& Ref = (p.replace_extension());
  58. assert(p == TC.expect);
  59. assert(&Ref == &p);
  60. }
  61. return 0;
  62. }