diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-07-23 03:10:56 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-07-23 03:10:56 +0000 |
commit | 0fdab5eb69ca4b2e9048526b33948af72976c7bc (patch) | |
tree | f46bce4590d4f9abf9281f6e0998bc8cbb6e57f8 /libcxx/test/std/experimental/filesystem/class.path | |
parent | 796331c026a6cd33624c0f22e4e289fc89093b43 (diff) | |
download | bcm5719-llvm-0fdab5eb69ca4b2e9048526b33948af72976c7bc.tar.gz bcm5719-llvm-0fdab5eb69ca4b2e9048526b33948af72976c7bc.zip |
Implement P0392r0. Integrate filesystem::path and string_view.
llvm-svn: 276511
Diffstat (limited to 'libcxx/test/std/experimental/filesystem/class.path')
5 files changed, 116 insertions, 3 deletions
diff --git a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.append.pass.cpp b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.append.pass.cpp index 1118497e06a..93892fbe10e 100644 --- a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.append.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.append.pass.cpp @@ -24,6 +24,7 @@ #include <experimental/filesystem> #include <type_traits> +#include <string_view> #include <cassert> #include "test_macros.h" @@ -77,6 +78,7 @@ void doAppendSourceAllocTest(AppendOperatorTestcase const& TC) using namespace fs; using Ptr = CharT const*; using Str = std::basic_string<CharT>; + using StrView = std::basic_string_view<CharT>; using InputIter = input_iterator<Ptr>; const Ptr L = TC.lhs; @@ -99,6 +101,16 @@ void doAppendSourceAllocTest(AppendOperatorTestcase const& TC) } assert(LHS == E); } + // basic_string_view + { + path LHS(L); PathReserve(LHS, ReserveSize); + StrView RHS(R); + { + DisableAllocationGuard g; + LHS /= RHS; + } + assert(LHS == E); + } // CharT* { path LHS(L); PathReserve(LHS, ReserveSize); @@ -153,6 +165,7 @@ void doAppendSourceTest(AppendOperatorTestcase const& TC) using namespace fs; using Ptr = CharT const*; using Str = std::basic_string<CharT>; + using StrView = std::basic_string_view<CharT>; using InputIter = input_iterator<Ptr>; const Ptr L = TC.lhs; const Ptr R = TC.rhs; @@ -172,6 +185,21 @@ void doAppendSourceTest(AppendOperatorTestcase const& TC) assert(LHS == E); assert(&Ref == &LHS); } + // basic_string_view + { + path LHS(L); + StrView RHS(R); + path& Ref = (LHS /= RHS); + assert(LHS == E); + assert(&Ref == &LHS); + } + { + path LHS(L); + StrView RHS(R); + path& Ref = LHS.append(RHS); + assert(LHS == E); + assert(&Ref == &LHS); + } // Char* { path LHS(L); diff --git a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp index 4c2d5112d10..ae725a88590 100644 --- a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp @@ -23,6 +23,7 @@ #include <experimental/filesystem> #include <type_traits> +#include <string_view> #include <cassert> #include "test_macros.h" @@ -69,6 +70,32 @@ void RunTestCase(MultiStringType const& MS) { assert(p.string<CharT>() == TestPath); assert(p.string<CharT>() == S); } + // basic_string<Char, Traits, Alloc> + { + const std::basic_string_view<CharT> S(TestPath); + path p; PathReserve(p, S.length() + 1); + { + // string provides a contigious iterator. No allocation needed. + DisableAllocationGuard g; + path& pref = (p = S); + assert(&pref == &p); + } + assert(p.native() == Expect); + assert(p.string<CharT>() == TestPath); + assert(p.string<CharT>() == S); + } + { + const std::basic_string_view<CharT> S(TestPath); + path p; PathReserve(p, S.length() + 1); + { + DisableAllocationGuard g; + path& pref = p.assign(S); + assert(&pref == &p); + } + assert(p.native() == Expect); + assert(p.string<CharT>() == TestPath); + assert(p.string<CharT>() == S); + } ////////////////////////////////////////////////////////////////////////////// // Char* pointers { diff --git a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.compare.pass.cpp b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.compare.pass.cpp index 557c1b24d88..64f57f13fb2 100644 --- a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.compare.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.compare.pass.cpp @@ -80,6 +80,7 @@ int main() const path p1(TC.LHS); const path p2(TC.RHS); const std::string R(TC.RHS); + const std::string_view RV(TC.RHS); const int E = TC.expect; { // compare(...) functions DisableAllocationGuard g; // none of these operations should allocate @@ -88,7 +89,8 @@ int main() int ret1 = p1.compare(p2); int ret2 = p1.compare(R); int ret3 = p1.compare(TC.RHS); - assert(ret1 == ret2 && ret1 == ret3); + int ret4 = p1.compare(RV); + assert(ret1 == ret2 && ret1 == ret3 && ret1 == ret4); int normalized_ret = ret1 < 0 ? -1 : (ret1 > 0 ? 1 : 0); assert(normalized_ret == E); diff --git a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.concat.pass.cpp b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.concat.pass.cpp index 6e00afe0b49..cd627b8c842 100644 --- a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.concat.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.concat.pass.cpp @@ -14,8 +14,9 @@ // class path // path& operator+=(const path& x); -// path& operator+=(const string_type& x); // Implemented as Source template -// path& operator+=(const value_type* x); // Implemented as Source template +// path& operator+=(const string_type& x); +// path& operator+=(string_view x); +// path& operator+=(const value_type* x); // path& operator+=(value_type x); // template <class Source> // path& operator+=(const Source& x); @@ -29,6 +30,8 @@ #include <experimental/filesystem> #include <type_traits> +#include <string> +#include <string_view> #include <cassert> #include "test_macros.h" @@ -82,6 +85,7 @@ void doConcatSourceAllocTest(ConcatOperatorTestcase const& TC) using namespace fs; using Ptr = CharT const*; using Str = std::basic_string<CharT>; + using StrView = std::basic_string_view<CharT>; using InputIter = input_iterator<Ptr>; const Ptr L = TC.lhs; @@ -98,6 +102,16 @@ void doConcatSourceAllocTest(ConcatOperatorTestcase const& TC) } assert(LHS == E); } + // basic_string_view + { + path LHS(L); PathReserve(LHS, ReserveSize); + StrView RHS(R); + { + DisableAllocationGuard g; + LHS += RHS; + } + assert(LHS == E); + } // CharT* { path LHS(L); PathReserve(LHS, ReserveSize); @@ -152,6 +166,7 @@ void doConcatSourceTest(ConcatOperatorTestcase const& TC) using namespace fs; using Ptr = CharT const*; using Str = std::basic_string<CharT>; + using StrView = std::basic_string_view<CharT>; using InputIter = input_iterator<Ptr>; const Ptr L = TC.lhs; const Ptr R = TC.rhs; @@ -171,6 +186,21 @@ void doConcatSourceTest(ConcatOperatorTestcase const& TC) assert(LHS == E); assert(&Ref == &LHS); } + // basic_string_view + { + path LHS(L); + StrView RHS(R); + path& Ref = (LHS += RHS); + assert(LHS == E); + assert(&Ref == &LHS); + } + { + path LHS(L); + StrView RHS(R); + path& Ref = LHS.concat(RHS); + assert(LHS == E); + assert(&Ref == &LHS); + } // Char* { path LHS(L); @@ -246,6 +276,13 @@ int main() assert(LHS == (const char*)TC.expect); assert(&Ref == &LHS); } + { + path LHS((const char*)TC.lhs); + std::string_view RHS((const char*)TC.rhs); + path& Ref = (LHS += RHS); + assert(LHS == (const char*)TC.expect); + assert(&Ref == &LHS); + } doConcatSourceTest<char> (TC); doConcatSourceTest<wchar_t> (TC); doConcatSourceTest<char16_t>(TC); @@ -265,6 +302,18 @@ int main() } assert(LHS == E); } + { + path LHS((const char*)TC.lhs); + std::string_view RHS((const char*)TC.rhs); + const char* E = TC.expect; + PathReserve(LHS, StrLen(E) + 5); + { + DisableAllocationGuard g; + path& Ref = (LHS += RHS); + assert(&Ref == &LHS); + } + assert(LHS == E); + } doConcatSourceAllocTest<char>(TC); doConcatSourceAllocTest<wchar_t>(TC); } diff --git a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp index d89e7c815ef..402225de11b 100644 --- a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp @@ -47,6 +47,13 @@ void RunTestCase(MultiStringType const& MS) { assert(p.string<CharT>() == TestPath); assert(p.string<CharT>() == S); } + { + const std::basic_string_view<CharT> S(TestPath); + path p(S); + assert(p.native() == Expect); + assert(p.string<CharT>() == TestPath); + assert(p.string<CharT>() == S); + } // Char* pointers { path p(TestPath); |