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