brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · 0d9dc50 Raw
139 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// <filesystem>12 13// class path14 15// template <class Source>16//      path(const Source& source);17// template <class InputIterator>18//      path(InputIterator first, InputIterator last);19 20 21#include <filesystem>22#include <cassert>23#include <iterator>24#include <type_traits>25 26#include "test_macros.h"27namespace fs = std::filesystem;28 29template <class Iter1, class Iter2>30bool checkCollectionsEqual(31    Iter1 start1, Iter1 const end132  , Iter2 start2, Iter2 const end233  )34{35    while (start1 != end1 && start2 != end2) {36        if (*start1 != *start2) {37            return false;38        }39        ++start1; ++start2;40    }41    return (start1 == end1 && start2 == end2);42}43 44template <class Iter1, class Iter2>45bool checkCollectionsEqualBackwards(46    Iter1 const start1, Iter1 end147  , Iter2 const start2, Iter2 end248  )49{50    while (start1 != end1 && start2 != end2) {51        --end1; --end2;52        if (*end1 != *end2) {53            return false;54        }55    }56    return (start1 == end1 && start2 == end2);57}58 59void checkIteratorConcepts() {60  using namespace fs;61  using It = path::iterator;62  using Traits = std::iterator_traits<It>;63  ASSERT_SAME_TYPE(path::const_iterator, It);64#if TEST_STD_VER > 1765  static_assert(std::bidirectional_iterator<It>);66#endif67  ASSERT_SAME_TYPE(Traits::value_type, path);68  LIBCPP_STATIC_ASSERT(std::is_same<Traits::iterator_category, std::input_iterator_tag>::value, "");69  LIBCPP_STATIC_ASSERT(std::is_same<Traits::pointer, path const*>::value, "");70  LIBCPP_STATIC_ASSERT(std::is_same<Traits::reference, path>::value, "");71  {72    It it;73    ASSERT_SAME_TYPE(It&, decltype(++it));74    ASSERT_SAME_TYPE(It, decltype(it++));75    ASSERT_SAME_TYPE(It&, decltype(--it));76    ASSERT_SAME_TYPE(It, decltype(it--));77    ASSERT_SAME_TYPE(Traits::reference, decltype(*it));78    ASSERT_SAME_TYPE(Traits::pointer, decltype(it.operator->()));79#ifdef _WIN3280    ASSERT_SAME_TYPE(std::wstring const&, decltype(it->native()));81#else82    ASSERT_SAME_TYPE(std::string const&, decltype(it->native()));83#endif84    ASSERT_SAME_TYPE(bool, decltype(it == it));85    ASSERT_SAME_TYPE(bool, decltype(it != it));86  }87  {88    path const p;89    ASSERT_SAME_TYPE(It, decltype(p.begin()));90    ASSERT_SAME_TYPE(It, decltype(p.end()));91    assert(p.begin() == p.end());92  }93}94 95void checkBeginEndBasic() {96  using namespace fs;97  using It = path::iterator;98  {99    path const p;100    ASSERT_SAME_TYPE(It, decltype(p.begin()));101    ASSERT_SAME_TYPE(It, decltype(p.end()));102    assert(p.begin() == p.end());103  }104  {105    path const p("foo");106    It default_constructed;107    default_constructed = p.begin();108    assert(default_constructed == p.begin());109    assert(default_constructed != p.end());110    default_constructed = p.end();111    assert(default_constructed == p.end());112    assert(default_constructed != p.begin());113  }114  {115    path p("//root_name//first_dir////second_dir");116#ifdef _WIN32117    const path expect[] = {"//root_name", "/", "first_dir", "second_dir"};118#else119    const path expect[] = {"/", "root_name", "first_dir", "second_dir"};120#endif121    assert(checkCollectionsEqual(p.begin(), p.end(), std::begin(expect), std::end(expect)));122    assert(checkCollectionsEqualBackwards(p.begin(), p.end(), std::begin(expect), std::end(expect)));123  }124  {125    path p("////foo/bar/baz///");126    const path expect[] = {"/", "foo", "bar", "baz", ""};127    assert(checkCollectionsEqual(p.begin(), p.end(), std::begin(expect), std::end(expect)));128    assert(checkCollectionsEqualBackwards(p.begin(), p.end(), std::begin(expect), std::end(expect)));129  }130}131 132int main(int, char**) {133  using namespace fs;134  checkIteratorConcepts();135  checkBeginEndBasic(); // See path.decompose.pass.cpp for more tests.136 137  return 0;138}139