brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 47a56c1 Raw
78 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& replace_filename( const path& replacement );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 ReplaceFilenameTestcase {27  const char* value;28  const char* expect;29  const char* filename;30};31 32const ReplaceFilenameTestcase TestCases[] =33  {34      {"/foo", "/bar", "bar"}35    , {"/foo", "/", ""}36    , {"foo", "bar", "bar"}37    , {"/", "/bar", "bar"}38#ifdef _WIN3239    , {"\\", "\\bar", "bar"}40#else41    , {"\\", "bar", "bar"}42#endif43    , {"///", "///bar", "bar"}44#ifdef _WIN3245    , {"\\\\", "\\\\bar", "bar"}46    , {"\\/\\", "\\/\\bar", "bar"}47#else48    , {"\\\\", "bar", "bar"}49    , {"\\/\\", "\\/bar", "bar"}50#endif51    , {".", "bar", "bar"}52    , {"..", "bar", "bar"}53    , {"/foo\\baz/bong/", "/foo\\baz/bong/bar", "bar"}54    , {"/foo\\baz/bong", "/foo\\baz/bar", "bar"}55  };56 57int main(int, char**)58{59  using namespace fs;60  for (auto const & TC : TestCases) {61    path p(TC.value);62    assert(p == TC.value);63    path& Ref = p.replace_filename(TC.filename);64    assert(p == TC.expect);65    assert(&Ref == &p);66    // Tests Effects "as-if": remove_filename() append(filename)67    {68      path p2(TC.value);69      path replace(TC.filename);70      p2.remove_filename();71      p2 /= replace;72      assert(p == p2);73    }74  }75 76  return 0;77}78