2021-01-23 21:39:18 +01:00
|
|
|
#pragma once
|
2023-07-29 00:56:08 +02:00
|
|
|
|
2023-07-29 13:56:00 +02:00
|
|
|
#include <string>
|
2021-01-23 21:39:18 +01:00
|
|
|
|
|
|
|
#ifdef CMAKE_GITHUB_CI
|
|
|
|
#include <doctest/doctest.h>
|
|
|
|
#else
|
|
|
|
#include <doctest.h>
|
|
|
|
#endif
|
|
|
|
|
2021-02-20 15:53:18 +01:00
|
|
|
struct buffer {
|
2023-07-29 13:56:00 +02:00
|
|
|
std::string data_;
|
|
|
|
|
|
|
|
char *operator()(const std::string &data) {
|
|
|
|
data_ = data;
|
|
|
|
return data_.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
char *append(const std::string &data) {
|
|
|
|
data_ += data;
|
|
|
|
return data_.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
char *append_overwrite_last(const std::string &data, size_t size) {
|
|
|
|
data_.resize(data_.size() - size);
|
|
|
|
return append(data);
|
|
|
|
}
|
2021-01-23 21:39:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
[[maybe_unused]] inline buffer buff;
|
2022-03-30 19:54:50 +02:00
|
|
|
|
|
|
|
#define CHECK_FLOATING_CONVERSION(input, type) \
|
2023-07-29 13:56:00 +02:00
|
|
|
{ \
|
|
|
|
auto eps = std::numeric_limits<type>::min(); \
|
|
|
|
std::string s = #input; \
|
|
|
|
auto t = ss::to_num<type>(s.c_str(), s.c_str() + s.size()); \
|
|
|
|
REQUIRE(t.has_value()); \
|
|
|
|
CHECK_LT(std::abs(t.value() - type(input)), eps); \
|
|
|
|
} \
|
|
|
|
{ \
|
|
|
|
/* check negative too */ \
|
|
|
|
auto eps = std::numeric_limits<type>::min(); \
|
|
|
|
auto s = std::string("-") + #input; \
|
|
|
|
auto t = ss::to_num<type>(s.c_str(), s.c_str() + s.size()); \
|
|
|
|
REQUIRE(t.has_value()); \
|
|
|
|
CHECK_LT(std::abs(t.value() - type(-input)), eps); \
|
|
|
|
}
|
2022-03-30 19:54:50 +02:00
|
|
|
|
|
|
|
#define CHECK_INVALID_CONVERSION(input, type) \
|
2023-07-29 13:56:00 +02:00
|
|
|
{ \
|
|
|
|
std::string s = input; \
|
|
|
|
auto t = ss::to_num<type>(s.c_str(), s.c_str() + s.size()); \
|
|
|
|
CHECK_FALSE(t.has_value()); \
|
|
|
|
}
|
2022-03-30 19:54:50 +02:00
|
|
|
|
|
|
|
#define REQUIRE_VARIANT(var, el, type) \
|
2023-07-29 13:56:00 +02:00
|
|
|
{ \
|
|
|
|
auto ptr = std::get_if<type>(&var); \
|
|
|
|
REQUIRE(ptr); \
|
|
|
|
REQUIRE_EQ(el, *ptr); \
|
|
|
|
}
|
2022-03-30 19:54:50 +02:00
|
|
|
|
|
|
|
#define CHECK_NOT_VARIANT(var, type) CHECK(!std::holds_alternative<type>(var));
|