diff --git a/cpp/include/libaddressinput/localization.h b/cpp/include/libaddressinput/localization.h index e116b32..e4e7e7c 100644 --- a/cpp/include/libaddressinput/localization.h +++ b/cpp/include/libaddressinput/localization.h @@ -49,22 +49,6 @@ class Localization { // there's no message with this identifier. std::string GetString(int message_id) const; - // Returns the error message. If |enable_examples| is false, then the error - // message will not contain examples of valid input. If |enable_links| is - // false, then the error message will not contain HTML links. (Some error - // messages contain postal code examples or link to post office websites to - // look up the postal code for an address). Vector field values (e.g. for - // street address) should not be empty if problem is UNKNOWN_VALUE. The - // POSTAL_CODE field should only be used with MISSING_REQUIRED_FIELD, - // INVALID_FORMAT, and MISMATCHING_VALUE problem codes. All other fields - // should only be used with MISSING_REQUIRED_FIELD, UNKNOWN_VALUE, and - // USES_P_O_BOX problem codes. - std::string GetErrorMessage(const AddressData& address, - AddressField field, - AddressProblem problem, - bool enable_examples, - bool enable_links) const; - // Sets the string getter that takes a message identifier and returns the // corresponding localized string. For example, in Chromium there is // l10n_util::GetStringUTF8 which always returns strings in the current @@ -72,18 +56,6 @@ class Localization { void SetGetter(std::string (*getter)(int)); private: - // Returns the error message where the address field is a postal code. Helper - // to |GetErrorMessage|. If |postal_code_example| is empty, then the error - // message will not contain examples of valid postal codes. If - // |post_service_url| is empty, then the error message will not contain a post - // service URL. The problem should only be one of MISSING_REQUIRED_FIELD, - // INVALID_FORMAT, or MISMATCHING_VALUE. - std::string GetErrorMessageForPostalCode( - AddressProblem problem, - bool uses_postal_code_as_label, - const std::string& postal_code_example, - const std::string& post_service_url) const; - // The string getter. std::string (*get_string_)(int); }; diff --git a/cpp/res/messages.grdp b/cpp/res/messages.grdp index b5b5bc1..9622805 100644 --- a/cpp/res/messages.grdp +++ b/cpp/res/messages.grdp @@ -167,134 +167,4 @@ limitations under the License. desc="Label for a neighborhood, shown as part of an address input form."> Neighborhood - - You can't leave this empty. - - - You must provide a postal code, for example $190291. Don't know your postal code? Find it out $2here$3. - - - You must provide a postal code, for example $190291. - - - You must provide a ZIP code, for example $190291. Don't know your ZIP code? Find it out $2here$3. - - - You must provide a ZIP code, for example $190291. - - - $1Cupertino is not recognized as a known value for this field. - - - This postal code format is not recognized. Example of a valid postal code: $190291. Don't know your postal code? Find it out $2here$3. - - - This postal code format is not recognized. Example of a valid postal code: $190291. - - - This postal code format is not recognized. - - - This ZIP code format is not recognized. Example of a valid ZIP code: $190291. Don't know your ZIP code? Find it out $2here$3. - - - This ZIP code format is not recognized. Example of a valid ZIP code: $190291. - - - This ZIP code format is not recognized. - - - This postal code does not appear to match the rest of this address. Don't know your postal code? Find it out $1here$2. - - - This postal code does not appear to match the rest of this address. - - - This ZIP code does not appear to match the rest of this address. Don't know your ZIP code? Find it out $1here$2. - - - This ZIP code does not appear to match the rest of this address. - - - This address line appears to contain a post office box. Please use a street or building address. - diff --git a/cpp/src/localization.cc b/cpp/src/localization.cc index 01a4016..a046c10 100644 --- a/cpp/src/localization.cc +++ b/cpp/src/localization.cc @@ -14,31 +14,10 @@ #include -#include -#include -#include - #include -#include #include -#include #include "messages.h" -#include "region_data_constants.h" -#include "rule.h" -#include "util/string_split.h" -#include "util/string_util.h" - -namespace { - -void PushBackUrl(const std::string& url, std::vector* parameters) { - assert(parameters != nullptr); - // TODO: HTML-escape the "url". - parameters->push_back(""); - parameters->emplace_back(""); -} - -} // namespace namespace i18n { namespace addressinput { @@ -60,127 +39,10 @@ std::string Localization::GetString(int message_id) const { return get_string_(message_id); } -std::string Localization::GetErrorMessage(const AddressData& address, - AddressField field, - AddressProblem problem, - bool enable_examples, - bool enable_links) const { - if (field == POSTAL_CODE) { - Rule rule; - rule.CopyFrom(Rule::GetDefault()); - std::string postal_code_example, post_service_url; - if (rule.ParseSerializedRule( - RegionDataConstants::GetRegionData(address.region_code))) { - if (enable_examples) { - std::vector 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(); - } - } else { - assert(false); - } - // If we can't parse the serialized rule |uses_postal_code_as_label| will be - // determined from the default rule. - bool uses_postal_code_as_label = - rule.GetPostalCodeNameMessageId() == - IDS_LIBADDRESSINPUT_POSTAL_CODE_LABEL; - return GetErrorMessageForPostalCode(problem, uses_postal_code_as_label, - postal_code_example, post_service_url); - } else { - if (problem == MISSING_REQUIRED_FIELD) { - return get_string_(IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD); - } else if (problem == UNKNOWN_VALUE) { - std::vector parameters; - if (AddressData::IsRepeatedFieldValue(field)) { - const auto& values = address.GetRepeatedFieldValue(field); - assert(!values.empty()); - parameters.push_back(values.front()); - } else { - parameters.push_back(address.GetFieldValue(field)); - } - return DoReplaceStringPlaceholders( - get_string_(IDS_LIBADDRESSINPUT_UNKNOWN_VALUE), parameters); - } else if (problem == USES_P_O_BOX) { - return get_string_(IDS_LIBADDRESSINPUT_PO_BOX_FORBIDDEN_VALUE); - } else { - // Keep the default under "else" so the compiler helps us check that all - // handled cases return and don't fall through. - assert(false); - return ""; - } - } -} - void Localization::SetGetter(std::string (*getter)(int)) { assert(getter != nullptr); get_string_ = getter; } -std::string Localization::GetErrorMessageForPostalCode( - AddressProblem problem, - bool uses_postal_code_as_label, - const std::string& postal_code_example, - const std::string& post_service_url) const { - int message_id; - std::vector parameters; - if (problem == MISSING_REQUIRED_FIELD) { - if (!postal_code_example.empty() && !post_service_url.empty()) { - message_id = uses_postal_code_as_label ? - IDS_LIBADDRESSINPUT_MISSING_REQUIRED_POSTAL_CODE_EXAMPLE_AND_URL : - IDS_LIBADDRESSINPUT_MISSING_REQUIRED_ZIP_CODE_EXAMPLE_AND_URL; - parameters.push_back(postal_code_example); - PushBackUrl(post_service_url, ¶meters); - } else if (!postal_code_example.empty()) { - message_id = uses_postal_code_as_label ? - IDS_LIBADDRESSINPUT_MISSING_REQUIRED_POSTAL_CODE_EXAMPLE : - IDS_LIBADDRESSINPUT_MISSING_REQUIRED_ZIP_CODE_EXAMPLE; - parameters.push_back(postal_code_example); - } else { - message_id = IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD; - } - return DoReplaceStringPlaceholders(get_string_(message_id), parameters); - } else if (problem == INVALID_FORMAT) { - if (!postal_code_example.empty() && !post_service_url.empty()) { - message_id = uses_postal_code_as_label ? - IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_POSTAL_CODE_EXAMPLE_AND_URL : - IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_ZIP_CODE_EXAMPLE_AND_URL; - parameters.push_back(postal_code_example); - PushBackUrl(post_service_url, ¶meters); - } else if (!postal_code_example.empty()) { - message_id = uses_postal_code_as_label ? - IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_POSTAL_CODE_EXAMPLE : - IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_ZIP_CODE_EXAMPLE; - parameters.push_back(postal_code_example); - } else { - message_id = uses_postal_code_as_label ? - IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_POSTAL_CODE : - IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_ZIP; - } - return DoReplaceStringPlaceholders(get_string_(message_id), parameters); - } else if (problem == MISMATCHING_VALUE) { - if (!post_service_url.empty()) { - message_id = uses_postal_code_as_label ? - IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_POSTAL_CODE_URL : - IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_ZIP_URL; - PushBackUrl(post_service_url, ¶meters); - } else { - message_id = uses_postal_code_as_label ? - IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_POSTAL_CODE : - IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_ZIP; - } - return DoReplaceStringPlaceholders(get_string_(message_id), parameters); - } else { - // Keep the default under "else" so the compiler helps us check that all - // handled cases return and don't fall through. - assert(false); - return ""; - } -} - } // namespace addressinput } // namespace i18n diff --git a/cpp/test/localization_test.cc b/cpp/test/localization_test.cc index 26daa9d..726eb8c 100644 --- a/cpp/test/localization_test.cc +++ b/cpp/test/localization_test.cc @@ -14,12 +14,7 @@ #include -#include -#include -#include - #include -#include #include @@ -28,27 +23,9 @@ namespace { -using i18n::addressinput::AddressData; -using i18n::addressinput::AddressField; using i18n::addressinput::INVALID_MESSAGE_ID; using i18n::addressinput::Localization; -using i18n::addressinput::COUNTRY; -using i18n::addressinput::ADMIN_AREA; -using i18n::addressinput::LOCALITY; -using i18n::addressinput::DEPENDENT_LOCALITY; -using i18n::addressinput::SORTING_CODE; -using i18n::addressinput::POSTAL_CODE; -using i18n::addressinput::STREET_ADDRESS; -using i18n::addressinput::ORGANIZATION; -using i18n::addressinput::RECIPIENT; - -using i18n::addressinput::MISSING_REQUIRED_FIELD; -using i18n::addressinput::UNKNOWN_VALUE; -using i18n::addressinput::INVALID_FORMAT; -using i18n::addressinput::MISMATCHING_VALUE; -using i18n::addressinput::USES_P_O_BOX; - // Tests for Localization object. class LocalizationTest : public testing::TestWithParam { public: @@ -100,24 +77,7 @@ INSTANTIATE_TEST_SUITE_P( IDS_LIBADDRESSINPUT_PARISH, IDS_LIBADDRESSINPUT_PREFECTURE, IDS_LIBADDRESSINPUT_PROVINCE, IDS_LIBADDRESSINPUT_STATE, IDS_LIBADDRESSINPUT_ORGANIZATION_LABEL, - IDS_LIBADDRESSINPUT_RECIPIENT_LABEL, - IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD, - IDS_LIBADDRESSINPUT_MISSING_REQUIRED_POSTAL_CODE_EXAMPLE_AND_URL, - IDS_LIBADDRESSINPUT_MISSING_REQUIRED_POSTAL_CODE_EXAMPLE, - IDS_LIBADDRESSINPUT_MISSING_REQUIRED_ZIP_CODE_EXAMPLE_AND_URL, - IDS_LIBADDRESSINPUT_MISSING_REQUIRED_ZIP_CODE_EXAMPLE, - IDS_LIBADDRESSINPUT_UNKNOWN_VALUE, - IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_POSTAL_CODE_EXAMPLE_AND_URL, - IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_POSTAL_CODE_EXAMPLE, - IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_POSTAL_CODE, - IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_ZIP_CODE_EXAMPLE_AND_URL, - IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_ZIP_CODE_EXAMPLE, - IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_ZIP, - IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_POSTAL_CODE_URL, - IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_POSTAL_CODE, - IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_ZIP_URL, - IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_ZIP, - IDS_LIBADDRESSINPUT_PO_BOX_FORBIDDEN_VALUE)); + IDS_LIBADDRESSINPUT_RECIPIENT_LABEL)); // Verifies that an invalid message identifier results in an empty string in the // default configuration. @@ -125,353 +85,4 @@ TEST_F(LocalizationTest, InvalidMessageIsEmptyString) { EXPECT_TRUE(localization_.GetString(INVALID_MESSAGE_ID).empty()); } -TEST(LocalizationGetErrorMessageTest, MissingRequiredPostalCode) { - Localization localization; - const AddressData address{.region_code = "CH"}; - EXPECT_EQ("You must provide a postal code, for example 2544." - " Don't know your postal code? Find it out" - " " - "here.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISSING_REQUIRED_FIELD, true, true)); - 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.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISSING_REQUIRED_FIELD, false, false)); - EXPECT_EQ("You can't leave this empty.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISSING_REQUIRED_FIELD, false, true)); -} - -TEST(LocalizationGetErrorMessageTest, MissingRequiredZipCode) { - Localization localization; - const AddressData address{.region_code = "US"}; - EXPECT_EQ("You must provide a ZIP code, for example 95014." - " Don't know your ZIP code? Find it out" - " here.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISSING_REQUIRED_FIELD, true, true)); - 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.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISSING_REQUIRED_FIELD, false, false)); - EXPECT_EQ("You can't leave this empty.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISSING_REQUIRED_FIELD, false, true)); -} - -TEST(LocalizationGetErrorMessageTest, MissingRequiredOtherFields) { - Localization localization; - const AddressData address{.region_code = "US"}; - const std::vector other_fields{ - COUNTRY, - ADMIN_AREA, - LOCALITY, - DEPENDENT_LOCALITY, - SORTING_CODE, - STREET_ADDRESS, - ORGANIZATION, - RECIPIENT, - }; - for (AddressField field : other_fields) { - EXPECT_EQ("You can't leave this empty.", - localization.GetErrorMessage( - address, field, MISSING_REQUIRED_FIELD, true, true)); - EXPECT_EQ("You can't leave this empty.", - localization.GetErrorMessage( - address, field, MISSING_REQUIRED_FIELD, true, false)); - EXPECT_EQ("You can't leave this empty.", - localization.GetErrorMessage( - address, field, MISSING_REQUIRED_FIELD, false, false)); - EXPECT_EQ("You can't leave this empty.", - localization.GetErrorMessage( - address, field, MISSING_REQUIRED_FIELD, false, true)); - } -} - -TEST(LocalizationGetErrorMessageTest, UnknownValueOtherFields) { - Localization localization; - const AddressData address{ - .region_code = "US", - .address_line{ - "bad address line 1", - "bad address line 2", - }, - .administrative_area = "bad admin area", - .locality = "bad locality", - .dependent_locality = "bad dependent locality", - .sorting_code = "bad sorting code", - .organization = "bad organization", - .recipient = "bad recipient", - }; - EXPECT_EQ("US " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, COUNTRY, UNKNOWN_VALUE, true, true)); - EXPECT_EQ("US " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, COUNTRY, UNKNOWN_VALUE, true, false)); - EXPECT_EQ("US " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, COUNTRY, UNKNOWN_VALUE, false, false)); - EXPECT_EQ("US " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, COUNTRY, UNKNOWN_VALUE, false, true)); - EXPECT_EQ("bad admin area " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, ADMIN_AREA, UNKNOWN_VALUE, true, true)); - EXPECT_EQ("bad admin area " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, ADMIN_AREA, UNKNOWN_VALUE, true, false)); - EXPECT_EQ("bad admin area " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, ADMIN_AREA, UNKNOWN_VALUE, false, false)); - EXPECT_EQ("bad admin area " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, ADMIN_AREA, UNKNOWN_VALUE, false, true)); - EXPECT_EQ("bad locality " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, LOCALITY, UNKNOWN_VALUE, true, true)); - EXPECT_EQ("bad locality " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, LOCALITY, UNKNOWN_VALUE, true, false)); - EXPECT_EQ("bad locality " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, LOCALITY, UNKNOWN_VALUE, false, false)); - EXPECT_EQ("bad locality " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, LOCALITY, UNKNOWN_VALUE, false, true)); - EXPECT_EQ("bad dependent locality " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, DEPENDENT_LOCALITY, UNKNOWN_VALUE, true, true)); - EXPECT_EQ("bad dependent locality " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, DEPENDENT_LOCALITY, UNKNOWN_VALUE, true, false)); - EXPECT_EQ("bad dependent locality " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, DEPENDENT_LOCALITY, UNKNOWN_VALUE, false, false)); - EXPECT_EQ("bad dependent locality " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, DEPENDENT_LOCALITY, UNKNOWN_VALUE, false, true)); - EXPECT_EQ("bad sorting code " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, SORTING_CODE, UNKNOWN_VALUE, true, true)); - EXPECT_EQ("bad sorting code " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, SORTING_CODE, UNKNOWN_VALUE, true, false)); - EXPECT_EQ("bad sorting code " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, SORTING_CODE, UNKNOWN_VALUE, false, false)); - EXPECT_EQ("bad sorting code " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, SORTING_CODE, UNKNOWN_VALUE, false, true)); - EXPECT_EQ("bad address line 1 " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, STREET_ADDRESS, UNKNOWN_VALUE, true, true)); - EXPECT_EQ("bad address line 1 " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, STREET_ADDRESS, UNKNOWN_VALUE, true, false)); - EXPECT_EQ("bad address line 1 " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, STREET_ADDRESS, UNKNOWN_VALUE, false, false)); - EXPECT_EQ("bad address line 1 " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, STREET_ADDRESS, UNKNOWN_VALUE, false, true)); - EXPECT_EQ("bad organization " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, ORGANIZATION, UNKNOWN_VALUE, true, true)); - EXPECT_EQ("bad organization " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, ORGANIZATION, UNKNOWN_VALUE, true, false)); - EXPECT_EQ("bad organization " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, ORGANIZATION, UNKNOWN_VALUE, false, false)); - EXPECT_EQ("bad organization " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, ORGANIZATION, UNKNOWN_VALUE, false, true)); - EXPECT_EQ("bad recipient " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, RECIPIENT, UNKNOWN_VALUE, true, true)); - EXPECT_EQ("bad recipient " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, RECIPIENT, UNKNOWN_VALUE, true, false)); - EXPECT_EQ("bad recipient " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, RECIPIENT, UNKNOWN_VALUE, false, false)); - EXPECT_EQ("bad recipient " - "is not recognized as a known value for this field.", - localization.GetErrorMessage( - address, RECIPIENT, UNKNOWN_VALUE, false, true)); -} - -TEST(LocalizationGetErrorMessageTest, InvalidFormatPostalCode) { - Localization localization; - const AddressData address{.region_code = "CH"}; - EXPECT_EQ("This postal code format is not recognized. Example " - "of a valid postal code: 2544." - " Don't know your postal code? Find it out" - " " - "here.", - localization.GetErrorMessage(address, POSTAL_CODE, - INVALID_FORMAT, true, true)); - EXPECT_EQ("This postal code format is not recognized. Example " - "of a valid postal code: 2544.", - localization.GetErrorMessage(address, POSTAL_CODE, - INVALID_FORMAT, true, false)); - EXPECT_EQ("This postal code format is not recognized.", - localization.GetErrorMessage(address, POSTAL_CODE, - INVALID_FORMAT, false, false)); - EXPECT_EQ("This postal code format is not recognized.", - localization.GetErrorMessage(address, POSTAL_CODE, - INVALID_FORMAT, false, true)); -} - -TEST(LocalizationGetErrorMessageTest, InvalidFormatZipCode) { - Localization localization; - const AddressData address{.region_code = "US"}; - EXPECT_EQ("This ZIP code format is not recognized. Example of " - "a valid ZIP code: 95014." - " Don't know your ZIP code? Find it out" - " here.", - localization.GetErrorMessage(address, POSTAL_CODE, - INVALID_FORMAT, true, true)); - EXPECT_EQ("This ZIP code format is not recognized. Example of " - "a valid ZIP code: 95014.", - localization.GetErrorMessage(address, POSTAL_CODE, - INVALID_FORMAT, true, false)); - EXPECT_EQ("This ZIP code format is not recognized.", - localization.GetErrorMessage(address, POSTAL_CODE, - INVALID_FORMAT, false, false)); - EXPECT_EQ("This ZIP code format is not recognized.", - localization.GetErrorMessage(address, POSTAL_CODE, - INVALID_FORMAT, false, true)); -} - -TEST(LocalizationGetErrorMessageTest, MismatchingValuePostalCode) { - Localization localization; - const AddressData address{.region_code = "CH"}; - EXPECT_EQ("This postal code does not appear to match the rest " - "of this address." - " Don't know your postal code? Find it out" - " " - "here.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISMATCHING_VALUE, true, true)); - EXPECT_EQ("This postal code does not appear to match the rest " - "of this address.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISMATCHING_VALUE, true, false)); - EXPECT_EQ("This postal code does not appear to match the rest " - "of this address.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISMATCHING_VALUE, false, false)); - EXPECT_EQ("This postal code does not appear to match the rest " - "of this address." - " Don't know your postal code? Find it out" - " " - "here.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISMATCHING_VALUE, false, true)); -} - -TEST(LocalizationGetErrorMessageTest, MismatchingValueZipCode) { - Localization localization; - const AddressData address{.region_code = "US"}; - EXPECT_EQ("This ZIP code does not appear to match the rest of " - "this address." - " Don't know your ZIP code? Find it out" - " here.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISMATCHING_VALUE, true, true)); - EXPECT_EQ("This ZIP code does not appear to match the rest of " - "this address.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISMATCHING_VALUE, true, false)); - EXPECT_EQ("This ZIP code does not appear to match the rest of " - "this address.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISMATCHING_VALUE, false, false)); - EXPECT_EQ("This ZIP code does not appear to match the rest of " - "this address." - " Don't know your ZIP code? Find it out" - " here.", - localization.GetErrorMessage(address, POSTAL_CODE, - MISMATCHING_VALUE, false, true)); -} - -TEST(LocalizationGetErrorMessageTest, UsesPOBoxOtherFields) { - Localization localization; - const AddressData address{.region_code = "US"}; - const std::vector other_fields{ - COUNTRY, - ADMIN_AREA, - LOCALITY, - DEPENDENT_LOCALITY, - SORTING_CODE, - STREET_ADDRESS, - ORGANIZATION, - RECIPIENT, - }; - for (AddressField field : other_fields) { - EXPECT_EQ("This address line appears to contain a post " - "office box. Please use a street" - " or building address.", - localization.GetErrorMessage( - address, field, USES_P_O_BOX, true, true)); - EXPECT_EQ("This address line appears to contain a post " - "office box. Please use a street" - " or building address.", - localization.GetErrorMessage( - address, field, USES_P_O_BOX, true, false)); - EXPECT_EQ("This address line appears to contain a post " - "office box. Please use a street" - " or building address.", - localization.GetErrorMessage( - address, field, USES_P_O_BOX, false, false)); - EXPECT_EQ("This address line appears to contain a post " - "office box. Please use a street" - " or building address.", - localization.GetErrorMessage( - address, field, USES_P_O_BOX, false, true)); - } -} - } // namespace