diff options
Diffstat (limited to 'test.cc')
-rw-r--r-- | test.cc | 127 |
1 files changed, 73 insertions, 54 deletions
@@ -34,14 +34,14 @@ static_assert(::zp::isptr<int const volatile * const volatile>::val == true); static_assert(::zp::typequ<int,int>::val == true); static_assert(::zp::typequ<int,long>::val == false); -static_assert(::zp::typequ<::zp::i8m, ::std::uint_least8_t>::val == true); -static_assert(::zp::typequ<::zp::i8ms, ::std::int_least8_t>::val == true); -static_assert(::zp::typequ<::zp::i01m, ::std::uint_least16_t>::val == true); -static_assert(::zp::typequ<::zp::i01ms,::std::int_least16_t>::val == true); -static_assert(::zp::typequ<::zp::i02m, ::std::uint_least32_t>::val == true); -static_assert(::zp::typequ<::zp::i02ms,::std::int_least32_t>::val == true); -static_assert(::zp::typequ<::zp::i04m, ::std::uint_least64_t>::val == true); -static_assert(::zp::typequ<::zp::i04ms,::std::int_least64_t>::val == true); +static_assert(::zp::typequ<::zp::i8, ::std::uint_least8_t>::val == true); +static_assert(::zp::typequ<::zp::i8s, ::std::int_least8_t>::val == true); +static_assert(::zp::typequ<::zp::i01, ::std::uint_least16_t>::val == true); +static_assert(::zp::typequ<::zp::i01s,::std::int_least16_t>::val == true); +static_assert(::zp::typequ<::zp::i02, ::std::uint_least32_t>::val == true); +static_assert(::zp::typequ<::zp::i02s,::std::int_least32_t>::val == true); +static_assert(::zp::typequ<::zp::i04, ::std::uint_least64_t>::val == true); +static_assert(::zp::typequ<::zp::i04s,::std::int_least64_t>::val == true); static_assert(::zp::typequ<::zp::intptr,::std::uintptr_t>::val == true); static_assert(::zp::typequ<::zp::siz, ::std::size_t>::val == true); @@ -157,14 +157,14 @@ static_assert(::zp::maxval<long unsigned>::val == ::std::numeric_limits<lon static_assert(::zp::maxval<long long unsigned>::val == ::std::numeric_limits<long long unsigned>::max()); static_assert(::zp::maxval<wchar_t>::val == ::std::numeric_limits<wchar_t>::max()); -template<typename ltyp,typename rtyp> static auto cmp(int unsigned & num,int unsigned & numerr,long const ln,ltyp const & lvalref,rtyp const & rvalref) noexcept { +template<typename ltyp,typename rtyp> static auto cmp_eq(int unsigned & num,int unsigned & numerr,long const ln,ltyp const & lvalref,rtyp const & rvalref) noexcept { char const * const ltypnm = typeid (ltyp).name(); char const * const rtypnm = typeid (rtyp).name(); auto const getval = [](auto const & valref) { using typ = typename ::zp::remref<decltype (valref)>::typ; - if constexpr (::zp::ischrtyp<typ>::val) {return static_cast<::zp::i02m>(valref);} + if constexpr (::zp::ischrtyp<typ>::val) {return static_cast<::zp::i02>(valref);} else if constexpr (::zp::isptr<typ>::val) {return reinterpret_cast<void *>(valref);} else {return valref;} }; @@ -185,14 +185,14 @@ template<typename ltyp,typename rtyp> static auto cmp(int unsigned & num,int uns ::std::cout <<"\x1B[38;5;77mequal\x1B[0m\n"; } -#define cmp(lval,rval) (::cmp(num,numerr,__LINE__,(lval),(rval))) +#define cmp_eq(lval,rval) (::cmp_eq(num,numerr,__LINE__,(lval),(rval))) int main() { int unsigned num; int unsigned numerr = 0x0u; - auto const tst = [&num](char const * const cmp) noexcept { - ::std::cout <<"\n\x1B[38;5;75mtesting\x1B[0m " <<cmp <<"\n\n"; + auto const tst = [&num](char const * const cmp_eq) noexcept { + ::std::cout <<"\n\x1B[38;5;75mtesting\x1B[0m " <<cmp_eq <<"\n\n"; num = 0x0; }; @@ -200,6 +200,25 @@ int main() { ::std::cout <<"zp " <<::zp::ver.api <<"." <<::zp::ver.ext <<", run-time test\n"; try { + [&] { + tst("optionals"); + + ::zp::opt<::zp::i8s> opt = ::zp::nulopt; + + cmp_eq(opt.chk(),false); + + auto const fun = [](char const * msg) -> void { + ::std::cout << msg << ::std::endl; + + ::std::abort(); + }; + + opt = -0x45; + + cmp_eq(opt.chk(),true); + cmp_eq(opt.exp(fun,"expectation failed"),-0x45); + }(); + /*[&] { tst("vectors"); @@ -211,7 +230,7 @@ int main() { .x = +0x2, .y = -0x4, }; - cmp(::zp::dot(lvec2,rvec2),0xE); + cmp_eq(::zp::dot(lvec2,rvec2),0xE); ::zp::vec3<int> const lvec3 = { .x = +0x1, @@ -223,7 +242,7 @@ int main() { .y = -0x4, .z = +0x6, }; - cmp(::zp::dot(lvec3,rvec3),0x2C); + cmp_eq(::zp::dot(lvec3,rvec3),0x2C); ::zp::vec4<int> const lvec4 = { .x = +0x1, @@ -237,22 +256,22 @@ int main() { .z = +0x6, .w = -0x8, }; - cmp(::zp::dot(lvec4,rvec4),0x64); + cmp_eq(::zp::dot(lvec4,rvec4),0x64); auto const avec2 = ::zp::vadd(lvec2,rvec2); auto const svec2 = ::zp::vsub(lvec2,rvec2); - cmp(avec2.x,+0x3); - cmp(avec2.y,-0x7); - cmp(svec2.x,-0x1); - cmp(svec2.y,+0x1); + cmp_eq(avec2.x,+0x3); + cmp_eq(avec2.y,-0x7); + cmp_eq(svec2.x,-0x1); + cmp_eq(svec2.y,+0x1); }(); [&] { tst("special numbers"); - cmp(zp_isnanf( zp_nanf), true); - cmp(zp_isnand( zp_nand), true); - cmp(zp_isnandl(zp_nanld),true); + cmp_eq(zp_isnanf( zp_nanf), true); + cmp_eq(zp_isnand( zp_nand), true); + cmp_eq(zp_isnandl(zp_nanld),true); }();*/ [&] { @@ -260,19 +279,19 @@ int main() { ::zp::i04 filbuf; - cmp(::zp::memfil(&filbuf,0xFFu,0x8u),reinterpret_cast<char unsigned *>(&filbuf)+0x8u); - cmp(::zp::memfil(&filbuf,0x7Fu,0x4u),reinterpret_cast<char unsigned *>(&filbuf)+0x4u); - cmp(::zp::memfil(&filbuf,0x3Fu,0x2u),reinterpret_cast<char unsigned *>(&filbuf)+0x2u); - cmp(::zp::memfil(&filbuf,0x1Fu,0x1u),reinterpret_cast<char unsigned *>(&filbuf)+0x1u); + cmp_eq(::zp::memfil(&filbuf,0xFFu,0x8u),reinterpret_cast<char unsigned *>(&filbuf)+0x8u); + cmp_eq(::zp::memfil(&filbuf,0x7Fu,0x4u),reinterpret_cast<char unsigned *>(&filbuf)+0x4u); + cmp_eq(::zp::memfil(&filbuf,0x3Fu,0x2u),reinterpret_cast<char unsigned *>(&filbuf)+0x2u); + cmp_eq(::zp::memfil(&filbuf,0x1Fu,0x1u),reinterpret_cast<char unsigned *>(&filbuf)+0x1u); - cmp(filbuf,0xFFFFFFFF7F7F3F1Fu); + cmp_eq(filbuf,0xFFFFFFFF7F7F3F1Fu); ::zp::i04 cpybuf; ::zp::memcpy(&cpybuf,&filbuf,0x8u); - cmp(cpybuf,filbuf); + cmp_eq(cpybuf,filbuf); - cmp(::zp::memsrh(&cpybuf,0x1Fu,0x8u),reinterpret_cast<char unsigned *>(&cpybuf)); + cmp_eq(::zp::memsrh(&cpybuf,0x1Fu,0x8u),reinterpret_cast<char unsigned *>(&cpybuf)); }(); [&] { @@ -286,17 +305,17 @@ int main() { ::zp::siz const wlen = ::zp_wstrlen( wstr); ::zp::siz const len02 = ::zp_utf32len(str02); - cmp(len, 0xCu); - cmp(wlen, 0xCu); - cmp(len02,0xCu); + cmp_eq(len, 0xCu); + cmp_eq(wlen, 0xCu); + cmp_eq(len02,0xCu); auto const buf = new char[ len]; auto const wbuf = new wchar_t[ wlen]; auto const buf02 = new char32_t[len02]; - cmp(::zp_strcpy( buf, str), len); - cmp(::zp_wstrcpy( wbuf, wstr), wlen); - cmp(::zp_utf32cpy(buf02,str02),len02); + cmp_eq(::zp_strcpy( buf, str), len); + cmp_eq(::zp_wstrcpy( wbuf, wstr), wlen); + cmp_eq(::zp_utf32cpy(buf02,str02),len02); delete[] buf; delete[] wbuf; @@ -309,27 +328,27 @@ int main() { char32_t const src[] = U"\U0001F480"; ::zp::siz const buf8len = ::zp_utf8enclen(src); - cmp(buf8len,0x4u); + cmp_eq(buf8len,0x4u); ::zp::c8 * buf8 = new ::zp::c8[buf8len+0x1]; ::zp_utf8enc(buf8,src); - cmp(buf8[0x0],0xF0u); - cmp(buf8[0x1],0x9Fu); - cmp(buf8[0x2],0x92u); - cmp(buf8[0x3],0x80u); - cmp(buf8[0x4],0x00u); + cmp_eq(buf8[0x0],0xF0u); + cmp_eq(buf8[0x1],0x9Fu); + cmp_eq(buf8[0x2],0x92u); + cmp_eq(buf8[0x3],0x80u); + cmp_eq(buf8[0x4],0x00u); ::zp::siz const buf02len = ::zp_utf8declen(buf8); - cmp(buf02len,0x1u); + cmp_eq(buf02len,0x1u); char32_t * buf02 = new char32_t[buf02len+0x1]; ::zp_utf8dec(buf02,buf8); - cmp(buf02[0x0],0x1F480u); - cmp(buf02[0x1],0x0u); + cmp_eq(buf02[0x0],0x1F480u); + cmp_eq(buf02[0x1],0x0u); delete[] buf8; delete[] buf02; @@ -341,27 +360,27 @@ int main() { char32_t const src[] = U"\U0001F480\u00F0"; ::zp::siz const buf01len = ::zp_utf16enclen(src); - cmp(buf01len,0x3u); + cmp_eq(buf01len,0x3u); char16_t * buf01 = new char16_t[buf01len+0x1]; ::zp_utf16enc(buf01,src); - cmp(buf01[0x0],0xD83Du); - cmp(buf01[0x1],0xDC80u); - cmp(buf01[0x2],0x00F0u); - cmp(buf01[0x3],0x0000u); + cmp_eq(buf01[0x0],0xD83Du); + cmp_eq(buf01[0x1],0xDC80u); + cmp_eq(buf01[0x2],0x00F0u); + cmp_eq(buf01[0x3],0x0000u); ::zp::siz const buf02len = ::zp_utf16declen(buf01); - cmp(buf02len,0x2u); + cmp_eq(buf02len,0x2u); char32_t * buf02 = new char32_t[buf02len+0x1]; ::zp_utf16dec(buf02,buf01); - cmp(buf02[0x0],0x1F480u); - cmp(buf02[0x1],0xF0u); - cmp(buf02[0x2],0x0u); + cmp_eq(buf02[0x0],0x1F480u); + cmp_eq(buf02[0x1],0xF0u); + cmp_eq(buf02[0x2],0x0u); delete[] buf01; delete[] buf02; |