Last active
June 8, 2016 11:07
-
-
Save sergey-shambir/8f4f01116c1876991d4a032b9187426c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void VerifyText(const std::wstring &text, const std::wstring expectedText) | |
{ | |
const auto pair = boost::mismatch(text, expectedText); | |
const bool textEnded = (pair.first == text.end()); | |
const bool expectedEnded = (pair.second == expectedText.end()); | |
if (textEnded) | |
{ | |
if (expectedEnded) | |
{ | |
// No message, strings equal. Check just to ensure: | |
BOOST_CHECK(text == expectedText); | |
} | |
else | |
{ | |
boost::format fmt("Text is too short: got %1% bytes while %2% bytes expected"); | |
BOOST_ERROR((fmt % text.size() % expectedText.size()).str()); | |
} | |
} | |
else | |
{ | |
if (expectedEnded) | |
{ | |
boost::format fmt("Text is too long: got %1% bytes while %2% bytes expected"); | |
BOOST_ERROR((fmt % text.size() % expectedText.size()).str()); | |
} | |
else | |
{ | |
const auto distance = (pair.first - text.begin()); | |
const auto lineNo = 1 + std::count(text.begin(), pair.first, L'\n'); | |
boost::format fmt("Text mismatch at %1%-th character (%2%-th line)."); | |
BOOST_ERROR((fmt % distance % lineNo).str()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment