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