test: check if uppercase is parsed

This commit is contained in:
ToruNiina
2024-07-14 15:14:01 +09:00
parent 452f1702c2
commit a69877005d
2 changed files with 44 additions and 16 deletions

View File

@@ -4,6 +4,7 @@
#include <toml11/parser.hpp> #include <toml11/parser.hpp>
#include <toml11/serializer.hpp> #include <toml11/serializer.hpp>
#include <toml11/types.hpp> #include <toml11/types.hpp>
#include <toml11/literal.hpp>
TEST_CASE("testing decimal") TEST_CASE("testing decimal")
{ {
@@ -25,19 +26,40 @@ TEST_CASE("testing decimal")
TEST_CASE("testing hex") TEST_CASE("testing hex")
{ {
const auto hex_fmt = [](std::size_t w, std::size_t s) { const auto hex_fmt = [](bool u, std::size_t w, std::size_t s) {
toml::integer_format_info fmt; toml::integer_format_info fmt;
fmt.fmt = toml::integer_format::hex; fmt.fmt = toml::integer_format::hex;
fmt.uppercase = u;
fmt.width = w; fmt.width = w;
fmt.spacer = s; fmt.spacer = s;
return fmt; return fmt;
}; };
CHECK_EQ("0xdeadbeef", toml::format(toml::value(0xDEADBEEF, hex_fmt(8, 0)))); CHECK_EQ("0xdeadbeef", toml::format(toml::value(0xDEADBEEF, hex_fmt(false, 8, 0))));
CHECK_EQ("0xdead_beef", toml::format(toml::value(0xDEADBEEF, hex_fmt(8, 4)))); CHECK_EQ("0xdead_beef", toml::format(toml::value(0xDEADBEEF, hex_fmt(false, 8, 4))));
CHECK_EQ("0xff", toml::format(toml::value(0xFF, hex_fmt(2, 0)))); CHECK_EQ("0xff", toml::format(toml::value(0xFF, hex_fmt(false, 2, 0))));
CHECK_EQ("0x00ff", toml::format(toml::value(0xFF, hex_fmt(4, 0)))); CHECK_EQ("0x00ff", toml::format(toml::value(0xFF, hex_fmt(false, 4, 0))));
CHECK_EQ("0x0000ff", toml::format(toml::value(0xFF, hex_fmt(6, 0)))); CHECK_EQ("0x0000ff", toml::format(toml::value(0xFF, hex_fmt(false, 6, 0))));
CHECK_EQ("0xDEADBEEF", toml::format(toml::value(0xDEADBEEF, hex_fmt(true, 8, 0))));
CHECK_EQ("0xDEAD_BEEF", toml::format(toml::value(0xDEADBEEF, hex_fmt(true, 8, 4))));
CHECK_EQ("0xFF", toml::format(toml::value(0xFF, hex_fmt(true, 2, 0))));
CHECK_EQ("0x00FF", toml::format(toml::value(0xFF, hex_fmt(true, 4, 0))));
CHECK_EQ("0x0000FF", toml::format(toml::value(0xFF, hex_fmt(true, 6, 0))));
using namespace toml::literals::toml_literals;
CHECK_EQ("0xdeadbeef", toml::format("0xdeadbeef"_toml ));
CHECK_EQ("0xdead_beef", toml::format("0xdead_beef"_toml));
CHECK_EQ("0xff", toml::format("0xff"_toml ));
CHECK_EQ("0x00ff", toml::format("0x00ff"_toml ));
CHECK_EQ("0x0000ff", toml::format("0x0000ff"_toml ));
CHECK_EQ("0xDEADBEEF", toml::format("0xDEADBEEF"_toml ));
CHECK_EQ("0xDEAD_BEEF", toml::format("0xDEAD_BEEF"_toml));
CHECK_EQ("0xFF", toml::format("0xFF"_toml ));
CHECK_EQ("0x00FF", toml::format("0x00FF"_toml ));
CHECK_EQ("0x0000FF", toml::format("0x0000FF"_toml ));
} }
TEST_CASE("testing oct") TEST_CASE("testing oct")

View File

@@ -34,23 +34,29 @@ TEST_CASE("testing decimal_value")
TEST_CASE("testing hex_value") TEST_CASE("testing hex_value")
{ {
toml::detail::context<toml::type_config> ctx(toml::spec::v(1,0,0)); toml::detail::context<toml::type_config> ctx(toml::spec::v(1,0,0));
const auto hex_fmt = [](std::size_t w, std::size_t s) { const auto hex_fmt = [](bool u, std::size_t w, std::size_t s) {
toml::integer_format_info fmt; toml::integer_format_info fmt;
fmt.fmt = toml::integer_format::hex; fmt.fmt = toml::integer_format::hex;
fmt.uppercase = u;
fmt.width = w; fmt.width = w;
fmt.spacer = s; fmt.spacer = s;
return fmt; return fmt;
}; };
toml11_test_parse_success<toml::value_t::integer>("0xDEADBEEF", 0xDEADBEEF, comments(), hex_fmt(8, 0), ctx); toml11_test_parse_success<toml::value_t::integer>("0xDEADBEEF", 0xDEADBEEF, comments(), hex_fmt(true, 8, 0), ctx);
toml11_test_parse_success<toml::value_t::integer>("0xdeadbeef", 0xDEADBEEF, comments(), hex_fmt(8, 0), ctx); toml11_test_parse_success<toml::value_t::integer>("0xdeadbeef", 0xDEADBEEF, comments(), hex_fmt(false, 8, 0), ctx);
toml11_test_parse_success<toml::value_t::integer>("0xDEADbeef", 0xDEADBEEF, comments(), hex_fmt(8, 0), ctx); toml11_test_parse_success<toml::value_t::integer>("0xDEADbeef", 0xDEADBEEF, comments(), hex_fmt(true, 8, 0), ctx);
toml11_test_parse_success<toml::value_t::integer>("0xDEAD_BEEF", 0xDEADBEEF, comments(), hex_fmt(8, 4), ctx); toml11_test_parse_success<toml::value_t::integer>("0xDEAD_BEEF", 0xDEADBEEF, comments(), hex_fmt(true, 8, 4), ctx);
toml11_test_parse_success<toml::value_t::integer>("0xdead_beef", 0xDEADBEEF, comments(), hex_fmt(8, 4), ctx); toml11_test_parse_success<toml::value_t::integer>("0xdead_beef", 0xDEADBEEF, comments(), hex_fmt(false, 8, 4), ctx);
toml11_test_parse_success<toml::value_t::integer>("0xdead_BEEF", 0xDEADBEEF, comments(), hex_fmt(8, 4), ctx); toml11_test_parse_success<toml::value_t::integer>("0xdead_BEEF", 0xDEADBEEF, comments(), hex_fmt(true, 8, 4), ctx);
toml11_test_parse_success<toml::value_t::integer>("0xFF", 0xFF, comments(), hex_fmt(2, 0), ctx); toml11_test_parse_success<toml::value_t::integer>("0xFF", 0xFF, comments(), hex_fmt(true, 2, 0), ctx);
toml11_test_parse_success<toml::value_t::integer>("0x00FF", 0xFF, comments(), hex_fmt(4, 0), ctx); toml11_test_parse_success<toml::value_t::integer>("0x00FF", 0xFF, comments(), hex_fmt(true, 4, 0), ctx);
toml11_test_parse_success<toml::value_t::integer>("0x0000FF", 0xFF, comments(), hex_fmt(6, 0), ctx); toml11_test_parse_success<toml::value_t::integer>("0x0000FF", 0xFF, comments(), hex_fmt(true, 6, 0), ctx);
toml11_test_parse_success<toml::value_t::integer>("0xff", 0xFF, comments(), hex_fmt(false, 2, 0), ctx);
toml11_test_parse_success<toml::value_t::integer>("0x00ff", 0xFF, comments(), hex_fmt(false, 4, 0), ctx);
toml11_test_parse_success<toml::value_t::integer>("0x0000ff", 0xFF, comments(), hex_fmt(false, 6, 0), ctx);
toml11_test_parse_success<toml::value_t::integer>("0x00", 0, comments(), hex_fmt(true, 2, 0), ctx);
toml11_test_parse_success<toml::value_t::integer>("0x12345", 0x12345, comments(), hex_fmt(true, 5, 0), ctx);
} }
TEST_CASE("testing oct_value") TEST_CASE("testing oct_value")