|
| 1 | +#include <gtest/gtest.h> |
| 2 | +#include <libhat/cow.hpp> |
| 3 | +#include <libhat/cstring_view.hpp> |
| 4 | +#include <libhat/fixed_string.hpp> |
| 5 | +#include <libhat/signature.hpp> |
| 6 | +#include <libhat/string_literal.hpp> |
| 7 | +#include <format> |
| 8 | + |
| 9 | +using namespace std::literals; |
| 10 | +using namespace hat::literals; |
| 11 | + |
| 12 | +TEST(FormatterTest, FixedString) { |
| 13 | + ASSERT_EQ(std::format("{}", hat::fixed_string{"abc"}), "abc"sv); |
| 14 | +} |
| 15 | + |
| 16 | +TEST(FormatterTest, StringLiteral) { |
| 17 | + ASSERT_EQ(std::format("{}", "abc"_s), "abc"sv); |
| 18 | +} |
| 19 | + |
| 20 | +TEST(FormatterTest, CStringView) { |
| 21 | + ASSERT_EQ(std::format("{}", "abc"_csv), "abc"sv); |
| 22 | +} |
| 23 | + |
| 24 | +TEST(FormatterTest, CowString) { |
| 25 | + ASSERT_EQ(std::format("{}", hat::cow_string{"abc"s}), "abc"sv); |
| 26 | + ASSERT_EQ(std::format("{}", hat::cow_string{"abc"sv}), "abc"sv); |
| 27 | +} |
| 28 | + |
| 29 | +TEST(FormatterTest, CowCString) { |
| 30 | + ASSERT_EQ(std::format("{}", hat::cow_cstring{"abc"s}), "abc"sv); |
| 31 | + ASSERT_EQ(std::format("{}", hat::cow_cstring{"abc"_csv}), "abc"sv); |
| 32 | +} |
| 33 | + |
| 34 | +TEST(FormatterTest, CowSpan) { |
| 35 | + std::vector data{1, 2, 3}; |
| 36 | + ASSERT_EQ(std::format("{}", hat::cow_span<int>{data}), "[1, 2, 3]"sv); |
| 37 | + ASSERT_EQ(std::format("{}", hat::cow_span<int>{std::span{data}}), "[1, 2, 3]"sv); |
| 38 | + // ASSERT_EQ(std::format("{}", hat::cow_writable_span<int>{data}), "[1, 2, 3]"sv); |
| 39 | + // ASSERT_EQ(std::format("{}", hat::cow_writable_span<int>{std::span{data}}), "[1, 2, 3]"sv); |
| 40 | +} |
| 41 | + |
| 42 | +TEST(FormatterTest, SignatureElement) { |
| 43 | + ASSERT_EQ(std::format("{}", hat::signature_element{std::byte{0x10}, std::byte{0xF0}}), "1?"sv); |
| 44 | +} |
| 45 | + |
| 46 | +TEST(FormatterTest, Signature) { |
| 47 | + constexpr auto sig = "11 22 33"_sig; |
| 48 | + ASSERT_EQ(std::format("{}", hat::signature(sig.begin(), sig.end())), "11 22 33"sv); |
| 49 | + ASSERT_EQ(std::format("{}", hat::signature_view{sig}), "11 22 33"sv); |
| 50 | + ASSERT_EQ(std::format("{}", sig), "11 22 33"sv); |
| 51 | +} |
0 commit comments