This patch fixes a few problems with the FormatAnsiTerminalCodes function:
- It does an infinite loop on an unknown color value.
- It crashes when the color value is at the end of the string.
- It deletes the first character behind the color token.
Also added a few tests that reproduce those problems (and test some other corner cases).
I would suggest getting rid of the temporary format variable. That way, if this assertion fails, the error message will immediately tell you what the failing command was.
(you can also use EXPECT_EQ here as operator== will do the right thing when one of the arguments is a std::string)