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