Add unit test and fix for non-char types.

This commit is contained in:
King_DuckZ 2018-10-13 00:44:38 +01:00
parent 63cbf324ef
commit 4eb4209409
3 changed files with 65 additions and 5 deletions

View file

@ -51,13 +51,13 @@ namespace dhandy {
constexpr V to() const { return V(data(), size() - (not empty() and not back() ? 1 : 0)); }
#if !defined(INT_CONV_WITHOUT_HELPERS)
constexpr std::string_view to_string_view() const { return to<std::string_view>(); }
bool operator== (const std::string_view& other) const { return to_string_view() == other; }
bool operator!= (const std::string_view& other) const { return not operator==(other); }
constexpr std::basic_string_view<T> to_string_view() const { return to<std::basic_string_view<T>>(); }
bool operator== (const std::basic_string_view<T>& other) const { return to_string_view() == other; }
bool operator!= (const std::basic_string_view<T>& other) const { return not operator==(other); }
bool operator== (const std::string& other) const { return to_string_view() == other; }
bool operator!= (const std::string& other) const { return not operator==(other); }
bool operator== (const char* other) const { return to_string_view() == std::string_view(other); }
bool operator!= (const char* other) const { return not operator==(other); }
bool operator== (const T* other) const { return to_string_view() == std::basic_string_view<T>(other); }
bool operator!= (const T* other) const { return not operator==(other); }
#endif
private:

View file

@ -5,6 +5,7 @@ add_executable(${PROJECT_NAME}
lexical_cast_test.cpp
endianness_test.cpp
int_conv_test.cpp
reversed_sized_array_test.cpp
)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)

View file

@ -0,0 +1,59 @@
/* Copyright 2016-2018 Michele Santullo
* This file is part of "duckhandy".
*
* "duckhandy" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "duckhandy" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "duckhandy". If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch2/catch.hpp"
#include "duckhandy/implem/reversed_sized_array_bt.hpp"
TEST_CASE ("Check conversion functions in ReversedSizedArray", "[ReversedSizedArray][containers]") {
using dhandy::ReversedSizedArray;
{
ReversedSizedArray<wchar_t, 8> ary;
CHECK(ary.empty());
CHECK(ary.size() == 0);
ary.push_front('a');
CHECK(not ary.empty());
REQUIRE(ary.size() == 1);
CHECK(ary.back() == 'a');
CHECK(ary.to_string_view().size() == 1);
CHECK(ary.to_string_view() == L"a");
ary.push_front('n');
ary.push_front('z');
ary.push_front('*');
REQUIRE(ary.size() == 4);
CHECK(ary.to_string_view() == L"*zna");
}
{
ReversedSizedArray<char, 4> ary;
CHECK(ary.empty());
CHECK(ary.size() == 0);
ary.push_front('\0');
CHECK(not ary.empty());
REQUIRE(ary.size() == 1);
CHECK(ary.back() == '\0');
CHECK(ary.to_string_view().size() == 0);
CHECK(ary.to_string_view() == "");
ary.push_front('8');
ary.push_front('+');
ary.push_front('&');
REQUIRE(ary.size() == 4);
CHECK(ary.to_string_view() == "&+8");
}
}