source.pass.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. void test_sfinae() {
  74. using namespace fs;
  75. {
  76. using It = const char* const;
  77. static_assert(std::is_constructible<path, It>::value, "");
  78. }
  79. {
  80. using It = input_iterator<const char*>;
  81. static_assert(std::is_constructible<path, It>::value, "");
  82. }
  83. {
  84. struct Traits {
  85. using iterator_category = std::input_iterator_tag;
  86. using value_type = const char;
  87. using pointer = const char*;
  88. using reference = const char&;
  89. using difference_type = std::ptrdiff_t;
  90. };
  91. using It = input_iterator<const char*, Traits>;
  92. static_assert(std::is_constructible<path, It>::value, "");
  93. }
  94. {
  95. using It = output_iterator<const char*>;
  96. static_assert(!std::is_constructible<path, It>::value, "");
  97. }
  98. {
  99. static_assert(!std::is_constructible<path, int*>::value, "");
  100. }
  101. }
  102. int main() {
  103. for (auto const& MS : PathList) {
  104. RunTestCase<char>(MS);
  105. RunTestCase<wchar_t>(MS);
  106. RunTestCase<char16_t>(MS);
  107. RunTestCase<char32_t>(MS);
  108. }
  109. test_sfinae();
  110. }