Utils: Add compare function for string views

It is more efficient to use compare instead of less and equal together.

Change-Id: I772b03ba02509c0ebc5d5d770be14cf7d5bd431e
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2017-08-21 10:21:47 +02:00
parent d45cd9a35b
commit 24e5dd0556
2 changed files with 67 additions and 0 deletions

View File

@@ -1375,3 +1375,24 @@ TEST(SmallString, ShortStringCapacity)
ASSERT_THAT(PathString().shortStringCapacity(), 189);
}
TEST(SmallString, Compare)
{
ASSERT_THAT(Utils::compare("", ""), Eq(0));
ASSERT_THAT(Utils::compare("text", "text"), Eq(0));
ASSERT_THAT(Utils::compare("", "text"), Le(0));
ASSERT_THAT(Utils::compare("textx", "text"), Gt(0));
ASSERT_THAT(Utils::compare("text", "textx"), Le(0));
ASSERT_THAT(Utils::compare("textx", "texta"), Gt(0));
ASSERT_THAT(Utils::compare("texta", "textx"), Le(0));
}
TEST(SmallString, ReverseCompare)
{
ASSERT_THAT(Utils::reverseCompare("", ""), Eq(0));
ASSERT_THAT(Utils::reverseCompare("text", "text"), Eq(0));
ASSERT_THAT(Utils::reverseCompare("", "text"), Le(0));
ASSERT_THAT(Utils::reverseCompare("textx", "text"), Gt(0));
ASSERT_THAT(Utils::reverseCompare("text", "textx"), Le(0));
ASSERT_THAT(Utils::reverseCompare("textx", "texta"), Gt(0));
ASSERT_THAT(Utils::reverseCompare("texta", "textx"), Le(0));
}