diff options
author | Rouslan Solomakhin <rouslan@chromium.org> | 2014-06-17 19:18:19 +0000 |
---|---|---|
committer | Fredrik Roubert <roubert@google.com> | 2014-09-01 19:20:48 +0200 |
commit | 55cee59462831ec0c28353b80f0f2bfe540a0f7b (patch) | |
tree | 34ca4d1cde5cbbcb0778bab2034917695697bbef | |
parent | eb22690fd935210a35d0bf9a1726fb7fc1b90ebf (diff) | |
download | src-55cee59462831ec0c28353b80f0f2bfe540a0f7b.tar.gz |
Show only one example of postal code in error messages.
This patch changes error messages for postal codes to show at most one
example of a valid postal code. This behavior resembles other
implementations more closely.
R=keghani@google.com
Review URL: https://codereview.appspot.com/107160044
-rw-r--r-- | cpp/src/localization.cc | 7 | ||||
-rw-r--r-- | cpp/test/localization_test.cc | 24 |
2 files changed, 14 insertions, 17 deletions
diff --git a/cpp/src/localization.cc b/cpp/src/localization.cc index 951f1a7..85cbf4d 100644 --- a/cpp/src/localization.cc +++ b/cpp/src/localization.cc @@ -25,6 +25,7 @@ #include "grit.h" #include "region_data_constants.h" #include "rule.h" +#include "util/string_split.h" #include "util/string_util.h" namespace { @@ -83,7 +84,11 @@ std::string Localization::GetErrorMessage(const AddressData& address, if (rule.ParseSerializedRule( RegionDataConstants::GetRegionData(address.region_code))) { if (enable_examples) { - postal_code_example = rule.GetPostalCodeExample(); + std::vector<std::string> examples_list; + SplitString(rule.GetPostalCodeExample(), ',', &examples_list); + if (!examples_list.empty()) { + postal_code_example = examples_list.front(); + } } if (enable_links) { post_service_url = rule.GetPostServiceUrl(); diff --git a/cpp/test/localization_test.cc b/cpp/test/localization_test.cc index d1c4a9d..32032ab 100644 --- a/cpp/test/localization_test.cc +++ b/cpp/test/localization_test.cc @@ -139,15 +139,13 @@ TEST(LocalizationGetErrorMessageTest, MissingRequiredPostalCode) { Localization localization; AddressData address; address.region_code = "CH"; - EXPECT_EQ(std::string("You must provide a postal code, for example") + - " 2544,1211,1556,3030." + + EXPECT_EQ(std::string("You must provide a postal code, for example 2544.") + " Don't know your postal code? Find it out" + " <a href=\"http://www.post.ch/db/owa/pv_plz_pack/pr_main\">" + "here</a>.", localization.GetErrorMessage(address, POSTAL_CODE, MISSING_REQUIRED_FIELD, true, true)); - EXPECT_EQ(std::string("You must provide a postal code, for example") + - " 2544,1211,1556,3030.", + EXPECT_EQ("You must provide a postal code, for example 2544.", localization.GetErrorMessage(address, POSTAL_CODE, MISSING_REQUIRED_FIELD, true, false)); EXPECT_EQ("You can't leave this empty.", @@ -162,15 +160,13 @@ TEST(LocalizationGetErrorMessageTest, MissingRequiredZipCode) { Localization localization; AddressData address; address.region_code = "US"; - EXPECT_EQ(std::string("You must provide a ZIP code, for example") + - " 95014,22162-1010." + + EXPECT_EQ(std::string("You must provide a ZIP code, for example 95014.") + " Don't know your ZIP code? Find it out" + " <a href=\"https://tools.usps.com/go/ZipLookupAction!" + "input.action\">here</a>.", localization.GetErrorMessage(address, POSTAL_CODE, MISSING_REQUIRED_FIELD, true, true)); - EXPECT_EQ(std::string("You must provide a ZIP code, for example") + - " 95014,22162-1010.", + EXPECT_EQ("You must provide a ZIP code, for example 95014.", localization.GetErrorMessage(address, POSTAL_CODE, MISSING_REQUIRED_FIELD, true, false)); EXPECT_EQ("You can't leave this empty.", @@ -342,16 +338,14 @@ TEST(LocalizationGetErrorMessageTest, InvalidFormatPostalCode) { AddressData address; address.region_code = "CH"; EXPECT_EQ(std::string("This postal code format is not recognized. Example ") + - "of a valid postal code:" + - " 2544,1211,1556,3030." + + "of a valid postal code: 2544." + " Don't know your postal code? Find it out" + " <a href=\"http://www.post.ch/db/owa/pv_plz_pack/pr_main\">" + "here</a>.", localization.GetErrorMessage(address, POSTAL_CODE, INVALID_FORMAT, true, true)); EXPECT_EQ(std::string("This postal code format is not recognized. Example ") + - "of a valid postal code:" + - " 2544,1211,1556,3030.", + "of a valid postal code: 2544.", localization.GetErrorMessage(address, POSTAL_CODE, INVALID_FORMAT, true, false)); EXPECT_EQ("This postal code format is not recognized.", @@ -367,16 +361,14 @@ TEST(LocalizationGetErrorMessageTest, InvalidFormatZipCode) { AddressData address; address.region_code = "US"; EXPECT_EQ(std::string("This ZIP code format is not recognized. Example of ") + - "a valid ZIP code:" + - " 95014,22162-1010." + + "a valid ZIP code: 95014." + " Don't know your ZIP code? Find it out" + " <a href=\"https://tools.usps.com/go/ZipLookupAction!" + "input.action\">here</a>.", localization.GetErrorMessage(address, POSTAL_CODE, INVALID_FORMAT, true, true)); EXPECT_EQ(std::string("This ZIP code format is not recognized. Example of ") + - "a valid ZIP code:" + - " 95014,22162-1010.", + "a valid ZIP code: 95014.", localization.GetErrorMessage(address, POSTAL_CODE, INVALID_FORMAT, true, false)); EXPECT_EQ("This ZIP code format is not recognized.", |