From 01ee2ecefc0b82f8eb52592518b2f8ceddfce3a8 Mon Sep 17 00:00:00 2001 From: ephphatha Date: Thu, 2 Jun 2022 23:20:29 +1000 Subject: [PATCH] Pretty print Size values in test failure messages --- Source/engine/size.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Source/engine/size.hpp b/Source/engine/size.hpp index 5840c95ce..c2cdc9fcc 100644 --- a/Source/engine/size.hpp +++ b/Source/engine/size.hpp @@ -1,5 +1,9 @@ #pragma once +#ifdef BUILD_TESTING +#include +#endif + namespace devilution { struct Size { @@ -75,6 +79,19 @@ struct Size { a /= factor; return a; } + +#ifdef BUILD_TESTING + /** + * @brief Format sizes nicely in test failure messages + * @param stream output stream, expected to have overloads for int and char* + * @param size Object to display + * @return the stream, to allow chaining + */ + friend std::ostream &operator<<(std::ostream &stream, const Size &size) + { + return stream << "(width: " << size.width << ", height: " << size.height << ")"; + } +#endif }; } // namespace devilution