1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++98, c++03 10 11 // <filesystem> 12 13 // class path 14 15 // template <class Source> 16 // path(const Source& source); 17 // template <class InputIterator> 18 // path(InputIterator first, InputIterator last); 19 20 21 #include "filesystem_include.h" 22 #include <iterator> 23 #include <type_traits> 24 #include <cassert> 25 26 #include "test_macros.h" 27 #include "filesystem_test_helper.h" 28 29 30 31 template <class It> 32 std::reverse_iterator<It> mkRev(It it) { 33 return std::reverse_iterator<It>(it); 34 } 35 36 void checkIteratorConcepts() { 37 using namespace fs; 38 using It = path::iterator; 39 using Traits = std::iterator_traits<It>; 40 ASSERT_SAME_TYPE(Traits::iterator_category, std::bidirectional_iterator_tag); 41 ASSERT_SAME_TYPE(Traits::value_type, path); 42 ASSERT_SAME_TYPE(Traits::pointer, path const*); 43 ASSERT_SAME_TYPE(Traits::reference, path const&); 44 { 45 It it; 46 ASSERT_SAME_TYPE(It&, decltype(++it)); 47 ASSERT_SAME_TYPE(It, decltype(it++)); 48 ASSERT_SAME_TYPE(It&, decltype(--it)); 49 ASSERT_SAME_TYPE(It, decltype(it--)); 50 ASSERT_SAME_TYPE(Traits::reference, decltype(*it)); 51 ASSERT_SAME_TYPE(Traits::pointer, decltype(it.operator->())); 52 ASSERT_SAME_TYPE(std::string const&, decltype(it->native())); 53 ASSERT_SAME_TYPE(bool, decltype(it == it)); 54 ASSERT_SAME_TYPE(bool, decltype(it != it)); 55 } 56 { 57 path const p; 58 ASSERT_SAME_TYPE(It, decltype(p.begin())); 59 ASSERT_SAME_TYPE(It, decltype(p.end())); 60 assert(p.begin() == p.end()); 61 } 62 } 63 64 void checkBeginEndBasic() { 65 using namespace fs; 66 using It = path::iterator; 67 { 68 path const p; 69 ASSERT_SAME_TYPE(It, decltype(p.begin())); 70 ASSERT_SAME_TYPE(It, decltype(p.end())); 71 assert(p.begin() == p.end()); 72 } 73 { 74 path const p("foo"); 75 It default_constructed; 76 default_constructed = p.begin(); 77 assert(default_constructed == p.begin()); 78 assert(default_constructed != p.end()); 79 default_constructed = p.end(); 80 assert(default_constructed == p.end()); 81 assert(default_constructed != p.begin()); 82 } 83 { 84 path p("//root_name//first_dir////second_dir"); 85 const path expect[] = {"/", "root_name", "first_dir", "second_dir"}; 86 assert(checkCollectionsEqual(p.begin(), p.end(), std::begin(expect), std::end(expect))); 87 assert(checkCollectionsEqualBackwards(p.begin(), p.end(), std::begin(expect), std::end(expect))); 88 89 } 90 { 91 path p("////foo/bar/baz///"); 92 const path expect[] = {"/", "foo", "bar", "baz", ""}; 93 assert(checkCollectionsEqual(p.begin(), p.end(), std::begin(expect), std::end(expect))); 94 assert(checkCollectionsEqualBackwards(p.begin(), p.end(), std::begin(expect), std::end(expect))); 95 96 } 97 98 } 99 100 int main(int, char**) { 101 using namespace fs; 102 checkIteratorConcepts(); 103 checkBeginEndBasic(); // See path.decompose.pass.cpp for more tests. 104 105 return 0; 106 } 107