Index: third_party/libaddressinput/chromium/cpp/test/address_ui_test.cc |
diff --git a/third_party/libaddressinput/chromium/cpp/test/address_ui_test.cc b/third_party/libaddressinput/chromium/cpp/test/address_ui_test.cc |
index 8eb41309392e68da8d36f6e45a40514ea93a74b8..79da7f7c356551fef590e24fcd71df5365b34288 100644 |
--- a/third_party/libaddressinput/chromium/cpp/test/address_ui_test.cc |
+++ b/third_party/libaddressinput/chromium/cpp/test/address_ui_test.cc |
@@ -18,6 +18,7 @@ |
#include <libaddressinput/address_ui_component.h> |
#include <libaddressinput/localization.h> |
+#include <set> |
#include <string> |
#include <vector> |
@@ -29,31 +30,39 @@ using i18n::addressinput::AddressField; |
using i18n::addressinput::AddressUiComponent; |
using i18n::addressinput::BuildComponents; |
using i18n::addressinput::COUNTRY; |
+using i18n::addressinput::GetCompactAddressLinesSeparator; |
using i18n::addressinput::GetRegionCodes; |
using i18n::addressinput::Localization; |
using i18n::addressinput::RECIPIENT; |
-// Returns testing::AssertionSuccess if the |components| are valid. Uses |
-// |region_code| in test failure messages. |
+// Returns testing::AssertionSuccess if the |components| are valid. |
testing::AssertionResult ComponentsAreValid( |
const std::vector<AddressUiComponent>& components) { |
if (components.empty()) { |
return testing::AssertionFailure() << "no components"; |
} |
+ std::set<AddressField> fields; |
for (std::vector<AddressUiComponent>::const_iterator |
- component_it = components.begin(); |
- component_it != components.end(); ++component_it) { |
+ component_it = components.begin(); |
+ component_it != components.end(); |
+ ++component_it) { |
static const AddressField kMinAddressField = COUNTRY; |
static const AddressField kMaxAddressField = RECIPIENT; |
if (component_it->field < kMinAddressField || |
component_it->field > kMaxAddressField) { |
- return testing::AssertionFailure() << "unexpected field " |
+ return testing::AssertionFailure() << "unexpected input field " |
<< component_it->field; |
} |
+ if (fields.find(component_it->field) != fields.end()) { |
+ return testing::AssertionFailure() << "duplicate input field " |
+ << component_it->field; |
+ } |
+ fields.insert(component_it->field); |
+ |
if (component_it->name.empty()) { |
- return testing::AssertionFailure() << "empty field name for field " |
+ return testing::AssertionFailure() << "empty name for input field " |
<< component_it->field; |
} |
} |
@@ -89,4 +98,43 @@ TEST_F(AddressUiTest, InvalidRegionCodeReturnsEmptyVector) { |
EXPECT_TRUE(BuildComponents("INVALID-REGION-CODE", localization_).empty()); |
} |
+struct SeparatorData { |
+ SeparatorData(const std::string& language_code, |
+ const std::string& country_code, |
+ const std::string& compact_line_separator) |
+ : language_code(language_code), |
+ country_code(country_code), |
+ compact_line_separator(compact_line_separator) {} |
+ |
+ ~SeparatorData() {} |
+ |
+ std::string language_code; |
+ std::string country_code; |
+ std::string compact_line_separator; |
+}; |
+ |
+// Tests for compact line separator. |
+class CompactLineSeparatorTest |
+ : public testing::TestWithParam<SeparatorData> {}; |
+ |
+TEST_P(CompactLineSeparatorTest, BasicTest) { |
+ EXPECT_EQ(GetParam().compact_line_separator, |
+ GetCompactAddressLinesSeparator(GetParam().language_code, |
+ GetParam().country_code)); |
+} |
+ |
+INSTANTIATE_TEST_CASE_P( |
+ CompactLineSeparators, CompactLineSeparatorTest, |
+ testing::Values( |
+ SeparatorData("", "AD", ", "), |
+ SeparatorData("", "XX", ", "), |
+ SeparatorData("ja", "JP", ""), |
+ SeparatorData("zh", "HK", ""), |
+ SeparatorData("zh-hans", "CN", ""), |
+ SeparatorData("ar", "YE", "، "), |
+ SeparatorData("ko", "KR", " "), |
+ SeparatorData("th", "TH", " "), |
+ SeparatorData("en", "US", ", "))); |
+ |
+ |
} // namespace |