brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 5779699 Raw
63 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// path& make_preferred()16 17#include <filesystem>18#include <cassert>19#include <string>20#include <type_traits>21 22#include "test_iterators.h"23#include "count_new.h"24namespace fs = std::filesystem;25 26struct MakePreferredTestcase {27  const char* value;28  const char* expected_posix;29  const char* expected_windows;30};31 32const MakePreferredTestcase TestCases[] =33  {34      {"", "", ""}35    , {"hello_world", "hello_world", "hello_world"}36    , {"/", "/", "\\"}37    , {"/foo/bar/baz/", "/foo/bar/baz/", "\\foo\\bar\\baz\\"}38    , {"\\", "\\", "\\"}39    , {"\\foo\\bar\\baz\\", "\\foo\\bar\\baz\\", "\\foo\\bar\\baz\\"}40    , {"\\foo\\/bar\\/baz\\", "\\foo\\/bar\\/baz\\", "\\foo\\\\bar\\\\baz\\"}41  };42 43int main(int, char**)44{45  // This operation is an identity operation on linux.46  // On windows, compare with preferred_win, if set.47  using namespace fs;48  for (auto const & TC : TestCases) {49    path p(TC.value);50    assert(p == TC.value);51    path& Ref = (p.make_preferred());52#ifdef _WIN3253    std::string s(TC.expected_windows);54#else55    std::string s(TC.expected_posix);56#endif57    assert(p.string() == s);58    assert(&Ref == &p);59  }60 61  return 0;62}63