#include #include #include #include namespace { struct PlainStruct { int code; std::string label; }; struct DiagInfo { std::string file; int line; std::string detail; }; } // namespace Void::Testing::Test repr_uses_std_format_when_available() { const auto out = Void::Result::Detail::repr(42); Void::Testing::expect_eq(out, std::string{"42"}); } Void::Testing::Test repr_uses_std_format_for_string() { const auto out = Void::Result::Detail::repr(std::string{"hello"}); Void::Testing::expect_eq(out, std::string{"hello"}); } #ifdef VOID_RESULT_HAS_REFLECTION // @tag reflection Void::Testing::Test repr_walks_struct_fields_via_reflection() { PlainStruct s{42, "ok"}; const auto out = Void::Result::Detail::repr(s); Void::Testing::expect(out.find("PlainStruct") != std::string::npos); Void::Testing::expect(out.find("code: 42") != std::string::npos); Void::Testing::expect(out.find("label: ok") != std::string::npos); } // @tag reflection Void::Testing::Test repr_handles_multiple_fields() { DiagInfo d{"foo.cpp", 17, "bad token"}; const auto out = Void::Result::Detail::repr(d); Void::Testing::expect(out.find("DiagInfo") != std::string::npos); Void::Testing::expect(out.find("file: foo.cpp") != std::string::npos); Void::Testing::expect(out.find("line: 17") != std::string::npos); Void::Testing::expect(out.find("detail: bad token") != std::string::npos); } #endif