source.pass.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. // template <class Source>
  13. // path(const Source& source);
  14. // template <class InputIterator>
  15. // path(InputIterator first, InputIterator last);
  16. #include <experimental/filesystem>
  17. #include <type_traits>
  18. #include <cassert>
  19. #include "test_macros.h"
  20. #include "test_iterators.h"
  21. #include "min_allocator.h"
  22. #include "filesystem_test_helper.hpp"
  23. namespace fs = std::experimental::filesystem;
  24. template <class CharT>
  25. void RunTestCase(MultiStringType const& MS) {
  26. using namespace fs;
  27. const char* Expect = MS;
  28. const CharT* TestPath = MS;
  29. const CharT* TestPathEnd = StrEnd(TestPath);
  30. const std::size_t Size = TestPathEnd - TestPath;
  31. const std::size_t SSize = StrEnd(Expect) - Expect;
  32. assert(Size == SSize);
  33. // StringTypes
  34. {
  35. const std::basic_string<CharT> S(TestPath);
  36. path p(S);
  37. assert(p.native() == Expect);
  38. assert(p.string<CharT>() == TestPath);
  39. assert(p.string<CharT>() == S);
  40. }
  41. {
  42. const std::basic_string_view<CharT> S(TestPath);
  43. path p(S);
  44. assert(p.native() == Expect);
  45. assert(p.string<CharT>() == TestPath);
  46. assert(p.string<CharT>() == S);
  47. }
  48. // Char* pointers
  49. {
  50. path p(TestPath);
  51. assert(p.native() == Expect);
  52. assert(p.string<CharT>() == TestPath);
  53. }
  54. {
  55. path p(TestPath, TestPathEnd);
  56. assert(p.native() == Expect);
  57. assert(p.string<CharT>() == TestPath);
  58. }
  59. // Iterators
  60. {
  61. using It = input_iterator<const CharT*>;
  62. path p(It{TestPath});
  63. assert(p.native() == Expect);
  64. assert(p.string<CharT>() == TestPath);
  65. }
  66. {
  67. using It = input_iterator<const CharT*>;
  68. path p(It{TestPath}, It{TestPathEnd});
  69. assert(p.native() == Expect);
  70. assert(p.string<CharT>() == TestPath);
  71. }
  72. }
  73. int main() {
  74. for (auto const& MS : PathList) {
  75. RunTestCase<char>(MS);
  76. RunTestCase<wchar_t>(MS);
  77. RunTestCase<char16_t>(MS);
  78. RunTestCase<char32_t>(MS);
  79. }
  80. }