replace_extension.pass.cpp 1.7 KB

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