OLD | NEW |
(Empty) | |
| 1 // Copyright (C) 2013 Google Inc. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #include "address_field_util.h" |
| 16 |
| 17 #include <libaddressinput/address_field.h> |
| 18 |
| 19 #include <string> |
| 20 #include <vector> |
| 21 |
| 22 #include <gtest/gtest.h> |
| 23 |
| 24 namespace { |
| 25 |
| 26 using i18n::addressinput::AddressField; |
| 27 using i18n::addressinput::COUNTRY; |
| 28 using i18n::addressinput::LOCALITY; |
| 29 using i18n::addressinput::NEWLINE; |
| 30 using i18n::addressinput::ORGANIZATION; |
| 31 using i18n::addressinput::ParseAddressFieldsFormat; |
| 32 using i18n::addressinput::POSTAL_CODE; |
| 33 using i18n::addressinput::RECIPIENT; |
| 34 using i18n::addressinput::STREET_ADDRESS; |
| 35 |
| 36 TEST(AddressFieldUtilTest, ParseNewlineFormat) { |
| 37 std::vector<AddressField> actual; |
| 38 ParseAddressFieldsFormat("%O%n%N%n%A%nAX-%Z %C%nĂ…LAND", &actual); |
| 39 |
| 40 std::vector<AddressField> expected; |
| 41 expected.push_back(ORGANIZATION); |
| 42 expected.push_back(static_cast<AddressField>(NEWLINE)); |
| 43 expected.push_back(RECIPIENT); |
| 44 expected.push_back(static_cast<AddressField>(NEWLINE)); |
| 45 expected.push_back(STREET_ADDRESS); |
| 46 expected.push_back(static_cast<AddressField>(NEWLINE)); |
| 47 expected.push_back(POSTAL_CODE); |
| 48 expected.push_back(LOCALITY); |
| 49 expected.push_back(static_cast<AddressField>(NEWLINE)); |
| 50 |
| 51 EXPECT_EQ(expected, actual); |
| 52 } |
| 53 |
| 54 TEST(AddressFieldUtilTest, DoubleTokenPrefixIsIgnored) { |
| 55 std::vector<AddressField> actual; |
| 56 ParseAddressFieldsFormat("%%R", &actual); |
| 57 std::vector<AddressField> expected(1, COUNTRY); |
| 58 EXPECT_EQ(expected, actual); |
| 59 } |
| 60 |
| 61 TEST(AddressFieldUtilTest, PrefixWithoutTokenIsIgnored) { |
| 62 std::vector<AddressField> actual; |
| 63 ParseAddressFieldsFormat("%", &actual); |
| 64 EXPECT_TRUE(actual.empty()); |
| 65 } |
| 66 |
| 67 TEST(AddressFieldUtilTest, EmptyString) { |
| 68 std::vector<AddressField> fields; |
| 69 ParseAddressFieldsFormat(std::string(), &fields); |
| 70 EXPECT_TRUE(fields.empty()); |
| 71 } |
| 72 |
| 73 } // namespace |
OLD | NEW |