Skip to content

Commit

Permalink
Extend hasFacet testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
HaxyM authored Sep 19, 2024
1 parent f3360c5 commit 0579391
Showing 1 changed file with 41 additions and 24 deletions.
65 changes: 41 additions & 24 deletions test/hasfacettest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <tuple>
#include <utility>

#include "../include/crap/locale.d/moneypunct.h"
#include "../include/crap/locale.d/numpunct.h"
#include "../include/crap/utility.d/typelist.h"

struct empty {};

Expand All @@ -15,45 +17,60 @@ template <class Type> struct withFacet
using facet = Type;
};

template <class Type> bool test_hasFacetNumpunct()
template <class Type, template <class> class Facet> bool test_hasFacet()
{
//Negative tests:
//No facet tests.
static_assert(!(crap :: hasFacet <std :: numpunct<Type>, void> :: value), "Void has no facet.");
static_assert(!(crap :: hasFacet <std :: numpunct<Type>, empty> :: value), "Empty has no facet.");
static_assert(!(crap :: hasFacet <crap :: numpunct<Type>, void> :: value), "Void has no facet.");
static_assert(!(crap :: hasFacet <crap :: numpunct<Type>, empty> :: value), "Empty has no facet.");
static_assert(!(crap :: hasFacet <Facet<Type>, void> :: value), "Void has no facet.");
static_assert(!(crap :: hasFacet <Facet<Type>, empty> :: value), "Empty has no facet.");
//Invalid facet tests.
static_assert(!(crap :: hasFacet <crap :: numpunct<Type>, withFacet<void> > :: value), "Facet is void.");
static_assert(!(crap :: hasFacet <crap :: numpunct<Type>, withFacet<empty> > :: value), "Facet is empty.");
static_assert(!(crap :: hasFacet <crap :: numpunct<Type>, withFacet<std :: tuple<> > > :: value),
"Facet is not having numpunct.");
static_assert(!(crap :: hasFacet <crap :: numpunct<Type>, withFacet<std :: tuple<void> > > :: value),
"Facet is not having numpunct.");
static_assert(!(crap :: hasFacet <crap :: numpunct<Type>, withFacet<std :: pair<void, empty> > > :: value),
"Facet is not having numpunct.");
static_assert(!(crap :: hasFacet <crap :: numpunct<Type>, withFacet<std :: tuple<void, empty, void> > > :: value),
"Facet is not having numpunct.");
static_assert(!(crap :: hasFacet <crap :: numpunct<Type>, withFacet<std :: pair<crap :: numpunct<Type>, crap :: numpunct<Type>> > > :: value),
"Facet is having many numpunct.");
static_assert(!(crap :: hasFacet <crap :: numpunct<Type>, withFacet<std :: tuple<crap :: numpunct<Type>, void, crap :: numpunct<Type>> > > :: value),
"Facet is having many numpunct.");
static_assert(!(crap :: hasFacet <Facet<Type>, withFacet<void> > :: value), "Facet is void.");
static_assert(!(crap :: hasFacet <Facet<Type>, withFacet<empty> > :: value), "Facet is empty.");
static_assert(!(crap :: hasFacet <Facet<Type>, withFacet<std :: tuple<> > > :: value),
"Facet is not having proper facet type.");
static_assert(!(crap :: hasFacet <Facet<Type>, withFacet<crap :: typeList<> > > :: value),
"Facet is not having proper facet type.");
static_assert(!(crap :: hasFacet <Facet<Type>, withFacet<std :: tuple<void> > > :: value),
"Facet is not having proper facet type.");
static_assert(!(crap :: hasFacet <Facet<Type>, withFacet<crap :: typeList<void> > > :: value),
"Facet is not having proper facet type.");
static_assert(!(crap :: hasFacet <Facet<Type>, withFacet<std :: pair<void, empty> > > :: value),
"Facet is not having proper facet type.");
static_assert(!(crap :: hasFacet <Facet<Type>, withFacet<std :: tuple<void, empty, void> > > :: value),
"Facet is not having proper facet type.");
static_assert(!(crap :: hasFacet <Facet<Type>, withFacet<crap :: typeList<void, empty, void> > > :: value),
"Facet is not having proper facet type.");
static_assert(!(crap :: hasFacet <Facet<Type>, withFacet<std :: pair<Facet<Type>, Facet<Type> > > > :: value),
"Facet is having many proper facet types.");
static_assert(!(crap :: hasFacet <Facet<Type>, withFacet<std :: tuple<Facet<Type>, void, Facet<Type> > > > :: value),
"Facet is having many proper facet types.");
static_assert(!(crap :: hasFacet <Facet<Type>, withFacet<crap :: typeList<Facet<Type>, void, Facet<Type> > > > :: value),
"Facet is having many proper facet types.");
//Positive tests:
//Valid facet tests.
static_assert(crap :: hasFacet <crap :: numpunct<Type>, withFacet<crap :: numpunct<Type> > > :: value, "Facet correct.");
static_assert(crap :: hasFacet <crap :: numpunct<Type>, withFacet<std :: pair<crap :: numpunct<Type>, void> > > :: value,
static_assert(crap :: hasFacet <Facet<Type>, withFacet<Facet<Type> > > :: value, "Facet correct.");
static_assert(crap :: hasFacet <Facet<Type>, withFacet<std :: pair<Facet<Type>, void> > > :: value,
"Facet correct.");
static_assert(crap :: hasFacet <crap :: numpunct<Type>, withFacet<std :: tuple<void, crap :: numpunct<Type>, void> > > :: value,
static_assert(crap :: hasFacet <Facet<Type>, withFacet<std :: tuple<void, Facet<Type>, void> > > :: value,
"Facet correct.");
static_assert(crap :: hasFacet <Facet<Type>, withFacet<crap :: typeList<void, Facet<Type>, void> > > :: value,
"Facet correct.");
return true;
}

template <class Type> using moneypunctInternational = crap :: moneypunct<Type, true>;
template <class Type> using moneypunctShort = crap :: moneypunct<Type, false>;

int main()
{
const bool results[] =
{
test_hasFacetNumpunct<char>(),
test_hasFacetNumpunct<wchar_t>()
test_hasFacet<char, moneypunctInternational>(),
test_hasFacet<wchar_t, moneypunctInternational>(),
test_hasFacet<char, moneypunctShort>(),
test_hasFacet<wchar_t, moneypunctShort>(),
test_hasFacet<char, crap :: numpunct>(),
test_hasFacet<wchar_t, crap :: numpunct>()
};
return std :: accumulate(std :: begin(results), std :: end(results), true, std :: logical_and<bool>())
? EXIT_SUCCESS
Expand Down

0 comments on commit 0579391

Please sign in to comment.