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:
faumaray committed 2026-11-26 20:27:42 +03:00
1 parent 53d42bda42
commit adfc8548dc
11 files changed
+2888 -28

No files matched your search

@@ -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);
}
+66
View File
@@ -152,3 +152,69 @@ Void::Testing::Test strict_json_decodes_valid_unicode_pairs()
Void::Testing::expect(
!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\"\\"});
}
+235
View File
@@ -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);
}
+85
View File
@@ -148,12 +148,97 @@ Void::Testing::Test semver_version_ranges_reject_overflowing_upper_bounds()
{
Void::Testing::expect(
!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::Semver::parse_range("4294967295.x").has_value());
Void::Testing::expect(
!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 ─────────────────────────────────────────────────────────────────────
Void::Testing::Test semver_bump_major()