#include #include #include #include namespace { using Void::Configuration::Config; using Void::Testing::Test; struct ByteSize : Void::Testing::Suite { Test si_units() { Config cfg; cfg.set("a", "10KB"); cfg.set("b", "2MB"); cfg.set("c", "1GB"); Void::Testing::expect_eq(cfg.get_as("a").value(), std::uint64_t{10'000}); Void::Testing::expect_eq(cfg.get_as("b").value(), std::uint64_t{2'000'000}); Void::Testing::expect_eq(cfg.get_as("c").value(), std::uint64_t{1'000'000'000}); } Test binary_units() { Config cfg; cfg.set("a", "1KiB"); cfg.set("b", "1GiB"); Void::Testing::expect_eq(cfg.get_as("a").value(), std::uint64_t{1024}); Void::Testing::expect_eq(cfg.get_as("b").value(), std::uint64_t{1024ull * 1024 * 1024}); } Test bare_and_fractional() { Config cfg; cfg.set("plain", "512"); cfg.set("half", "1.5KB"); cfg.set("bytes", "64B"); Void::Testing::expect_eq( cfg.get_as("plain").value(), std::size_t{512}); Void::Testing::expect_eq( cfg.get_as("half").value(), std::size_t{1500}); Void::Testing::expect_eq( cfg.get_as("bytes").value(), std::size_t{64}); } Test invalid_unit_is_error() { Config cfg; cfg.set("bad", "10ZZ"); Void::Testing::expect( !cfg.get_as("bad").has_value()); } }; } // namespace