source.pass.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 "filesystem_include.hpp"
  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. template <class CharT>
  24. void RunTestCase(MultiStringType const& MS) {
  25. using namespace fs;
  26. const char* Expect = MS;
  27. const CharT* TestPath = MS;
  28. const CharT* TestPathEnd = StrEnd(TestPath);
  29. const std::size_t Size = TestPathEnd - TestPath;
  30. const std::size_t SSize = StrEnd(Expect) - Expect;
  31. assert(Size == SSize);
  32. // StringTypes
  33. {
  34. const std::basic_string<CharT> S(TestPath);
  35. path p(S);
  36. assert(p.native() == Expect);
  37. assert(p.string<CharT>() == TestPath);
  38. assert(p.string<CharT>() == S);
  39. }
  40. {
  41. const std::basic_string_view<CharT> S(TestPath);
  42. path p(S);
  43. assert(p.native() == Expect);
  44. assert(p.string<CharT>() == TestPath);
  45. assert(p.string<CharT>() == S);
  46. }
  47. // Char* pointers
  48. {
  49. path p(TestPath);
  50. assert(p.native() == Expect);
  51. assert(p.string<CharT>() == TestPath);
  52. }
  53. {
  54. path p(TestPath, TestPathEnd);
  55. assert(p.native() == Expect);
  56. assert(p.string<CharT>() == TestPath);
  57. }
  58. // Iterators
  59. {
  60. using It = input_iterator<const CharT*>;
  61. path p(It{TestPath});
  62. assert(p.native() == Expect);
  63. assert(p.string<CharT>() == TestPath);
  64. }
  65. {
  66. using It = input_iterator<const CharT*>;
  67. path p(It{TestPath}, It{TestPathEnd});
  68. assert(p.native() == Expect);
  69. assert(p.string<CharT>() == TestPath);
  70. }
  71. }
  72. void test_sfinae() {
  73. using namespace fs;
  74. {
  75. using It = const char* const;
  76. static_assert(std::is_constructible<path, It>::value, "");
  77. }
  78. {
  79. using It = input_iterator<const char*>;
  80. static_assert(std::is_constructible<path, It>::value, "");
  81. }
  82. {
  83. struct Traits {
  84. using iterator_category = std::input_iterator_tag;
  85. using value_type = const char;
  86. using pointer = const char*;
  87. using reference = const char&;
  88. using difference_type = std::ptrdiff_t;
  89. };
  90. using It = input_iterator<const char*, Traits>;
  91. static_assert(std::is_constructible<path, It>::value, "");
  92. }
  93. {
  94. using It = output_iterator<const char*>;
  95. static_assert(!std::is_constructible<path, It>::value, "");
  96. }
  97. {
  98. static_assert(!std::is_constructible<path, int*>::value, "");
  99. }
  100. }
  101. int main() {
  102. for (auto const& MS : PathList) {
  103. RunTestCase<char>(MS);
  104. RunTestCase<wchar_t>(MS);
  105. RunTestCase<char16_t>(MS);
  106. RunTestCase<char32_t>(MS);
  107. }
  108. test_sfinae();
  109. }