1// Copyright (C) 2014 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 "format_element.h" 16 17#include <libaddressinput/address_field.h> 18 19#include <sstream> 20 21#include <gtest/gtest.h> 22 23namespace { 24 25using i18n::addressinput::FormatElement; 26using i18n::addressinput::SORTING_CODE; 27 28TEST(FormatElementTest, StreamFunctionNewline) { 29 std::ostringstream oss; 30 oss << FormatElement(); 31 EXPECT_EQ("Newline", oss.str()); 32} 33 34TEST(FormatElementTest, StreamFunctionLiteral) { 35 std::ostringstream oss; 36 oss << FormatElement("Text"); 37 EXPECT_EQ("Literal: Text", oss.str()); 38} 39 40TEST(FormatElementTest, StreamFunctionField) { 41 std::ostringstream oss; 42 oss << FormatElement(SORTING_CODE); 43 EXPECT_EQ("Field: SORTING_CODE", oss.str()); 44} 45 46TEST(FormatElementTest, IsNewline) { 47 EXPECT_TRUE(FormatElement().IsNewline()); 48 EXPECT_FALSE(FormatElement(" ").IsNewline()); 49 EXPECT_FALSE(FormatElement(SORTING_CODE).IsNewline()); 50} 51 52TEST(FormatElementTest, IsField) { 53 EXPECT_FALSE(FormatElement().IsField()); 54 EXPECT_FALSE(FormatElement(" ").IsField()); 55 EXPECT_TRUE(FormatElement(SORTING_CODE).IsField()); 56} 57 58} // namespace 59