1 parent
8583a479dd
commit
3851aeb703
42 files changed
+6948
-759
No files matched your search
@@ -1,240 +1,290 @@
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
#include <Void/Text/Base64.hpp>
|
||||
#include <Void/Text/Hex.hpp>
|
||||
#include <Void/Text/Html.hpp>
|
||||
#include <Void/Text/Url.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
// ── Base64 encode ─────────────────────────────────────────────────────────────
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
|
||||
// ── Base64 encode
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test base64_encode_empty()
|
||||
{
|
||||
Void::Testing::expect(Void::Encoding::Base64::encode("").empty());
|
||||
Void::Testing::expect(Void::Encoding::Base64::encode("").empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_encode_man()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Base64::encode("Man"),
|
||||
std::string{"TWFu"});
|
||||
Void::Testing::expect_eq(Void::Encoding::Base64::encode("Man"),
|
||||
std::string{"TWFu"});
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_encode_ma()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Base64::encode("Ma"),
|
||||
std::string{"TWE="});
|
||||
Void::Testing::expect_eq(Void::Encoding::Base64::encode("Ma"),
|
||||
std::string{"TWE="});
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_encode_m()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Base64::encode("M"),
|
||||
std::string{"TQ=="});
|
||||
Void::Testing::expect_eq(Void::Encoding::Base64::encode("M"),
|
||||
std::string{"TQ=="});
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_encode_hello_world()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Base64::encode("Hello, World!"),
|
||||
std::string{"SGVsbG8sIFdvcmxkIQ=="});
|
||||
Void::Testing::expect_eq(Void::Encoding::Base64::encode("Hello, World!"),
|
||||
std::string{"SGVsbG8sIFdvcmxkIQ=="});
|
||||
}
|
||||
|
||||
// ── Base64 decode ─────────────────────────────────────────────────────────────
|
||||
// ── Base64 decode
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test base64_decode_empty()
|
||||
{
|
||||
const auto r = Void::Encoding::Base64::decode("");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect(r->empty());
|
||||
const auto r = Void::Encoding::Base64::decode("");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect(r->empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_decode_man()
|
||||
{
|
||||
const auto r = Void::Encoding::Base64::decode("TWFu");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"Man"});
|
||||
const auto r = Void::Encoding::Base64::decode("TWFu");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"Man"});
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_decode_with_padding()
|
||||
{
|
||||
const auto r = Void::Encoding::Base64::decode("SGVsbG8sIFdvcmxkIQ==");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"Hello, World!"});
|
||||
const auto r = Void::Encoding::Base64::decode("SGVsbG8sIFdvcmxkIQ==");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"Hello, World!"});
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_decode_invalid_returns_nullopt()
|
||||
{
|
||||
const auto r = Void::Encoding::Base64::decode("!!");
|
||||
Void::Testing::expect(!r.has_value());
|
||||
const auto r = Void::Encoding::Base64::decode("!!");
|
||||
Void::Testing::expect(!r.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_decode_rejects_malformed_padding()
|
||||
{
|
||||
Void::Testing::expect(!Void::Encoding::Base64::decode("T=WE").has_value());
|
||||
Void::Testing::expect(!Void::Encoding::Base64::decode("TWFu=").has_value());
|
||||
Void::Testing::expect(!Void::Encoding::Base64::decode("TQ===").has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_decode_rejects_nonzero_trailing_bits()
|
||||
{
|
||||
Void::Testing::expect(!Void::Encoding::Base64::decode("TR==").has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_round_trip()
|
||||
{
|
||||
const std::string original = "The quick brown fox jumps over the lazy dog";
|
||||
const auto encoded = Void::Encoding::Base64::encode(original);
|
||||
const auto decoded = Void::Encoding::Base64::decode(encoded);
|
||||
Void::Testing::expect(decoded.has_value());
|
||||
Void::Testing::expect_eq(*decoded, original);
|
||||
const std::string original = "The quick brown fox jumps over the lazy dog";
|
||||
const auto encoded = Void::Encoding::Base64::encode(original);
|
||||
const auto decoded = Void::Encoding::Base64::decode(encoded);
|
||||
Void::Testing::expect(decoded.has_value());
|
||||
Void::Testing::expect_eq(*decoded, original);
|
||||
}
|
||||
|
||||
// ── Base64 URL ────────────────────────────────────────────────────────────────
|
||||
Void::Testing::Test base64_byte_buffer_round_trip()
|
||||
{
|
||||
const std::array<std::uint8_t, 5> original{0x00, 0x7F, 0x80, 0xFE, 0xFF};
|
||||
const auto encoded =
|
||||
Void::Encoding::Base64::encode(std::span<const std::uint8_t>{original});
|
||||
const auto decoded = Void::Encoding::Base64::decode_bytes(encoded);
|
||||
Void::Testing::expect(decoded.has_value());
|
||||
Void::Testing::expect_eq(decoded->size(), original.size());
|
||||
for (std::size_t i = 0; i < original.size(); ++i) {
|
||||
Void::Testing::expect_eq(std::to_integer<std::uint8_t>((*decoded)[i]),
|
||||
original[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Base64 URL
|
||||
// ────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test base64url_no_padding()
|
||||
{
|
||||
const auto s = Void::Encoding::Base64::encode_url("Man");
|
||||
Void::Testing::expect_eq(s, std::string{"TWFu"});
|
||||
Void::Testing::expect(s.find('=') == std::string::npos);
|
||||
const auto s = Void::Encoding::Base64::encode_url("Man");
|
||||
Void::Testing::expect_eq(s, std::string{"TWFu"});
|
||||
Void::Testing::expect(s.find('=') == std::string::npos);
|
||||
}
|
||||
|
||||
Void::Testing::Test base64url_no_plus_or_slash()
|
||||
{
|
||||
// encode something that would produce + or / in standard base64
|
||||
const std::string tricky = "\xfb\xff\xfe";
|
||||
const auto s = Void::Encoding::Base64::encode_url(tricky);
|
||||
Void::Testing::expect(s.find('+') == std::string::npos);
|
||||
Void::Testing::expect(s.find('/') == std::string::npos);
|
||||
// encode something that would produce + or / in standard base64
|
||||
const std::string tricky = "\xfb\xff\xfe";
|
||||
const auto s = Void::Encoding::Base64::encode_url(tricky);
|
||||
Void::Testing::expect(s.find('+') == std::string::npos);
|
||||
Void::Testing::expect(s.find('/') == std::string::npos);
|
||||
}
|
||||
|
||||
// ── Hex encode ───────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test hex_encode_empty()
|
||||
{
|
||||
Void::Testing::expect(Void::Encoding::Hex::encode("").empty());
|
||||
Void::Testing::expect(Void::Encoding::Hex::encode("").empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_encode_hello()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Hex::encode("Hi"),
|
||||
std::string{"4869"});
|
||||
Void::Testing::expect_eq(Void::Encoding::Hex::encode("Hi"),
|
||||
std::string{"4869"});
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_encode_binary()
|
||||
{
|
||||
const std::string bin{'\x00', '\xff', '\xab'};
|
||||
Void::Testing::expect_eq(Void::Encoding::Hex::encode(bin),
|
||||
std::string{"00ffab"});
|
||||
const std::string bin{'\x00', '\xff', '\xab'};
|
||||
Void::Testing::expect_eq(Void::Encoding::Hex::encode(bin),
|
||||
std::string{"00ffab"});
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_encode_upper()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Hex::encode_upper("Hi"),
|
||||
std::string{"4869"});
|
||||
Void::Testing::expect_eq(Void::Encoding::Hex::encode_upper("Hi"),
|
||||
std::string{"4869"});
|
||||
}
|
||||
|
||||
// ── Hex decode ───────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test hex_decode_empty()
|
||||
{
|
||||
const auto r = Void::Encoding::Hex::decode("");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect(r->empty());
|
||||
const auto r = Void::Encoding::Hex::decode("");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect(r->empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_decode_hello()
|
||||
{
|
||||
const auto r = Void::Encoding::Hex::decode("4869");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"Hi"});
|
||||
const auto r = Void::Encoding::Hex::decode("4869");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"Hi"});
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_decode_uppercase()
|
||||
{
|
||||
const auto r = Void::Encoding::Hex::decode("4869");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"Hi"});
|
||||
const auto r = Void::Encoding::Hex::decode("4869");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"Hi"});
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_decode_odd_length_fails()
|
||||
{
|
||||
Void::Testing::expect(!Void::Encoding::Hex::decode("abc").has_value());
|
||||
Void::Testing::expect(!Void::Encoding::Hex::decode("abc").has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_decode_invalid_char_fails()
|
||||
{
|
||||
Void::Testing::expect(!Void::Encoding::Hex::decode("zz").has_value());
|
||||
Void::Testing::expect(!Void::Encoding::Hex::decode("zz").has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_round_trip()
|
||||
{
|
||||
const std::string original = "binary\x00\x01\x02\xff";
|
||||
const auto encoded = Void::Encoding::Hex::encode(original);
|
||||
const auto decoded = Void::Encoding::Hex::decode(encoded);
|
||||
Void::Testing::expect(decoded.has_value());
|
||||
Void::Testing::expect_eq(*decoded, original);
|
||||
const std::string original = "binary\x00\x01\x02\xff";
|
||||
const auto encoded = Void::Encoding::Hex::encode(original);
|
||||
const auto decoded = Void::Encoding::Hex::decode(encoded);
|
||||
Void::Testing::expect(decoded.has_value());
|
||||
Void::Testing::expect_eq(*decoded, original);
|
||||
}
|
||||
|
||||
// ── URL / percent encoding ─────────────────────────────────────────────────────
|
||||
Void::Testing::Test hex_byte_buffer_round_trip()
|
||||
{
|
||||
const std::array<std::uint8_t, 5> original{0x00, 0x7F, 0x80, 0xFE, 0xFF};
|
||||
const auto encoded =
|
||||
Void::Encoding::Hex::encode(std::span<const std::uint8_t>{original});
|
||||
const auto decoded = Void::Encoding::Hex::decode_bytes(encoded);
|
||||
Void::Testing::expect(decoded.has_value());
|
||||
Void::Testing::expect_eq(decoded->size(), original.size());
|
||||
for (std::size_t i = 0; i < original.size(); ++i) {
|
||||
Void::Testing::expect_eq(std::to_integer<std::uint8_t>((*decoded)[i]),
|
||||
original[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// ── URL / percent encoding
|
||||
// ─────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test url_encode_unreserved_passthrough()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Url::encode("AZaz09-._~"),
|
||||
std::string{"AZaz09-._~"});
|
||||
Void::Testing::expect_eq(Void::Encoding::Url::encode("AZaz09-._~"),
|
||||
std::string{"AZaz09-._~"});
|
||||
}
|
||||
|
||||
Void::Testing::Test url_encode_reserved()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Url::encode("a b/c?d=e&f"),
|
||||
std::string{"a%20b%2Fc%3Fd%3De%26f"});
|
||||
Void::Testing::expect_eq(Void::Encoding::Url::encode("a b/c?d=e&f"),
|
||||
std::string{"a%20b%2Fc%3Fd%3De%26f"});
|
||||
}
|
||||
|
||||
Void::Testing::Test url_query_encode_space_as_plus()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Url::query_encode("a b c"),
|
||||
std::string{"a+b+c"});
|
||||
Void::Testing::expect_eq(Void::Encoding::Url::query_encode("a b c"),
|
||||
std::string{"a+b+c"});
|
||||
}
|
||||
|
||||
Void::Testing::Test url_decode_basic()
|
||||
{
|
||||
const auto r = Void::Encoding::Url::decode("a%20b%2Fc");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"a b/c"});
|
||||
const auto r = Void::Encoding::Url::decode("a%20b%2Fc");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"a b/c"});
|
||||
}
|
||||
|
||||
Void::Testing::Test url_decode_plus_as_space()
|
||||
{
|
||||
const auto r = Void::Encoding::Url::decode("a+b", /*plus_as_space=*/true);
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"a b"});
|
||||
const auto r = Void::Encoding::Url::decode("a+b", /*plus_as_space=*/true);
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"a b"});
|
||||
}
|
||||
|
||||
Void::Testing::Test url_decode_malformed_fails()
|
||||
{
|
||||
Void::Testing::expect(!Void::Encoding::Url::decode("a%2").has_value());
|
||||
Void::Testing::expect(!Void::Encoding::Url::decode("a%zz").has_value());
|
||||
Void::Testing::expect(!Void::Encoding::Url::decode("a%2").has_value());
|
||||
Void::Testing::expect(!Void::Encoding::Url::decode("a%zz").has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test url_round_trip_utf8()
|
||||
{
|
||||
const std::string original = "café/naïve?x=1 2";
|
||||
const auto enc = Void::Encoding::Url::encode(original);
|
||||
const auto dec = Void::Encoding::Url::decode(enc);
|
||||
Void::Testing::expect(dec.has_value());
|
||||
Void::Testing::expect_eq(*dec, original);
|
||||
const std::string original = "café/naïve?x=1 2";
|
||||
const auto enc = Void::Encoding::Url::encode(original);
|
||||
const auto dec = Void::Encoding::Url::decode(enc);
|
||||
Void::Testing::expect(dec.has_value());
|
||||
Void::Testing::expect_eq(*dec, original);
|
||||
}
|
||||
|
||||
// ── HTML entity decoding ───────────────────────────────────────────────────────
|
||||
// ── HTML entity decoding
|
||||
// ───────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test html_named_entities()
|
||||
{
|
||||
Void::Testing::expect_eq(
|
||||
Void::Text::html_unescape("a & b < c > d "e""),
|
||||
std::string{"a & b < c > d \"e\""});
|
||||
Void::Testing::expect_eq(
|
||||
Void::Text::html_unescape("a & b < c > d "e""),
|
||||
std::string{"a & b < c > d \"e\""});
|
||||
}
|
||||
|
||||
Void::Testing::Test html_numeric_decimal()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Text::html_unescape("ABC"),
|
||||
std::string{"ABC"});
|
||||
Void::Testing::expect_eq(Void::Text::html_unescape("ABC"),
|
||||
std::string{"ABC"});
|
||||
}
|
||||
|
||||
Void::Testing::Test html_numeric_hex_utf8()
|
||||
{
|
||||
// U+1F600 grinning face -> 4-byte UTF-8
|
||||
const auto r = Void::Text::html_unescape("😀");
|
||||
Void::Testing::expect_eq(r.size(), std::size_t{4});
|
||||
// U+1F600 grinning face -> 4-byte UTF-8
|
||||
const auto r = Void::Text::html_unescape("😀");
|
||||
Void::Testing::expect_eq(r.size(), std::size_t{4});
|
||||
}
|
||||
|
||||
Void::Testing::Test html_unknown_left_verbatim()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Text::html_unescape("a &bogus; b"),
|
||||
std::string{"a &bogus; b"});
|
||||
Void::Testing::expect_eq(Void::Text::html_unescape("plain & text"),
|
||||
std::string{"plain & text"});
|
||||
Void::Testing::expect_eq(Void::Text::html_unescape("a &bogus; b"),
|
||||
std::string{"a &bogus; b"});
|
||||
Void::Testing::expect_eq(Void::Text::html_unescape("plain & text"),
|
||||
std::string{"plain & text"});
|
||||
}
|
||||
@@ -4,158 +4,203 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
// ── parse ─────────────────────────────────────────────────────────────────────
|
||||
// ── parse
|
||||
// ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test semver_parse_simple()
|
||||
{
|
||||
const auto v = Void::Semver::parse("1.2.3");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->major, 1u);
|
||||
Void::Testing::expect_eq(v->minor, 2u);
|
||||
Void::Testing::expect_eq(v->patch, 3u);
|
||||
const auto v = Void::Semver::parse("1.2.3");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->major, 1u);
|
||||
Void::Testing::expect_eq(v->minor, 2u);
|
||||
Void::Testing::expect_eq(v->patch, 3u);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_parse_with_v_prefix()
|
||||
{
|
||||
const auto v = Void::Semver::parse("v2.0.0");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->major, 2u);
|
||||
const auto v = Void::Semver::parse("v2.0.0");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->major, 2u);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_parse_pre_release()
|
||||
{
|
||||
const auto v = Void::Semver::parse("1.0.0-alpha.1");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->pre_release, std::string{"alpha.1"});
|
||||
const auto v = Void::Semver::parse("1.0.0-alpha.1");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->pre_release, std::string{"alpha.1"});
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_parse_build_metadata()
|
||||
{
|
||||
const auto v = Void::Semver::parse("1.0.0+build.123");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->build, std::string{"build.123"});
|
||||
const auto v = Void::Semver::parse("1.0.0+build.123");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->build, std::string{"build.123"});
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_parse_full()
|
||||
{
|
||||
const auto v = Void::Semver::parse("2.3.4-beta.2+20240101");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->major, 2u);
|
||||
Void::Testing::expect_eq(v->pre_release, std::string{"beta.2"});
|
||||
Void::Testing::expect_eq(v->build, std::string{"20240101"});
|
||||
const auto v = Void::Semver::parse("2.3.4-beta.2+20240101");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->major, 2u);
|
||||
Void::Testing::expect_eq(v->pre_release, std::string{"beta.2"});
|
||||
Void::Testing::expect_eq(v->build, std::string{"20240101"});
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_parse_invalid()
|
||||
{
|
||||
Void::Testing::expect(!Void::Semver::parse("not-a-version").has_value());
|
||||
Void::Testing::expect(!Void::Semver::parse("1.2").has_value());
|
||||
Void::Testing::expect(!Void::Semver::parse("not-a-version").has_value());
|
||||
Void::Testing::expect(!Void::Semver::parse("1.2").has_value());
|
||||
Void::Testing::expect(!Void::Semver::parse_strict("v1.2.3").has_value());
|
||||
Void::Testing::expect(!Void::Semver::parse("01.2.3").has_value());
|
||||
Void::Testing::expect(!Void::Semver::parse("1.2.3-alpha.01").has_value());
|
||||
Void::Testing::expect(!Void::Semver::parse("1.2.3-alpha..1").has_value());
|
||||
}
|
||||
|
||||
// ── to_string ─────────────────────────────────────────────────────────────────
|
||||
// ── to_string
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test semver_to_string_simple()
|
||||
{
|
||||
Void::Semver::Version v{1, 2, 3};
|
||||
Void::Testing::expect_eq(v.to_string(), std::string{"1.2.3"});
|
||||
Void::Semver::Version v{1, 2, 3};
|
||||
Void::Testing::expect_eq(v.to_string(), std::string{"1.2.3"});
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_to_string_with_pre_release()
|
||||
{
|
||||
Void::Semver::Version v{1, 0, 0};
|
||||
v.pre_release = "alpha";
|
||||
Void::Testing::expect_eq(v.to_string(), std::string{"1.0.0-alpha"});
|
||||
Void::Semver::Version v{1, 0, 0};
|
||||
v.pre_release = "alpha";
|
||||
Void::Testing::expect_eq(v.to_string(), std::string{"1.0.0-alpha"});
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_round_trip()
|
||||
{
|
||||
const auto v = Void::Semver::parse("3.1.4-rc.1+build1");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->to_string(), std::string{"3.1.4-rc.1+build1"});
|
||||
const auto v = Void::Semver::parse("3.1.4-rc.1+build1");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->to_string(), std::string{"3.1.4-rc.1+build1"});
|
||||
}
|
||||
|
||||
// ── comparison ───────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test semver_compare_major()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("2.0.0");
|
||||
const auto b = *Void::Semver::parse("1.9.9");
|
||||
Void::Testing::expect(a > b);
|
||||
const auto a = *Void::Semver::parse("2.0.0");
|
||||
const auto b = *Void::Semver::parse("1.9.9");
|
||||
Void::Testing::expect(a > b);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_compare_minor()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("1.2.0");
|
||||
const auto b = *Void::Semver::parse("1.1.9");
|
||||
Void::Testing::expect(a > b);
|
||||
const auto a = *Void::Semver::parse("1.2.0");
|
||||
const auto b = *Void::Semver::parse("1.1.9");
|
||||
Void::Testing::expect(a > b);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_compare_patch()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("1.0.1");
|
||||
const auto b = *Void::Semver::parse("1.0.0");
|
||||
Void::Testing::expect(a > b);
|
||||
const auto a = *Void::Semver::parse("1.0.1");
|
||||
const auto b = *Void::Semver::parse("1.0.0");
|
||||
Void::Testing::expect(a > b);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_release_gt_pre_release()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("1.0.0");
|
||||
const auto b = *Void::Semver::parse("1.0.0-alpha");
|
||||
Void::Testing::expect(a > b);
|
||||
const auto a = *Void::Semver::parse("1.0.0");
|
||||
const auto b = *Void::Semver::parse("1.0.0-alpha");
|
||||
Void::Testing::expect(a > b);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_equal()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("1.2.3");
|
||||
const auto b = *Void::Semver::parse("1.2.3");
|
||||
Void::Testing::expect(a == b);
|
||||
const auto a = *Void::Semver::parse("1.2.3");
|
||||
const auto b = *Void::Semver::parse("1.2.3");
|
||||
Void::Testing::expect(a == b);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_prerelease_precedence_is_spec_compliant()
|
||||
{
|
||||
const auto rc2 = *Void::Semver::parse("1.0.0-rc.2");
|
||||
const auto rc10 = *Void::Semver::parse("1.0.0-rc.10");
|
||||
const auto numeric = *Void::Semver::parse("1.0.0-1");
|
||||
const auto alpha = *Void::Semver::parse("1.0.0-alpha");
|
||||
Void::Testing::expect(rc10 > rc2);
|
||||
Void::Testing::expect(numeric < alpha);
|
||||
Void::Testing::expect(*Void::Semver::parse("1.0.0-alpha") <
|
||||
*Void::Semver::parse("1.0.0-alpha.1"));
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_version_ranges()
|
||||
{
|
||||
auto bounded = Void::Semver::parse_range(">=1.2.0 <2.0.0");
|
||||
auto caret = Void::Semver::parse_range("^1.2.3");
|
||||
auto wildcard = Void::Semver::parse_range("1.4.x || 2.0.0");
|
||||
Void::Testing::require(bounded.has_value());
|
||||
Void::Testing::require(caret.has_value());
|
||||
Void::Testing::require(wildcard.has_value());
|
||||
Void::Testing::expect(bounded->contains(*Void::Semver::parse("1.9.9")));
|
||||
Void::Testing::expect(!bounded->contains(*Void::Semver::parse("2.0.0")));
|
||||
Void::Testing::expect(caret->contains(*Void::Semver::parse("1.8.0")));
|
||||
Void::Testing::expect(!caret->contains(*Void::Semver::parse("2.0.0")));
|
||||
Void::Testing::expect(wildcard->contains(*Void::Semver::parse("1.4.9")));
|
||||
Void::Testing::expect(wildcard->contains(*Void::Semver::parse("2.0.0")));
|
||||
}
|
||||
|
||||
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.x").has_value());
|
||||
Void::Testing::expect(
|
||||
!Void::Semver::parse_range("1.4294967295.x").has_value());
|
||||
}
|
||||
|
||||
// ── bump ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test semver_bump_major()
|
||||
{
|
||||
const auto v = Void::Semver::Version{1, 2, 3};
|
||||
const auto b = v.bumped_major();
|
||||
Void::Testing::expect_eq(b.major, 2u);
|
||||
Void::Testing::expect_eq(b.minor, 0u);
|
||||
Void::Testing::expect_eq(b.patch, 0u);
|
||||
const auto v = Void::Semver::Version{1, 2, 3};
|
||||
const auto b = v.bumped_major();
|
||||
Void::Testing::expect_eq(b.major, 2u);
|
||||
Void::Testing::expect_eq(b.minor, 0u);
|
||||
Void::Testing::expect_eq(b.patch, 0u);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_bump_minor()
|
||||
{
|
||||
const auto v = Void::Semver::Version{1, 2, 3};
|
||||
const auto b = v.bumped_minor();
|
||||
Void::Testing::expect_eq(b.minor, 3u);
|
||||
Void::Testing::expect_eq(b.patch, 0u);
|
||||
const auto v = Void::Semver::Version{1, 2, 3};
|
||||
const auto b = v.bumped_minor();
|
||||
Void::Testing::expect_eq(b.minor, 3u);
|
||||
Void::Testing::expect_eq(b.patch, 0u);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_bump_patch()
|
||||
{
|
||||
const auto v = Void::Semver::Version{1, 2, 3};
|
||||
Void::Testing::expect_eq(v.bumped_patch().patch, 4u);
|
||||
const auto v = Void::Semver::Version{1, 2, 3};
|
||||
Void::Testing::expect_eq(v.bumped_patch().patch, 4u);
|
||||
}
|
||||
|
||||
// ── compatible_with ───────────────────────────────────────────────────────────
|
||||
// ── compatible_with
|
||||
// ───────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test semver_compatible_same_major()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("1.3.0");
|
||||
const auto req = *Void::Semver::parse("1.2.0");
|
||||
Void::Testing::expect(a.compatible_with(req));
|
||||
const auto a = *Void::Semver::parse("1.3.0");
|
||||
const auto req = *Void::Semver::parse("1.2.0");
|
||||
Void::Testing::expect(a.compatible_with(req));
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_incompatible_different_major()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("2.0.0");
|
||||
const auto req = *Void::Semver::parse("1.9.9");
|
||||
Void::Testing::expect(!a.compatible_with(req));
|
||||
const auto a = *Void::Semver::parse("2.0.0");
|
||||
const auto req = *Void::Semver::parse("1.9.9");
|
||||
Void::Testing::expect(!a.compatible_with(req));
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_is_stable()
|
||||
{
|
||||
Void::Testing::expect(Void::Semver::Version{1,0,0}.is_stable());
|
||||
Void::Testing::expect(!Void::Semver::Version{0,9,0}.is_stable());
|
||||
Void::Semver::Version pre{1,0,0};
|
||||
pre.pre_release = "alpha";
|
||||
Void::Testing::expect(!pre.is_stable());
|
||||
Void::Testing::expect(Void::Semver::Version{1, 0, 0}.is_stable());
|
||||
Void::Testing::expect(!Void::Semver::Version{0, 9, 0}.is_stable());
|
||||
Void::Semver::Version pre{1, 0, 0};
|
||||
pre.pre_release = "alpha";
|
||||
Void::Testing::expect(!pre.is_stable());
|
||||
}
|
||||
Reference in new issue
Block a user