1 // Copyright (C) 2014 Google Inc.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include "post_box_matchers.h"
20 #include <gtest/gtest.h>
25 namespace addressinput {
27 } // namespace addressinput
32 using i18n::addressinput::PostBoxMatchers;
33 using i18n::addressinput::RE2ptr;
34 using i18n::addressinput::Rule;
36 TEST(PostBoxMatchersTest, AlwaysGetMatcherForLanguageUnd) {
38 std::vector<const RE2ptr*> matchers = PostBoxMatchers::GetMatchers(rule);
39 EXPECT_EQ(1, matchers.size());
40 EXPECT_TRUE(matchers[0] != NULL);
43 TEST(PostBoxMatchersTest, NoMatcherForInvalidLanguage) {
45 ASSERT_TRUE(rule.ParseSerializedRule("{\"languages\":\"xx\"}"));
46 std::vector<const RE2ptr*> matchers = PostBoxMatchers::GetMatchers(rule);
47 EXPECT_EQ(1, matchers.size());
48 EXPECT_TRUE(matchers[0] != NULL);
51 TEST(PostBoxMatchersTest, HasMatcherForValidLanguage) {
53 ASSERT_TRUE(rule.ParseSerializedRule("{\"languages\":\"sv\"}"));
54 std::vector<const RE2ptr*> matchers = PostBoxMatchers::GetMatchers(rule);
55 EXPECT_EQ(2, matchers.size());
56 EXPECT_TRUE(matchers[0] != NULL);
57 EXPECT_TRUE(matchers[1] != NULL);
60 TEST(PostBoxMatchersTest, MixValidAndInvalidLanguage) {
62 ASSERT_TRUE(rule.ParseSerializedRule("{\"languages\":\"xx~sv\"}"));
63 std::vector<const RE2ptr*> matchers = PostBoxMatchers::GetMatchers(rule);
64 EXPECT_EQ(2, matchers.size());
65 EXPECT_TRUE(matchers[0] != NULL);
66 EXPECT_TRUE(matchers[1] != NULL);
69 TEST(PostBoxMatchersTest, UseBaseLanguageForMatching) {
71 ASSERT_TRUE(rule.ParseSerializedRule("{\"languages\":\"sv-SE\"}"));
72 std::vector<const RE2ptr*> matchers = PostBoxMatchers::GetMatchers(rule);
73 EXPECT_EQ(2, matchers.size());
74 EXPECT_TRUE(matchers[0] != NULL);
75 EXPECT_TRUE(matchers[1] != NULL);
78 TEST(PostBoxMatchersTest, LenientLanguageTagParsing) {
80 ASSERT_TRUE(rule.ParseSerializedRule("{\"languages\":\"SV_SE\"}"));
81 std::vector<const RE2ptr*> matchers = PostBoxMatchers::GetMatchers(rule);
82 EXPECT_EQ(2, matchers.size());
83 EXPECT_TRUE(matchers[0] != NULL);
84 EXPECT_TRUE(matchers[1] != NULL);