From f5d105b34d25f3b152001c097b7311c3093f8a46 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 18 Sep 2024 22:57:42 -0600 Subject: [PATCH] qvec: allow gtest to print --- include/common/qvec.hh | 6 ++++++ tests/test_light.cc | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/common/qvec.hh b/include/common/qvec.hh index c4f72fc1..33f3ee67 100644 --- a/include/common/qvec.hh +++ b/include/common/qvec.hh @@ -296,6 +296,12 @@ public: constexpr auto end() const { return v.end(); } constexpr auto cbegin() const { return v.cbegin(); } constexpr auto cend() const { return v.cend(); } + + // gtest support + friend std::ostream& operator<<(std::ostream& os, const qvec& point) { + os << fmt::format("{}", point); + return os; + } }; // Fmt support diff --git a/tests/test_light.cc b/tests/test_light.cc index a8b742e9..ed3995df 100644 --- a/tests/test_light.cc +++ b/tests/test_light.cc @@ -717,6 +717,20 @@ TEST(mathlib, qvecConstructorExtra) EXPECT_EQ(2, test[1]); } +TEST(mathlib, qvecGTestPrint) +{ + const qvec2f test(1, 2); + + EXPECT_EQ(testing::PrintToString(test), "1 2"); +} + +TEST(mathlib, qvecFmtFormat) +{ + const qvec2f test(1, 2); + + EXPECT_EQ("1 2", fmt::format("{}", test)); +} + // aabb3f TEST(mathlib, aabbBasic)