libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

comparisons.pass.cpp (2376B)


      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 // <filesystem>
     13 
     14 // class directory_entry
     15 
     16 // bool operator==(directory_entry const&) const noexcept;
     17 // bool operator!=(directory_entry const&) const noexcept;
     18 // bool operator< (directory_entry const&) const noexcept;
     19 // bool operator<=(directory_entry const&) const noexcept;
     20 // bool operator> (directory_entry const&) const noexcept;
     21 // bool operator>=(directory_entry const&) const noexcept;
     22 
     23 
     24 #include "filesystem_include.hpp"
     25 #include <type_traits>
     26 #include <cassert>
     27 
     28 
     29 #define CHECK_OP(Op) \
     30   static_assert(std::is_same<decltype(ce. operator Op (ce)), bool>::value, ""); \
     31   static_assert(noexcept(ce.operator Op (ce)), "Operation must be noexcept" )
     32 
     33 void test_comparison_signatures() {
     34   using namespace fs;
     35   path const p("foo/bar/baz");
     36   // Check that the operators are member functions with the correct signatures.
     37   {
     38     directory_entry const ce(p);
     39     CHECK_OP(==);
     40     CHECK_OP(!=);
     41     CHECK_OP(< );
     42     CHECK_OP(<=);
     43     CHECK_OP(> );
     44     CHECK_OP(>=);
     45   }
     46 }
     47 #undef CHECK_OP
     48 
     49 // The actual semantics of the comparisons are testing via paths operators.
     50 void test_comparisons_simple() {
     51   using namespace fs;
     52   typedef std::pair<path, path> TestType;
     53   TestType TestCases[] =
     54   {
     55       {"", ""},
     56       {"", "a"},
     57       {"a", "a"},
     58       {"a", "b"},
     59       {"foo/bar/baz", "foo/bar/baz/"}
     60   };
     61   auto TestFn = [](path const& LHS, const directory_entry& LHSE,
     62                    path const& RHS, const directory_entry& RHSE) {
     63     assert((LHS == RHS) == (LHSE == RHSE));
     64     assert((LHS != RHS) == (LHSE != RHSE));
     65     assert((LHS < RHS) ==  (LHSE < RHSE));
     66     assert((LHS <= RHS) == (LHSE <= RHSE));
     67     assert((LHS > RHS) ==  (LHSE > RHSE));
     68     assert((LHS >= RHS) == (LHSE >= RHSE));
     69   };
     70   for (auto const& TC : TestCases) {
     71     const directory_entry L(TC.first);
     72     const directory_entry R(TC.second);
     73     TestFn(TC.first,  L, TC.second, R);
     74     TestFn(TC.second, R, TC.first, L);
     75   }
     76 }
     77 
     78 int main() {
     79   test_comparison_signatures();
     80   test_comparisons_simple();
     81 }