Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions include/iris/test/catch2.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#ifndef IRIS_ZZ_TEST_CATCH2_HPP
#define IRIS_ZZ_TEST_CATCH2_HPP

// SPDX-License-Identifier: MIT

#include <iris/config.hpp> // IWYU pragma: keep

#include <iris/unicode/string.hpp>
#include <iris/string.hpp>

#include <catch2/catch_test_macros.hpp> // IWYU pragma: export
#include <catch2/catch_tostring.hpp>

#include <concepts>
#include <type_traits>
#include <string>
#include <string_view>
#include <ranges>
#include <format>

#include <cstddef> // IWYU pragma: keep

template<std::formattable<char> T>
requires (!std::ranges::range<T>)
struct Catch::StringMaker<T>
{
static std::string convert(T const& value)
{
return std::format("{}", value);
}
};

template<iris::CharLike CharT, std::size_t N>
requires (!std::same_as<CharT, char> && !std::same_as<CharT, wchar_t>)
struct Catch::StringMaker<CharT[N]>
{
static std::string convert(CharT const (&str)[N])
{
return iris::to_string_ref(str);
}
};

template<iris::CharLike CharT>
requires (!std::same_as<CharT, char> && !std::same_as<CharT, wchar_t>)
struct Catch::StringMaker<CharT const*>
{
static std::string convert(CharT const* str)
{
return iris::to_string_ref(str);
}
};

template<class CharT, class TraitsT, class AllocT>
requires (!std::same_as<CharT, char> && !std::same_as<CharT, wchar_t>)
struct Catch::StringMaker<std::basic_string<CharT, TraitsT, AllocT>, std::enable_if_t<Catch::is_range<std::basic_string<CharT, TraitsT, AllocT>>::value && !::Catch::Detail::IsStreamInsertable_v<std::basic_string<CharT, TraitsT, AllocT>>>>
{
static std::string convert(std::basic_string<CharT, TraitsT, AllocT> const& str)
{
return iris::to_string_ref(str);
}
};

template<class CharT, class TraitsT>
requires (!std::same_as<CharT, char> && !std::same_as<CharT, wchar_t>)
struct Catch::StringMaker<std::basic_string_view<CharT, TraitsT>, std::enable_if_t<Catch::is_range<std::basic_string_view<CharT, TraitsT>>::value && !::Catch::Detail::IsStreamInsertable_v<std::basic_string_view<CharT, TraitsT>>>>
{
static std::string convert(std::basic_string_view<CharT, TraitsT> const& str)
{
return iris::to_string_ref(str);
}
};

#endif
40 changes: 20 additions & 20 deletions include/iris/unicode/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1416,22 +1416,22 @@ template<class CharT>
requires std::same_as<CharT, char8_t>
constexpr std::u8string_view transcode_ref(std::u8string const&&) = delete;

//template<class CharT>
// requires (!std::same_as<CharT, char16_t>)
//[[nodiscard]] constexpr std::basic_string<CharT> transcode_ref(std::u16string_view str)
//{
// return unicode::transcode<CharT>(str);
//}
template<class CharT>
requires (!std::same_as<CharT, char16_t>)
[[nodiscard]] constexpr std::basic_string<CharT> transcode_ref(std::u16string_view str)
{
return unicode::transcode<CharT>(str);
}

//template<class CharT>
// requires std::same_as<CharT, char16_t>
//[[nodiscard]] constexpr std::u16string_view transcode_ref(std::u16string_view str)
//{
// return str;
//}
//template<class CharT>
// requires std::same_as<CharT, char16_t>
//constexpr std::u16string_view transcode_ref(std::u16string const&&) = delete;
template<class CharT>
requires std::same_as<CharT, char16_t>
[[nodiscard]] constexpr std::u16string_view transcode_ref(std::u16string_view str)
{
return str;
}
template<class CharT>
requires std::same_as<CharT, char16_t>
constexpr std::u16string_view transcode_ref(std::u16string const&&) = delete;

template<class CharT>
requires (!std::same_as<CharT, char32_t>)
Expand Down Expand Up @@ -1486,11 +1486,11 @@ template<int = 0>

// -------------------------------------------------------

//template<int = 0>
//[[nodiscard]] constexpr std::string to_string_ref(std::u16string_view str)
//{
// return unicode::transcode<char>(str);
//}
template<int = 0>
[[nodiscard]] constexpr std::string to_string_ref(std::u16string_view str)
{
return unicode::transcode<char>(str);
}

// -------------------------------------------------------

Expand Down
16 changes: 1 addition & 15 deletions test/iris_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@

#include <iris/config.hpp> // IWYU pragma: keep

#include <catch2/catch_test_macros.hpp> // IWYU pragma: export
#include <catch2/catch_tostring.hpp>

#include <ranges>
#include <format>

template<std::formattable<char> T>
requires (!std::ranges::range<T>)
struct Catch::StringMaker<T>
{
static std::string convert(T const& value)
{
return std::format("{}", value);
}
};
#include <iris/test/catch2.hpp>

#endif
Loading