mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:47:45 +00:00
AK: Fix logic in String::operator>(const String&)
Null strings should not compare greater than non-null strings. Add tests for >, <, >=, and <= comparison involving null strings.
This commit is contained in:
parent
c74f75b910
commit
47e8d58553
2 changed files with 17 additions and 4 deletions
|
@ -58,10 +58,10 @@ bool String::operator<(const String& other) const
|
||||||
|
|
||||||
bool String::operator>(const String& other) const
|
bool String::operator>(const String& other) const
|
||||||
{
|
{
|
||||||
if (!m_impl)
|
|
||||||
return other.m_impl;
|
|
||||||
|
|
||||||
if (!other.m_impl)
|
if (!other.m_impl)
|
||||||
|
return m_impl;
|
||||||
|
|
||||||
|
if (!m_impl)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return strcmp(characters(), other.characters()) > 0;
|
return strcmp(characters(), other.characters()) > 0;
|
||||||
|
|
|
@ -42,7 +42,6 @@ TEST_CASE(construct_contents)
|
||||||
|
|
||||||
TEST_CASE(compare)
|
TEST_CASE(compare)
|
||||||
{
|
{
|
||||||
String test_string = "ABCDEF";
|
|
||||||
EXPECT("a" < String("b"));
|
EXPECT("a" < String("b"));
|
||||||
EXPECT(!("a" > String("b")));
|
EXPECT(!("a" > String("b")));
|
||||||
EXPECT("b" > String("a"));
|
EXPECT("b" > String("a"));
|
||||||
|
@ -51,6 +50,20 @@ TEST_CASE(compare)
|
||||||
EXPECT(!("a" >= String("b")));
|
EXPECT(!("a" >= String("b")));
|
||||||
EXPECT("a" <= String("a"));
|
EXPECT("a" <= String("a"));
|
||||||
EXPECT(!("b" <= String("a")));
|
EXPECT(!("b" <= String("a")));
|
||||||
|
|
||||||
|
EXPECT(String("a") > String());
|
||||||
|
EXPECT(!(String() > String("a")));
|
||||||
|
EXPECT(String() < String("a"));
|
||||||
|
EXPECT(!(String("a") < String()));
|
||||||
|
EXPECT(String("a") >= String());
|
||||||
|
EXPECT(!(String() >= String("a")));
|
||||||
|
EXPECT(String() <= String("a"));
|
||||||
|
EXPECT(!(String("a") <= String()));
|
||||||
|
|
||||||
|
EXPECT(!(String() > String()));
|
||||||
|
EXPECT(!(String() < String()));
|
||||||
|
EXPECT(String() >= String());
|
||||||
|
EXPECT(String() <= String());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(index_access)
|
TEST_CASE(index_access)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue