Overload of String::operator<< taking Point and Rectangle

Currently, it’s impossible to write unit tests that check Rectangles for equality, because writing

expectEquals (rectangle1, rectangle2);

triggers the following error:

Adding an overload for << that takes a Rectangle and calls its toString() method to append the string representation would fix the issue.

All of what is said above regarding Rectangle, also applies to Point

I’ve added a lot of these custom string conversions to my codebase for exactly this reason.

I find that the toString() methods aren’t always formatted in a way that makes debugging them easy, so I add a bit more decoration so they come out something like:

"juce::Rectangle<i>{ 1, 2, 3, 4 }"
"juce::Point<f>{ 5.6, 7.8 }"

I’d be all in favour of adding some default string conversions for common JUCE types, but only if they can be easily overridden to add my own custom conversions (or have the default ones be super verbose).

1 Like