feat(data,text,testing): implement VL-002 TOML, VL-008 StrictJson UTF-8, VL-009 native tests, and VL-013 Semver shorthands
This commit is contained in:
1 parent
53d42bda42
commit
adfc8548dc
11 files changed
+2888
-28
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
@@ -41,6 +42,72 @@ namespace Void::Json::Strict
|
|||||||
ParseError error;
|
ParseError error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr std::size_t
|
||||||
|
validate_utf8_at(const std::string_view input,
|
||||||
|
const std::size_t pos) noexcept
|
||||||
|
{
|
||||||
|
if (pos >= input.size()) {
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
const auto b0 = static_cast<unsigned char>(input[pos]);
|
||||||
|
if (b0 <= 0x7FU) {
|
||||||
|
return 1U;
|
||||||
|
}
|
||||||
|
if (b0 >= 0xC2U && b0 <= 0xDFU) {
|
||||||
|
if (pos + 1U >= input.size()) {
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
const auto b1 = static_cast<unsigned char>(input[pos + 1U]);
|
||||||
|
return (b1 >= 0x80U && b1 <= 0xBFU) ? 2U : 0U;
|
||||||
|
}
|
||||||
|
if (b0 >= 0xE0U && b0 <= 0xEFU) {
|
||||||
|
if (pos + 2U >= input.size()) {
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
const auto b1 = static_cast<unsigned char>(input[pos + 1U]);
|
||||||
|
const auto b2 = static_cast<unsigned char>(input[pos + 2U]);
|
||||||
|
const unsigned char lo = (b0 == 0xE0U) ? 0xA0U : 0x80U;
|
||||||
|
const unsigned char hi = (b0 == 0xEDU) ? 0x9FU : 0xBFU;
|
||||||
|
if (b1 < lo || b1 > hi || b2 < 0x80U || b2 > 0xBFU) {
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
return 3U;
|
||||||
|
}
|
||||||
|
if (b0 >= 0xF0U && b0 <= 0xF4U) {
|
||||||
|
if (pos + 3U >= input.size()) {
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
const auto b1 = static_cast<unsigned char>(input[pos + 1U]);
|
||||||
|
const auto b2 = static_cast<unsigned char>(input[pos + 2U]);
|
||||||
|
const auto b3 = static_cast<unsigned char>(input[pos + 3U]);
|
||||||
|
const unsigned char lo = (b0 == 0xF0U) ? 0x90U : 0x80U;
|
||||||
|
const unsigned char hi = (b0 == 0xF4U) ? 0x8FU : 0xBFU;
|
||||||
|
if (b1 < lo || b1 > hi || b2 < 0x80U || b2 > 0xBFU ||
|
||||||
|
b3 < 0x80U || b3 > 0xBFU) {
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
return 4U;
|
||||||
|
}
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] inline std::expected<void, ParseError>
|
||||||
|
validate_utf8_bytes(const std::string_view input)
|
||||||
|
{
|
||||||
|
std::size_t pos = 0U;
|
||||||
|
while (pos < input.size()) {
|
||||||
|
const std::size_t len = validate_utf8_at(input, pos);
|
||||||
|
if (len == 0U) {
|
||||||
|
return std::unexpected{ParseError{
|
||||||
|
.offset = pos,
|
||||||
|
.message = "invalid UTF-8 sequence",
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
pos += len;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
class Parser final
|
class Parser final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -179,6 +246,18 @@ namespace Void::Json::Strict
|
|||||||
fail("control character in string");
|
fail("control character in string");
|
||||||
}
|
}
|
||||||
if (value != '\\') {
|
if (value != '\\') {
|
||||||
|
if (value >= 0x80U) {
|
||||||
|
const std::size_t seq_start = position_ - 1U;
|
||||||
|
const std::size_t len =
|
||||||
|
validate_utf8_at(input_, seq_start);
|
||||||
|
if (len == 0U) {
|
||||||
|
position_ = seq_start;
|
||||||
|
fail("invalid UTF-8 sequence");
|
||||||
|
}
|
||||||
|
output.append(input_.substr(seq_start, len));
|
||||||
|
position_ = seq_start + len;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
output.push_back(static_cast<char>(value));
|
output.push_back(static_cast<char>(value));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -435,4 +514,171 @@ namespace Void::Json::Strict
|
|||||||
.allowDecimals = true});
|
.allowDecimals = true});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] inline bool is_valid_utf8(const std::string_view input) noexcept
|
||||||
|
{
|
||||||
|
std::size_t pos = 0U;
|
||||||
|
while (pos < input.size()) {
|
||||||
|
const std::size_t len = Detail::validate_utf8_at(input, pos);
|
||||||
|
if (len == 0U) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pos += len;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] inline std::expected<void, ParseError>
|
||||||
|
validate_utf8(const std::string_view input)
|
||||||
|
{
|
||||||
|
return Detail::validate_utf8_bytes(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Detail
|
||||||
|
{
|
||||||
|
inline void append_escaped_string(std::string& out,
|
||||||
|
const std::string_view text)
|
||||||
|
{
|
||||||
|
const auto utf8 = validate_utf8_bytes(text);
|
||||||
|
if (!utf8.has_value()) {
|
||||||
|
throw ParseFailure{.error = utf8.error()};
|
||||||
|
}
|
||||||
|
out.push_back('"');
|
||||||
|
std::size_t pos = 0U;
|
||||||
|
while (pos < text.size()) {
|
||||||
|
const auto ch = static_cast<unsigned char>(text[pos]);
|
||||||
|
switch (ch) {
|
||||||
|
case '"':
|
||||||
|
out += "\\\"";
|
||||||
|
++pos;
|
||||||
|
break;
|
||||||
|
case '\\':
|
||||||
|
out += "\\\\";
|
||||||
|
++pos;
|
||||||
|
break;
|
||||||
|
case '\b':
|
||||||
|
out += "\\b";
|
||||||
|
++pos;
|
||||||
|
break;
|
||||||
|
case '\f':
|
||||||
|
out += "\\f";
|
||||||
|
++pos;
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
out += "\\n";
|
||||||
|
++pos;
|
||||||
|
break;
|
||||||
|
case '\r':
|
||||||
|
out += "\\r";
|
||||||
|
++pos;
|
||||||
|
break;
|
||||||
|
case '\t':
|
||||||
|
out += "\\t";
|
||||||
|
++pos;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (ch < 0x20U) {
|
||||||
|
static constexpr char kHex[] = "0123456789abcdef";
|
||||||
|
out += "\\u00";
|
||||||
|
out.push_back(kHex[(ch >> 4U) & 0x0FU]);
|
||||||
|
out.push_back(kHex[ch & 0x0FU]);
|
||||||
|
++pos;
|
||||||
|
} else if (ch >= 0x80U) {
|
||||||
|
const std::size_t len = validate_utf8_at(text, pos);
|
||||||
|
out.append(text.substr(pos, len));
|
||||||
|
pos += len;
|
||||||
|
} else {
|
||||||
|
out.push_back(static_cast<char>(ch));
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.push_back('"');
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void serialize_value(std::string& out, const Value& val,
|
||||||
|
const std::size_t depth,
|
||||||
|
const std::size_t maximumDepth)
|
||||||
|
{
|
||||||
|
if (depth > maximumDepth) {
|
||||||
|
throw ParseFailure{
|
||||||
|
.error =
|
||||||
|
{
|
||||||
|
.offset = out.size(),
|
||||||
|
.message = "nesting limit exceeded during serialize",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
std::visit(
|
||||||
|
[&](const auto& node) {
|
||||||
|
using T = std::decay_t<decltype(node)>;
|
||||||
|
if constexpr (std::same_as<T, std::nullptr_t>) {
|
||||||
|
out += "null";
|
||||||
|
} else if constexpr (std::same_as<T, bool>) {
|
||||||
|
out += (node ? "true" : "false");
|
||||||
|
} else if constexpr (std::same_as<T, std::int64_t>) {
|
||||||
|
std::array<char, 32> buf{};
|
||||||
|
const auto res = std::to_chars(
|
||||||
|
buf.data(), buf.data() + buf.size(), node);
|
||||||
|
out.append(buf.data(), res.ptr);
|
||||||
|
} else if constexpr (std::same_as<T, double>) {
|
||||||
|
if (!std::isfinite(node)) {
|
||||||
|
throw ParseFailure{
|
||||||
|
.error =
|
||||||
|
{
|
||||||
|
.offset = out.size(),
|
||||||
|
.message =
|
||||||
|
"non-finite double is not valid JSON",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
std::array<char, 64> buf{};
|
||||||
|
const auto res = std::to_chars(
|
||||||
|
buf.data(), buf.data() + buf.size(), node,
|
||||||
|
std::chars_format::general);
|
||||||
|
out.append(buf.data(), res.ptr);
|
||||||
|
} else if constexpr (std::same_as<T, std::string>) {
|
||||||
|
append_escaped_string(out, node);
|
||||||
|
} else if constexpr (std::same_as<T, Value::Array>) {
|
||||||
|
out.push_back('[');
|
||||||
|
for (std::size_t i = 0; i < node.size(); ++i) {
|
||||||
|
if (i > 0U) {
|
||||||
|
out.push_back(',');
|
||||||
|
}
|
||||||
|
serialize_value(out, node[i], depth + 1U,
|
||||||
|
maximumDepth);
|
||||||
|
}
|
||||||
|
out.push_back(']');
|
||||||
|
} else if constexpr (std::same_as<T, Value::Object>) {
|
||||||
|
out.push_back('{');
|
||||||
|
bool first = true;
|
||||||
|
for (const auto& [k, v] : node) {
|
||||||
|
if (!first) {
|
||||||
|
out.push_back(',');
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
append_escaped_string(out, k);
|
||||||
|
out.push_back(':');
|
||||||
|
serialize_value(out, v, depth + 1U, maximumDepth);
|
||||||
|
}
|
||||||
|
out.push_back('}');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
val.value);
|
||||||
|
}
|
||||||
|
} // namespace Detail
|
||||||
|
|
||||||
|
[[nodiscard]] inline std::expected<std::string, ParseError>
|
||||||
|
serialize(const Value& value,
|
||||||
|
const std::size_t maximumDepth = default_maximum_depth)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
std::string out;
|
||||||
|
Detail::serialize_value(out, value, 0U, maximumDepth);
|
||||||
|
return out;
|
||||||
|
} catch (const Detail::ParseFailure& failure) {
|
||||||
|
return std::unexpected{failure.error};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Void::Json::Strict
|
} // namespace Void::Json::Strict
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -75,6 +75,7 @@ namespace Void::Result
|
|||||||
inline constexpr std::uint32_t kPluginErrorDomain = 23;
|
inline constexpr std::uint32_t kPluginErrorDomain = 23;
|
||||||
inline constexpr std::uint32_t kConfigurationErrorDomain = 24;
|
inline constexpr std::uint32_t kConfigurationErrorDomain = 24;
|
||||||
inline constexpr std::uint32_t kFsmErrorDomain = 25;
|
inline constexpr std::uint32_t kFsmErrorDomain = 25;
|
||||||
|
inline constexpr std::uint32_t kNetErrorDomain = 26;
|
||||||
|
|
||||||
struct ErrorCode {
|
struct ErrorCode {
|
||||||
std::uint32_t domain{kGenericErrorDomain};
|
std::uint32_t domain{kGenericErrorDomain};
|
||||||
|
|||||||
@@ -1,10 +1,190 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace Void::Testing {
|
#include <Void/Testing/Config.hpp>
|
||||||
|
#include <Void/Testing/Detail/Registry.hpp>
|
||||||
|
|
||||||
// Aliases to void so users can omit return statements safely
|
#include <initializer_list>
|
||||||
// and avoid compiler warnings/errors. Perfectly matches std::function<void()>.
|
#include <string>
|
||||||
using Test = void;
|
#include <string_view>
|
||||||
using DisabledTest = void;
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Void::Testing
|
||||||
|
{
|
||||||
|
|
||||||
|
// Aliases to void so users can omit return statements safely
|
||||||
|
// and avoid compiler warnings/errors. Perfectly matches
|
||||||
|
// std::function<void()>.
|
||||||
|
using Test = void;
|
||||||
|
using DisabledTest = void;
|
||||||
|
|
||||||
|
namespace Detail
|
||||||
|
{
|
||||||
|
[[nodiscard]] inline std::string
|
||||||
|
normalize_suite_label(std::string_view raw)
|
||||||
|
{
|
||||||
|
if (raw.size() >= 2 && raw.front() == '"' && raw.back() == '"') {
|
||||||
|
raw = raw.substr(1, raw.size() - 2);
|
||||||
|
}
|
||||||
|
return std::string{raw};
|
||||||
|
}
|
||||||
|
|
||||||
|
class NativeRegistrar final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
NativeRegistrar(void (*fn)(), std::string_view suite,
|
||||||
|
const char* file, int line,
|
||||||
|
std::string_view name,
|
||||||
|
std::initializer_list<const char*> tags = {},
|
||||||
|
bool disabled = false,
|
||||||
|
std::string_view skip_reason = {})
|
||||||
|
{
|
||||||
|
std::vector<std::string> tag_vec;
|
||||||
|
tag_vec.reserve(tags.size());
|
||||||
|
for (const char* t : tags) {
|
||||||
|
if (t != nullptr) {
|
||||||
|
tag_vec.emplace_back(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Registry::instance().add(TestCase{
|
||||||
|
.run = fn,
|
||||||
|
.name = std::string{name},
|
||||||
|
.suite = normalize_suite_label(suite),
|
||||||
|
.file = file != nullptr ? file : "",
|
||||||
|
.line = line,
|
||||||
|
.disabled = disabled,
|
||||||
|
.skip_reason = std::string{skip_reason},
|
||||||
|
.tags = std::move(tag_vec),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename FixtureT> class NativeFixtureRegistrar final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
NativeFixtureRegistrar(void (*fn)(FixtureT&),
|
||||||
|
std::string_view suite,
|
||||||
|
const char* file, int line,
|
||||||
|
std::string_view name,
|
||||||
|
std::initializer_list<const char*> tags = {},
|
||||||
|
bool disabled = false,
|
||||||
|
std::string_view skip_reason = {})
|
||||||
|
{
|
||||||
|
std::vector<std::string> tag_vec;
|
||||||
|
tag_vec.reserve(tags.size());
|
||||||
|
for (const char* t : tags) {
|
||||||
|
if (t != nullptr) {
|
||||||
|
tag_vec.emplace_back(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Registry::instance().add(TestCase{
|
||||||
|
.run =
|
||||||
|
[fn]() {
|
||||||
|
FixtureT fixture{};
|
||||||
|
if constexpr (requires { fixture.setup(); }) {
|
||||||
|
fixture.setup();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
fn(fixture);
|
||||||
|
} catch (...) {
|
||||||
|
if constexpr (requires {
|
||||||
|
fixture.teardown();
|
||||||
|
}) {
|
||||||
|
fixture.teardown();
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
if constexpr (requires { fixture.teardown(); }) {
|
||||||
|
fixture.teardown();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.name = std::string{name},
|
||||||
|
.suite = normalize_suite_label(suite),
|
||||||
|
.file = file != nullptr ? file : "",
|
||||||
|
.line = line,
|
||||||
|
.disabled = disabled,
|
||||||
|
.skip_reason = std::string{skip_reason},
|
||||||
|
.tags = std::move(tag_vec),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace Detail
|
||||||
|
|
||||||
} // namespace Void::Testing
|
} // namespace Void::Testing
|
||||||
|
|
||||||
|
#define VOID_TESTING_DETAIL_CAT_IMPL(a, b) a##b
|
||||||
|
#define VOID_TESTING_DETAIL_CAT(a, b) VOID_TESTING_DETAIL_CAT_IMPL(a, b)
|
||||||
|
|
||||||
|
#ifdef __COUNTER__
|
||||||
|
#define VOID_TESTING_DETAIL_NEXT_ID __COUNTER__
|
||||||
|
#else
|
||||||
|
#define VOID_TESTING_DETAIL_NEXT_ID __LINE__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define VOID_TESTING_DETAIL_DEFINE_TEST(suite_expr, test_name, disabled_flag, \
|
||||||
|
skip_msg, uid, ...) \
|
||||||
|
static void VOID_TESTING_DETAIL_CAT(_void_native_test_fn_, uid)(); \
|
||||||
|
namespace \
|
||||||
|
{ \
|
||||||
|
[[maybe_unused]] const ::Void::Testing::Detail::NativeRegistrar \
|
||||||
|
VOID_TESTING_DETAIL_CAT(_void_native_test_reg_, uid){ \
|
||||||
|
&VOID_TESTING_DETAIL_CAT(_void_native_test_fn_, uid), \
|
||||||
|
(suite_expr), \
|
||||||
|
__FILE__, \
|
||||||
|
__LINE__, \
|
||||||
|
#test_name, \
|
||||||
|
{__VA_ARGS__}, \
|
||||||
|
(disabled_flag), \
|
||||||
|
(skip_msg)}; \
|
||||||
|
} \
|
||||||
|
static void VOID_TESTING_DETAIL_CAT(_void_native_test_fn_, uid)()
|
||||||
|
|
||||||
|
#define VOID_TESTING_DETAIL_DEFINE_FIXTURE_TEST(fixture_type, test_name, \
|
||||||
|
disabled_flag, skip_msg, uid) \
|
||||||
|
static void VOID_TESTING_DETAIL_CAT(_void_native_fx_fn_, uid)( \
|
||||||
|
fixture_type&); \
|
||||||
|
namespace \
|
||||||
|
{ \
|
||||||
|
[[maybe_unused]] const ::Void::Testing::Detail::NativeFixtureRegistrar< \
|
||||||
|
fixture_type> \
|
||||||
|
VOID_TESTING_DETAIL_CAT(_void_native_fx_reg_, uid){ \
|
||||||
|
&VOID_TESTING_DETAIL_CAT(_void_native_fx_fn_, uid), \
|
||||||
|
#fixture_type, \
|
||||||
|
__FILE__, \
|
||||||
|
__LINE__, \
|
||||||
|
#test_name, \
|
||||||
|
{}, \
|
||||||
|
(disabled_flag), \
|
||||||
|
(skip_msg)}; \
|
||||||
|
} \
|
||||||
|
static void VOID_TESTING_DETAIL_CAT(_void_native_fx_fn_, uid)( \
|
||||||
|
[[maybe_unused]] fixture_type& fixture)
|
||||||
|
|
||||||
|
/// Declare a self-registering test case with zero CMake scanner dependency.
|
||||||
|
/// Symbols are internal-linkage and counter-disambiguated so files sharing the
|
||||||
|
/// same basename in different subdirectories link cleanly together.
|
||||||
|
#define VOID_TEST(suite, name) \
|
||||||
|
VOID_TESTING_DETAIL_DEFINE_TEST(#suite, name, false, "", \
|
||||||
|
VOID_TESTING_DETAIL_NEXT_ID)
|
||||||
|
|
||||||
|
/// Same as VOID_TEST, taking tags (string literals) after `name`.
|
||||||
|
#define VOID_TEST_TAGGED(suite, name, ...) \
|
||||||
|
VOID_TESTING_DETAIL_DEFINE_TEST(#suite, name, false, "", \
|
||||||
|
VOID_TESTING_DETAIL_NEXT_ID, __VA_ARGS__)
|
||||||
|
|
||||||
|
/// Declare a skipped/disabled self-registering test case.
|
||||||
|
#define VOID_TEST_DISABLED(suite, name, reason) \
|
||||||
|
VOID_TESTING_DETAIL_DEFINE_TEST(#suite, name, true, (reason), \
|
||||||
|
VOID_TESTING_DETAIL_NEXT_ID)
|
||||||
|
|
||||||
|
/// Declare a self-registering fixture test. The fixture instance is bound as
|
||||||
|
/// `fixture` inside the test body, with optional setup()/teardown() hooks.
|
||||||
|
#define VOID_TEST_FIXTURE(fixture_type, name) \
|
||||||
|
VOID_TESTING_DETAIL_DEFINE_FIXTURE_TEST(fixture_type, name, false, "", \
|
||||||
|
VOID_TESTING_DETAIL_NEXT_ID)
|
||||||
|
|
||||||
|
#define VOID_TEST_FIXTURE_DISABLED(fixture_type, name, reason) \
|
||||||
|
VOID_TESTING_DETAIL_DEFINE_FIXTURE_TEST(fixture_type, name, true, (reason), \
|
||||||
|
VOID_TESTING_DETAIL_NEXT_ID)
|
||||||
@@ -438,6 +438,54 @@ namespace Void::Semver
|
|||||||
using Clause = std::vector<Comparator>;
|
using Clause = std::vector<Comparator>;
|
||||||
std::vector<Clause> m_alternatives;
|
std::vector<Clause> m_alternatives;
|
||||||
|
|
||||||
|
struct PartialVersion {
|
||||||
|
Version version{};
|
||||||
|
int components{0};
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] static std::optional<PartialVersion>
|
||||||
|
parse_partial(std::string_view token)
|
||||||
|
{
|
||||||
|
if (token.empty()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
if (token.find('-') != std::string_view::npos ||
|
||||||
|
token.find('+') != std::string_view::npos) {
|
||||||
|
const auto full = parse_strict(token);
|
||||||
|
if (!full) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return PartialVersion{*full, 3};
|
||||||
|
}
|
||||||
|
const auto first_dot = token.find('.');
|
||||||
|
if (first_dot == std::string_view::npos) {
|
||||||
|
unsigned major = 0;
|
||||||
|
if (!Detail::parse_component(token, major)) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return PartialVersion{
|
||||||
|
Version{.major = major, .minor = 0, .patch = 0}, 1};
|
||||||
|
}
|
||||||
|
const auto second_dot = token.find('.', first_dot + 1);
|
||||||
|
if (second_dot == std::string_view::npos) {
|
||||||
|
unsigned major = 0;
|
||||||
|
unsigned minor = 0;
|
||||||
|
if (!Detail::parse_component(token.substr(0, first_dot),
|
||||||
|
major) ||
|
||||||
|
!Detail::parse_component(token.substr(first_dot + 1),
|
||||||
|
minor)) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return PartialVersion{
|
||||||
|
Version{.major = major, .minor = minor, .patch = 0}, 2};
|
||||||
|
}
|
||||||
|
const auto full = parse_strict(token);
|
||||||
|
if (!full) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return PartialVersion{*full, 3};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] static bool append_token(Clause& clause,
|
[[nodiscard]] static bool append_token(Clause& clause,
|
||||||
std::string_view token)
|
std::string_view token)
|
||||||
{
|
{
|
||||||
@@ -447,53 +495,76 @@ namespace Void::Semver
|
|||||||
if (token.starts_with('^') || token.starts_with('~')) {
|
if (token.starts_with('^') || token.starts_with('~')) {
|
||||||
const char kind = token.front();
|
const char kind = token.front();
|
||||||
token.remove_prefix(1);
|
token.remove_prefix(1);
|
||||||
const auto lower = parse_strict(token);
|
const auto partial = parse_partial(token);
|
||||||
if (!lower) {
|
if (!partial) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const Version& lower = partial->version;
|
||||||
Version upper;
|
Version upper;
|
||||||
if (kind == '~') {
|
if (kind == '~') {
|
||||||
if (lower->minor ==
|
if (partial->components == 1) {
|
||||||
|
if (lower.major ==
|
||||||
|
std::numeric_limits<unsigned>::max()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
upper = Version{.major = lower.major + 1,
|
||||||
|
.minor = 0,
|
||||||
|
.patch = 0,
|
||||||
|
.pre_release = {},
|
||||||
|
.build = {}};
|
||||||
|
} else {
|
||||||
|
if (lower.minor ==
|
||||||
|
std::numeric_limits<unsigned>::max()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
upper = Version{.major = lower.major,
|
||||||
|
.minor = lower.minor + 1,
|
||||||
|
.patch = 0,
|
||||||
|
.pre_release = {},
|
||||||
|
.build = {}};
|
||||||
|
}
|
||||||
|
} else if (partial->components == 1) {
|
||||||
|
if (lower.major ==
|
||||||
std::numeric_limits<unsigned>::max()) {
|
std::numeric_limits<unsigned>::max()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
upper = Version{.major = lower->major,
|
upper = Version{.major = lower.major + 1,
|
||||||
.minor = lower->minor + 1,
|
|
||||||
.patch = 0,
|
|
||||||
.pre_release = {},
|
|
||||||
.build = {}};
|
|
||||||
} else if (lower->major > 0) {
|
|
||||||
if (lower->major ==
|
|
||||||
std::numeric_limits<unsigned>::max()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
upper = Version{.major = lower->major + 1,
|
|
||||||
.minor = 0,
|
.minor = 0,
|
||||||
.patch = 0,
|
.patch = 0,
|
||||||
.pre_release = {},
|
.pre_release = {},
|
||||||
.build = {}};
|
.build = {}};
|
||||||
} else if (lower->minor > 0) {
|
} else if (lower.major > 0) {
|
||||||
if (lower->minor ==
|
if (lower.major ==
|
||||||
|
std::numeric_limits<unsigned>::max()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
upper = Version{.major = lower.major + 1,
|
||||||
|
.minor = 0,
|
||||||
|
.patch = 0,
|
||||||
|
.pre_release = {},
|
||||||
|
.build = {}};
|
||||||
|
} else if (lower.minor > 0) {
|
||||||
|
if (lower.minor ==
|
||||||
std::numeric_limits<unsigned>::max()) {
|
std::numeric_limits<unsigned>::max()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
upper = Version{.major = 0,
|
upper = Version{.major = 0,
|
||||||
.minor = lower->minor + 1,
|
.minor = lower.minor + 1,
|
||||||
.patch = 0,
|
.patch = 0,
|
||||||
.pre_release = {},
|
.pre_release = {},
|
||||||
.build = {}};
|
.build = {}};
|
||||||
} else {
|
} else {
|
||||||
if (lower->patch ==
|
if (lower.patch ==
|
||||||
std::numeric_limits<unsigned>::max()) {
|
std::numeric_limits<unsigned>::max()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
upper = Version{.major = 0,
|
upper = Version{.major = 0,
|
||||||
.minor = 0,
|
.minor = 0,
|
||||||
.patch = lower->patch + 1,
|
.patch = lower.patch + 1,
|
||||||
.pre_release = {},
|
.pre_release = {},
|
||||||
.build = {}};
|
.build = {}};
|
||||||
}
|
}
|
||||||
clause.push_back({Operation::GreaterEqual, *lower});
|
clause.push_back({Operation::GreaterEqual, lower});
|
||||||
clause.push_back({Operation::Less, std::move(upper)});
|
clause.push_back({Operation::Less, std::move(upper)});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -518,11 +589,11 @@ namespace Void::Semver
|
|||||||
} else if (token.starts_with('=')) {
|
} else if (token.starts_with('=')) {
|
||||||
token.remove_prefix(1);
|
token.remove_prefix(1);
|
||||||
}
|
}
|
||||||
const auto version = parse_strict(token);
|
const auto partial = parse_partial(token);
|
||||||
if (!version) {
|
if (!partial) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
clause.push_back({operation, *version});
|
clause.push_back({operation, partial->version});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#include <Void/Testing/Assert.hpp>
|
||||||
|
#include <Void/Testing/Test.hpp>
|
||||||
|
|
||||||
|
VOID_TEST(NativeGxx, from_dir_a_first)
|
||||||
|
{
|
||||||
|
Void::Testing::expect_eq(10 + 5, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID_TEST(NativeGxx, duplicate_name_test)
|
||||||
|
{
|
||||||
|
Void::Testing::expect(true);
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#include <Void/Testing/Assert.hpp>
|
||||||
|
#include <Void/Testing/Test.hpp>
|
||||||
|
|
||||||
|
VOID_TEST(NativeGxx, from_dir_b_first)
|
||||||
|
{
|
||||||
|
Void::Testing::expect_eq(6 * 7, 42);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID_TEST(NativeGxx, duplicate_name_test)
|
||||||
|
{
|
||||||
|
Void::Testing::expect_eq(1, 1);
|
||||||
|
}
|
||||||
@@ -152,3 +152,69 @@ Void::Testing::Test strict_json_decodes_valid_unicode_pairs()
|
|||||||
Void::Testing::expect(
|
Void::Testing::expect(
|
||||||
!Void::Json::Strict::parse(R"("\uD83D")").has_value());
|
!Void::Json::Strict::parse(R"("\uD83D")").has_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test strict_json_validates_utf8_in_parse_and_serialize()
|
||||||
|
{
|
||||||
|
// Valid 1, 2, 3, and 4-byte scalars including boundaries U+D7FF, U+E000, U+10FFFF
|
||||||
|
const std::string valid_json =
|
||||||
|
std::string{R"({"ascii":"hello","latin":")"} + "\xC3\xA9" +
|
||||||
|
R"(","euro":")" + "\xE2\x82\xAC" + R"(","emoji":")" +
|
||||||
|
"\xF0\x9F\x98\x80" + R"(","hi_bmp":")" + "\xED\x9F\xBF" +
|
||||||
|
R"(","priv":")" + "\xEE\x80\x80" + R"(","max_cp":")" +
|
||||||
|
"\xF4\x8F\xBF\xBF" + R"("})";
|
||||||
|
|
||||||
|
const auto parsed = Void::Json::Strict::parse(valid_json);
|
||||||
|
Void::Testing::require(parsed.has_value());
|
||||||
|
const auto serialized = Void::Json::Strict::serialize(*parsed);
|
||||||
|
Void::Testing::require(serialized.has_value());
|
||||||
|
const auto reparsed = Void::Json::Strict::parse(*serialized);
|
||||||
|
Void::Testing::require(reparsed.has_value());
|
||||||
|
|
||||||
|
// Invalid UTF-8 sequences in string values and object keys
|
||||||
|
const std::array<std::string, 10> invalid_payloads{
|
||||||
|
std::string{"\"\xFF\""}, // invalid lead 0xFF
|
||||||
|
std::string{"\"\x80\""}, // stray continuation byte
|
||||||
|
std::string{"\"\xBF\""}, // stray continuation byte
|
||||||
|
std::string{"\"\xC0\xAF\""}, // overlong 2-byte '/'
|
||||||
|
std::string{"\"\xC1\x81\""}, // overlong 2-byte 'A'
|
||||||
|
std::string{"\"\xE0\x9F\x80\""}, // overlong 3-byte
|
||||||
|
std::string{"\"\xED\xA0\x80\""}, // UTF-8 encoded U+D800
|
||||||
|
std::string{"\"\xED\xBF\xBF\""}, // UTF-8 encoded U+DFFF
|
||||||
|
std::string{"\"\xF4\x90\x80\x80\""}, // > U+10FFFF (U+110000)
|
||||||
|
std::string{"{\"\xFF\":\"val\"}"}, // invalid UTF-8 in object key
|
||||||
|
};
|
||||||
|
for (const auto& payload : invalid_payloads) {
|
||||||
|
const auto res = Void::Json::Strict::parse(payload);
|
||||||
|
Void::Testing::expect(!res.has_value());
|
||||||
|
Void::Testing::expect(!Void::Json::Strict::is_valid_utf8(payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Truncated multi-byte sequences inside strings
|
||||||
|
Void::Testing::expect(
|
||||||
|
!Void::Json::Strict::parse(std::string{"\"\xC3\""}).has_value());
|
||||||
|
Void::Testing::expect(
|
||||||
|
!Void::Json::Strict::parse(std::string{"\"\xF0\x9F\x98\""})
|
||||||
|
.has_value());
|
||||||
|
|
||||||
|
// Serialization must also reject corrupt UTF-8 in Values or keys
|
||||||
|
const Void::Json::Strict::Value bad_val{std::string{"ok\xED\xA0\x80"}};
|
||||||
|
Void::Testing::expect(
|
||||||
|
!Void::Json::Strict::serialize(bad_val).has_value());
|
||||||
|
|
||||||
|
Void::Json::Strict::Value::Object bad_key_obj;
|
||||||
|
bad_key_obj.emplace(std::string{"bad\xFFkey"},
|
||||||
|
Void::Json::Strict::Value{1});
|
||||||
|
Void::Testing::expect(
|
||||||
|
!Void::Json::Strict::serialize(
|
||||||
|
Void::Json::Strict::Value{std::move(bad_key_obj)})
|
||||||
|
.has_value());
|
||||||
|
|
||||||
|
// Control char escaping & round-trip in serialize()
|
||||||
|
const Void::Json::Strict::Value ctrl{std::string{"a\nb\tc\x01\"\\"}};
|
||||||
|
const auto escaped = Void::Json::Strict::serialize(ctrl);
|
||||||
|
Void::Testing::require(escaped.has_value());
|
||||||
|
const auto ctrl_back = Void::Json::Strict::parse(*escaped);
|
||||||
|
Void::Testing::require(ctrl_back.has_value());
|
||||||
|
Void::Testing::expect_eq(std::get<std::string>(ctrl_back->value),
|
||||||
|
std::string{"a\nb\tc\x01\"\\"});
|
||||||
|
}
|
||||||
@@ -0,0 +1,235 @@
|
|||||||
|
#include <Void/Data/Toml.hpp>
|
||||||
|
#include <Void/Testing/Assert.hpp>
|
||||||
|
#include <Void/Testing/Test.hpp>
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <limits>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
Void::Testing::Test toml_parses_scalars_multilines_and_numbers()
|
||||||
|
{
|
||||||
|
constexpr std::string_view kDoc = R"toml(
|
||||||
|
# Comment line
|
||||||
|
title = "Void Build"
|
||||||
|
literal_win = 'C:\Users\Void'
|
||||||
|
multi_basic = """
|
||||||
|
Hello \
|
||||||
|
world ""escaped"" \u0041 \U0001F600!"""
|
||||||
|
multi_quotes = """here are two ""quotes"" and two at end "" """
|
||||||
|
five_quotes = """say """""
|
||||||
|
multi_lit = '''
|
||||||
|
line1\nraw
|
||||||
|
line2 'ok' ''ok''
|
||||||
|
'''
|
||||||
|
|
||||||
|
flag_t = true
|
||||||
|
flag_f = false
|
||||||
|
|
||||||
|
dec_pos = +42
|
||||||
|
dec_neg = -1_000_000
|
||||||
|
hex_num = 0xDEAD_BEEF
|
||||||
|
oct_num = 0o755
|
||||||
|
bin_num = 0b1101_0110
|
||||||
|
min_i64 = -9223372036854775808
|
||||||
|
max_i64 = 9223372036854775807
|
||||||
|
|
||||||
|
flt = -1.25e+2
|
||||||
|
flt_zero = 0.0
|
||||||
|
inf_pos = +inf
|
||||||
|
inf_neg = -inf
|
||||||
|
not_a_num = nan
|
||||||
|
)toml";
|
||||||
|
|
||||||
|
const auto parsed = Void::Data::Toml::parse(kDoc);
|
||||||
|
Void::Testing::require(parsed.has_value());
|
||||||
|
const auto& root = parsed->root;
|
||||||
|
|
||||||
|
Void::Testing::require(root.find("title") != nullptr);
|
||||||
|
Void::Testing::expect_eq(
|
||||||
|
*root.find("title")->as_string(), std::string{"Void Build"});
|
||||||
|
Void::Testing::expect(root.find("title")->origin.line >= 3U);
|
||||||
|
Void::Testing::expect_eq(
|
||||||
|
*root.find("literal_win")->as_string(), std::string{R"(C:\Users\Void)"});
|
||||||
|
Void::Testing::expect_eq(
|
||||||
|
*root.find("multi_basic")->as_string(),
|
||||||
|
std::string{"Hello world \"\"escaped\"\" A \xF0\x9F\x98\x80!"});
|
||||||
|
Void::Testing::expect_eq(
|
||||||
|
*root.find("five_quotes")->as_string(), std::string{"say \"\""});
|
||||||
|
Void::Testing::expect_eq(
|
||||||
|
*root.find("multi_lit")->as_string(),
|
||||||
|
std::string{"line1\\nraw\nline2 'ok' ''ok''\n"});
|
||||||
|
|
||||||
|
Void::Testing::expect_eq(*root.find("flag_t")->as_bool(), true);
|
||||||
|
Void::Testing::expect_eq(*root.find("flag_f")->as_bool(), false);
|
||||||
|
|
||||||
|
Void::Testing::expect_eq(*root.find("dec_pos")->as_integer(),
|
||||||
|
std::int64_t{42});
|
||||||
|
Void::Testing::expect_eq(*root.find("dec_neg")->as_integer(),
|
||||||
|
std::int64_t{-1000000});
|
||||||
|
Void::Testing::expect_eq(*root.find("hex_num")->as_integer(),
|
||||||
|
std::int64_t{0xDEADBEEFLL});
|
||||||
|
Void::Testing::expect_eq(*root.find("oct_num")->as_integer(),
|
||||||
|
std::int64_t{0755});
|
||||||
|
Void::Testing::expect_eq(*root.find("bin_num")->as_integer(),
|
||||||
|
std::int64_t{0b11010110});
|
||||||
|
Void::Testing::expect_eq(*root.find("min_i64")->as_integer(),
|
||||||
|
std::numeric_limits<std::int64_t>::min());
|
||||||
|
Void::Testing::expect_eq(*root.find("max_i64")->as_integer(),
|
||||||
|
std::numeric_limits<std::int64_t>::max());
|
||||||
|
|
||||||
|
Void::Testing::expect_eq(*root.find("flt")->as_float(), -125.0);
|
||||||
|
Void::Testing::expect_eq(*root.find("flt_zero")->as_float(), 0.0);
|
||||||
|
Void::Testing::expect(std::isinf(*root.find("inf_pos")->as_float()) &&
|
||||||
|
*root.find("inf_pos")->as_float() > 0.0);
|
||||||
|
Void::Testing::expect(std::isinf(*root.find("inf_neg")->as_float()) &&
|
||||||
|
*root.find("inf_neg")->as_float() < 0.0);
|
||||||
|
Void::Testing::expect(std::isnan(*root.find("not_a_num")->as_float()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test toml_parses_datetimes_tables_inline_and_arrays_of_tables()
|
||||||
|
{
|
||||||
|
constexpr std::string_view kDoc = R"toml(
|
||||||
|
odt_utc = 1979-05-27T07:32:00Z
|
||||||
|
odt_space = 1979-05-27 07:32:00.123456-07:00
|
||||||
|
ldt = 2000-02-29T12:00:00
|
||||||
|
ld = 2026-11-26
|
||||||
|
lt = 08:15:30.5
|
||||||
|
|
||||||
|
name.first = "Ada"
|
||||||
|
name."last.part" = "Lovelace"
|
||||||
|
inline_pt = { x = 1, y = 2, nested.z = "ok" }
|
||||||
|
arr = [
|
||||||
|
1,
|
||||||
|
"two", # comment inside array
|
||||||
|
{ k = true },
|
||||||
|
]
|
||||||
|
|
||||||
|
[server]
|
||||||
|
host = "127.0.0.1"
|
||||||
|
ports = [8080, 8443]
|
||||||
|
|
||||||
|
[server.tls]
|
||||||
|
enabled = true
|
||||||
|
|
||||||
|
[[products]]
|
||||||
|
name = "Hammer"
|
||||||
|
sku = 738594937
|
||||||
|
|
||||||
|
[[products]] # empty entry in middle is allowed
|
||||||
|
[[products]]
|
||||||
|
name = "Nail"
|
||||||
|
sku = 284758393
|
||||||
|
color = ["gray", "steel"]
|
||||||
|
|
||||||
|
[products.meta]
|
||||||
|
origin = "local"
|
||||||
|
)toml";
|
||||||
|
|
||||||
|
const auto parsed = Void::Data::Toml::parse(kDoc);
|
||||||
|
Void::Testing::require(parsed.has_value());
|
||||||
|
const auto& root = parsed->root;
|
||||||
|
|
||||||
|
const auto* odt = root.find("odt_utc")->as_datetime();
|
||||||
|
Void::Testing::require(odt != nullptr);
|
||||||
|
Void::Testing::expect_eq(odt->to_string(),
|
||||||
|
std::string{"1979-05-27T07:32:00Z"});
|
||||||
|
|
||||||
|
const auto* odt2 = root.find("odt_space")->as_datetime();
|
||||||
|
Void::Testing::require(odt2 != nullptr);
|
||||||
|
Void::Testing::expect_eq(
|
||||||
|
odt2->to_string(), std::string{"1979-05-27T07:32:00.123456-07:00"});
|
||||||
|
|
||||||
|
const auto* ldt = root.find("ldt")->as_datetime();
|
||||||
|
Void::Testing::require(ldt != nullptr);
|
||||||
|
Void::Testing::expect_eq(ldt->date.year, 2000);
|
||||||
|
Void::Testing::expect_eq(ldt->date.month, 2);
|
||||||
|
Void::Testing::expect_eq(ldt->date.day, 29);
|
||||||
|
|
||||||
|
const auto* name_tbl = root.find("name")->as_table();
|
||||||
|
Void::Testing::require(name_tbl != nullptr);
|
||||||
|
Void::Testing::expect_eq(*name_tbl->find("first")->as_string(),
|
||||||
|
std::string{"Ada"});
|
||||||
|
Void::Testing::expect_eq(*name_tbl->find("last.part")->as_string(),
|
||||||
|
std::string{"Lovelace"});
|
||||||
|
|
||||||
|
const auto* inline_pt = root.find("inline_pt")->as_table();
|
||||||
|
Void::Testing::require(inline_pt != nullptr);
|
||||||
|
Void::Testing::expect(inline_pt->is_inline);
|
||||||
|
Void::Testing::expect_eq(*inline_pt->find("x")->as_integer(),
|
||||||
|
std::int64_t{1});
|
||||||
|
Void::Testing::expect_eq(
|
||||||
|
*inline_pt->find("nested")->as_table()->find("z")->as_string(),
|
||||||
|
std::string{"ok"});
|
||||||
|
|
||||||
|
const auto* aot = root.find("products")->as_array_of_tables();
|
||||||
|
Void::Testing::require(aot != nullptr);
|
||||||
|
Void::Testing::expect_eq(aot->tables.size(), std::size_t{3});
|
||||||
|
Void::Testing::expect_eq(*aot->tables[0].find("name")->as_string(),
|
||||||
|
std::string{"Hammer"});
|
||||||
|
Void::Testing::expect(aot->tables[1].empty());
|
||||||
|
Void::Testing::expect_eq(*aot->tables[2].find("name")->as_string(),
|
||||||
|
std::string{"Nail"});
|
||||||
|
Void::Testing::expect_eq(
|
||||||
|
*aot->tables[2].find("meta")->as_table()->find("origin")->as_string(),
|
||||||
|
std::string{"local"});
|
||||||
|
|
||||||
|
// Deterministic canonical serialize & round-trip idempotence
|
||||||
|
const std::string out1 = Void::Data::Toml::serialize(*parsed);
|
||||||
|
const auto reparsed = Void::Data::Toml::parse(out1);
|
||||||
|
Void::Testing::require(reparsed.has_value());
|
||||||
|
const std::string out2 = Void::Data::Toml::serialize(*reparsed);
|
||||||
|
Void::Testing::expect_eq(out1, out2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test toml_reports_exact_origin_and_rejects_errors()
|
||||||
|
{
|
||||||
|
// Line 1: ok, Line 2: ok, Line 3: duplicate key starts at col 1
|
||||||
|
constexpr std::string_view kDupKey = "a = 1\nb = 2\na = 3\n";
|
||||||
|
const auto e1 = Void::Data::Toml::parse(kDupKey);
|
||||||
|
Void::Testing::require(!e1.has_value());
|
||||||
|
Void::Testing::expect_eq(e1.error().origin.line, std::size_t{3});
|
||||||
|
Void::Testing::expect_eq(e1.error().origin.column, std::size_t{1});
|
||||||
|
|
||||||
|
// Duplicate [table]
|
||||||
|
constexpr std::string_view kDupTable = "[pkg]\nname = \"x\"\n\n[pkg]\n";
|
||||||
|
const auto e2 = Void::Data::Toml::parse(kDupTable);
|
||||||
|
Void::Testing::require(!e2.has_value());
|
||||||
|
Void::Testing::expect_eq(e2.error().origin.line, std::size_t{4});
|
||||||
|
|
||||||
|
// Defining explicit [table] after dotted key
|
||||||
|
const auto e3 = Void::Data::Toml::parse("a.b = 1\n[a]\n");
|
||||||
|
Void::Testing::expect(!e3.has_value());
|
||||||
|
|
||||||
|
// Extending inline table
|
||||||
|
const auto e4 = Void::Data::Toml::parse("t = { a = 1 }\nt.b = 2\n");
|
||||||
|
Void::Testing::expect(!e4.has_value());
|
||||||
|
|
||||||
|
// Multiline inline table forbidden in TOML 1.0
|
||||||
|
const auto e5 = Void::Data::Toml::parse("t = {\n a = 1\n}\n");
|
||||||
|
Void::Testing::expect(!e5.has_value());
|
||||||
|
|
||||||
|
// Trailing comma in inline table forbidden in TOML 1.0
|
||||||
|
const auto e6 = Void::Data::Toml::parse("t = { a = 1, }\n");
|
||||||
|
Void::Testing::expect(!e6.has_value());
|
||||||
|
|
||||||
|
// Invalid calendar date (non-leap year 1900-02-29)
|
||||||
|
const auto e7 = Void::Data::Toml::parse("d = 1900-02-29\n");
|
||||||
|
Void::Testing::expect(!e7.has_value());
|
||||||
|
|
||||||
|
// Invalid 6-quote basic string close
|
||||||
|
const auto e8 = Void::Data::Toml::parse("s = \"\"\"hello\"\"\"\"\"\"\n");
|
||||||
|
Void::Testing::expect(!e8.has_value());
|
||||||
|
|
||||||
|
// Invalid UTF-8 byte
|
||||||
|
const auto e9 = Void::Data::Toml::parse(std::string{"s = \"\xFF\"\n"});
|
||||||
|
Void::Testing::expect(!e9.has_value());
|
||||||
|
|
||||||
|
// Subtable before parent table IS valid per TOML 1.0
|
||||||
|
const auto super_after =
|
||||||
|
Void::Data::Toml::parse("[a.b]\nx = 1\n[a]\ny = 2\n");
|
||||||
|
Void::Testing::require(super_after.has_value());
|
||||||
|
Void::Testing::expect_eq(
|
||||||
|
*super_after->root.find("a")->as_table()->find("y")->as_integer(),
|
||||||
|
std::int64_t{2});
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#include <Void/Testing/Assert.hpp>
|
||||||
|
#include <Void/Testing/Detail/Registry.hpp>
|
||||||
|
#include <Void/Testing/Test.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace void_testing_native_test
|
||||||
|
{
|
||||||
|
struct CounterFixture {
|
||||||
|
int value{0};
|
||||||
|
void setup() { value = 41; }
|
||||||
|
void teardown() { value = 0; }
|
||||||
|
};
|
||||||
|
} // namespace void_testing_native_test
|
||||||
|
|
||||||
|
VOID_TEST(NativeApi, self_registers_free_test)
|
||||||
|
{
|
||||||
|
Void::Testing::expect_eq(2 + 3, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID_TEST_TAGGED(NativeApi, tagged_native_test, "fast", "native")
|
||||||
|
{
|
||||||
|
const auto& tests = Void::Testing::Detail::Registry::instance().tests();
|
||||||
|
bool found = false;
|
||||||
|
for (const auto& t : tests) {
|
||||||
|
if (t.suite == "NativeApi" && t.name == "tagged_native_test") {
|
||||||
|
found = (t.tags.size() == 2U && t.tags[0] == "fast" &&
|
||||||
|
t.tags[1] == "native");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Void::Testing::expect(found);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID_TEST_DISABLED(NativeApi, disabled_native_test, "intentional skip check")
|
||||||
|
{
|
||||||
|
Void::Testing::expect(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID_TEST_FIXTURE(void_testing_native_test::CounterFixture,
|
||||||
|
fixture_runs_setup_hook)
|
||||||
|
{
|
||||||
|
Void::Testing::expect_eq(fixture.value, 41);
|
||||||
|
fixture.value += 1;
|
||||||
|
Void::Testing::expect_eq(fixture.value, 42);
|
||||||
|
}
|
||||||
@@ -148,12 +148,97 @@ Void::Testing::Test semver_version_ranges_reject_overflowing_upper_bounds()
|
|||||||
{
|
{
|
||||||
Void::Testing::expect(
|
Void::Testing::expect(
|
||||||
!Void::Semver::parse_range("^4294967295.0.0").has_value());
|
!Void::Semver::parse_range("^4294967295.0.0").has_value());
|
||||||
|
Void::Testing::expect(
|
||||||
|
!Void::Semver::parse_range("^4294967295").has_value());
|
||||||
|
Void::Testing::expect(
|
||||||
|
!Void::Semver::parse_range("~4294967295").has_value());
|
||||||
Void::Testing::expect(
|
Void::Testing::expect(
|
||||||
!Void::Semver::parse_range("4294967295.x").has_value());
|
!Void::Semver::parse_range("4294967295.x").has_value());
|
||||||
Void::Testing::expect(
|
Void::Testing::expect(
|
||||||
!Void::Semver::parse_range("1.4294967295.x").has_value());
|
!Void::Semver::parse_range("1.4294967295.x").has_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test semver_shorthand_comparators()
|
||||||
|
{
|
||||||
|
const auto caret_major = Void::Semver::parse_range("^1");
|
||||||
|
Void::Testing::require(caret_major.has_value());
|
||||||
|
Void::Testing::expect(
|
||||||
|
caret_major->contains(*Void::Semver::parse("1.0.0")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
caret_major->contains(*Void::Semver::parse("1.9.9")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
!caret_major->contains(*Void::Semver::parse("2.0.0")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
!caret_major->contains(*Void::Semver::parse("0.9.0")));
|
||||||
|
|
||||||
|
const auto caret_zero = Void::Semver::parse_range("^0");
|
||||||
|
Void::Testing::require(caret_zero.has_value());
|
||||||
|
Void::Testing::expect(
|
||||||
|
caret_zero->contains(*Void::Semver::parse("0.0.0")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
caret_zero->contains(*Void::Semver::parse("0.9.5")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
!caret_zero->contains(*Void::Semver::parse("1.0.0")));
|
||||||
|
|
||||||
|
const auto caret_minor = Void::Semver::parse_range("^1.0");
|
||||||
|
Void::Testing::require(caret_minor.has_value());
|
||||||
|
Void::Testing::expect(
|
||||||
|
caret_minor->contains(*Void::Semver::parse("1.0.0")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
caret_minor->contains(*Void::Semver::parse("1.5.2")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
!caret_minor->contains(*Void::Semver::parse("2.0.0")));
|
||||||
|
|
||||||
|
const auto caret_11 = Void::Semver::parse_range("^11.0");
|
||||||
|
Void::Testing::require(caret_11.has_value());
|
||||||
|
Void::Testing::expect(
|
||||||
|
caret_11->contains(*Void::Semver::parse("11.4.2")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
!caret_11->contains(*Void::Semver::parse("12.0.0")));
|
||||||
|
|
||||||
|
const auto caret_zero_minor = Void::Semver::parse_range("^0.2");
|
||||||
|
Void::Testing::require(caret_zero_minor.has_value());
|
||||||
|
Void::Testing::expect(
|
||||||
|
caret_zero_minor->contains(*Void::Semver::parse("0.2.7")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
!caret_zero_minor->contains(*Void::Semver::parse("0.3.0")));
|
||||||
|
|
||||||
|
const auto tilde_minor = Void::Semver::parse_range("~1.2");
|
||||||
|
Void::Testing::require(tilde_minor.has_value());
|
||||||
|
Void::Testing::expect(
|
||||||
|
tilde_minor->contains(*Void::Semver::parse("1.2.0")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
tilde_minor->contains(*Void::Semver::parse("1.2.9")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
!tilde_minor->contains(*Void::Semver::parse("1.3.0")));
|
||||||
|
|
||||||
|
const auto tilde_major = Void::Semver::parse_range("~2");
|
||||||
|
Void::Testing::require(tilde_major.has_value());
|
||||||
|
Void::Testing::expect(
|
||||||
|
tilde_major->contains(*Void::Semver::parse("2.5.0")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
!tilde_major->contains(*Void::Semver::parse("3.0.0")));
|
||||||
|
|
||||||
|
const auto mixed = Void::Semver::parse_range(">=1.2 <2");
|
||||||
|
Void::Testing::require(mixed.has_value());
|
||||||
|
Void::Testing::expect(mixed->contains(*Void::Semver::parse("1.2.0")));
|
||||||
|
Void::Testing::expect(mixed->contains(*Void::Semver::parse("1.9.4")));
|
||||||
|
Void::Testing::expect(!mixed->contains(*Void::Semver::parse("1.1.9")));
|
||||||
|
Void::Testing::expect(!mixed->contains(*Void::Semver::parse("2.0.0")));
|
||||||
|
|
||||||
|
const auto less_only = Void::Semver::parse_range("<1.2.0");
|
||||||
|
Void::Testing::require(less_only.has_value());
|
||||||
|
Void::Testing::expect(less_only->contains(*Void::Semver::parse("1.1.9")));
|
||||||
|
Void::Testing::expect(
|
||||||
|
!less_only->contains(*Void::Semver::parse("1.2.0")));
|
||||||
|
|
||||||
|
Void::Testing::expect(!Void::Semver::parse_range("^").has_value());
|
||||||
|
Void::Testing::expect(!Void::Semver::parse_range("^1.").has_value());
|
||||||
|
Void::Testing::expect(!Void::Semver::parse_range("^01").has_value());
|
||||||
|
Void::Testing::expect(
|
||||||
|
!Void::Semver::parse_range(">=1.2-alpha").has_value());
|
||||||
|
}
|
||||||
|
|
||||||
// ── bump ─────────────────────────────────────────────────────────────────────
|
// ── bump ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
Void::Testing::Test semver_bump_major()
|
Void::Testing::Test semver_bump_major()
|
||||||
|
|||||||
Reference in new issue
Block a user