Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cpp/test/phonenumbers/phonenumbermatcher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ class PhoneNumberMatcherTest : public testing::Test {
void EnsureTermination(const string& text, const string& default_country,
PhoneNumberMatcher::Leniency leniency) {
for (size_t index = 0; index <= text.length(); ++index) {
string sub = text.substr(index);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, not quite sure what this test tries to achieve. This line is the only use of index, so not sure what the point is of running this test text.length() times. Maybe the code below wanted to use sub somewhere? Do you know what this attempts to achieve?

As-is, this PR fixes the warning and keeps current behavior.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry about the late response and thank you for the PR. EnsureTermination was ported from PhoneNumberMatcherTest.ensureTermination in Java (java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java), which tests that matching terminates when starting from every offset in text:

String sub = text.substring(index);
...
for (PhoneNumberMatch match :
     phoneUtil.findNumbers(sub, defaultCountry, leniency, Long.MAX_VALUE)) {

Passing text instead of sub to PhoneNumberMatcher here was a typo in the C++ port (compare AssertEqualRange earlier in this file, which passes sub). Could you keep string sub = text.substr(index); and pass sub to PhoneNumberMatcher on line 321 instead? That both resolves the unused-variable warning and makes the test actually exercise each suffix as intended.

// Iterates over all matches.
PhoneNumberMatcher matcher(phone_util_, text, default_country, leniency,
1000000 /* max_tries */);
Expand Down
Loading