forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StringView: Add StringView::operator==(StringView)
Previously we'd implicitly convert the second StringView to a String when comparing two StringViews, which is obviously not what we wanted.
- Loading branch information
1 parent
77737be
commit 2349dc1
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <AK/TestSuite.h> | ||
|
||
#include <AK/AKString.h> | ||
|
||
TEST_CASE(construct_empty) | ||
{ | ||
EXPECT(StringView().is_null()); | ||
EXPECT(StringView().is_empty()); | ||
EXPECT(!StringView().characters_without_null_termination()); | ||
EXPECT_EQ(StringView().length(), 0); | ||
} | ||
|
||
TEST_CASE(view_literal) | ||
{ | ||
const char* truth = "cats rule dogs drool"; | ||
StringView view(truth); | ||
EXPECT_EQ(view.is_null(), false); | ||
EXPECT_EQ(view.characters_without_null_termination(), truth); | ||
EXPECT_EQ(view, view); | ||
EXPECT_EQ(view, truth); | ||
} | ||
|
||
TEST_CASE(compare_views) | ||
{ | ||
String foo1 = "foo"; | ||
String foo2 = "foo"; | ||
auto view1 = foo1.view(); | ||
auto view2 = foo2.view(); | ||
|
||
EXPECT_EQ(view1, view2); | ||
EXPECT_EQ(view1, foo1); | ||
EXPECT_EQ(view1, foo2); | ||
EXPECT_EQ(view1, "foo"); | ||
} | ||
|
||
TEST_MAIN(StringView) |