Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sstring.find(): make find("") compatible with std::string #1002

Closed
wants to merge 1 commit into from

Conversation

longqimin
Copy link

Copy link
Contributor

@nyh nyh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I left a suggestion on how to improve the test by making it more convincing that find's behavior is the same as std::string's, and not just our incorrect interpretation.

BOOST_REQUIRE_EQUAL(sstring("abcde").find("", 0), 0u);
BOOST_REQUIRE_EQUAL(sstring("abcde").find("", 1), 1u);
BOOST_REQUIRE_EQUAL(sstring("abcde").find("", 5), 5u);
BOOST_REQUIRE_EQUAL(sstring("abcde").find("", 6), sstring::npos);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the goal of this test (or at least the newly added lines) is to check compatiblity with std::string, this implementation of the test is not convincing enough: you check that find("", 5) should be 5, but who said it should be 5?

What I would have done is to do something like

auto check_find = [] (const char* s1, const char* s2, int n1, unsigned int n2) {
    BOOST_REQUIRE_EQUAL(sstring(s1).find(s2, n), n2);
    // verify that std::string really has the same behavior as we just tested for sstring
    BOOST_REQUIRE_EQUAL(std::string(s1).find(s2, n), n2);
}
check_find("", "", 0, 0);
check_find("", "", 1, sstring::npos);
...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test updated. but i found the npos of sstring/std::string may not be equal

Copy link
Contributor

@nyh nyh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@nyh nyh closed this in fde471f Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants