Path: blob/main/libshaderc_util/src/format_test.cc
1560 views
// Copyright 2015 The Shaderc Authors. All rights reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314#include "libshaderc_util/format.h"1516#include <gmock/gmock.h>17#include <map>18#include <string>19#include <unordered_map>2021namespace {2223using testing::AllOf;24using testing::HasSubstr;25using testing::IsEmpty;2627class FormatMap : public testing::Test {28public:29FormatMap()30: map1({{"one", 1}}),31umap1({map1.begin(), map1.end()}),32map8({{1, "one"},33{2, "two"},34{3, "three"},35{4, "four"},36{5, "five"},37{6, "six"},38{7, "seven"},39{8, "eight"}}),40umap8({map8.begin(), map8.end()}),41mmap({{1, 100}, {1, 200}, {2, 100}, {2, 200}}),42ummap({mmap.begin(), mmap.end()}) {}4344protected:45std::map<int, int> empty_map;46std::unordered_map<int, int> empty_umap;47std::map<std::string, int> map1;48std::unordered_map<std::string, int> umap1;49std::map<int, std::string> map8;50std::unordered_map<int, std::string> umap8;51std::multimap<int, int> mmap;52std::unordered_multimap<int, int> ummap;53};5455TEST_F(FormatMap, EmptyMap) {56EXPECT_THAT(shaderc_util::format(empty_map, "pre", "in", "post"), IsEmpty());57EXPECT_THAT(shaderc_util::format(empty_umap, "pre", "in", "post"), IsEmpty());58}5960TEST_F(FormatMap, SingleEntry) {61EXPECT_EQ("PREoneIN1POST", shaderc_util::format(map1, "PRE", "IN", "POST"));62EXPECT_EQ("PREoneIN1POST", shaderc_util::format(umap1, "PRE", "IN", "POST"));63}6465TEST_F(FormatMap, EmptyPrefix) {66EXPECT_EQ("oneIN1POST", shaderc_util::format(map1, "", "IN", "POST"));67EXPECT_EQ("oneIN1POST", shaderc_util::format(umap1, "", "IN", "POST"));68}6970TEST_F(FormatMap, EmptyInfix) {71EXPECT_EQ("PREone1POST", shaderc_util::format(map1, "PRE", "", "POST"));72EXPECT_EQ("PREone1POST", shaderc_util::format(umap1, "PRE", "", "POST"));73}7475TEST_F(FormatMap, EmptyPostfix) {76EXPECT_EQ("PREoneIN1", shaderc_util::format(map1, "PRE", "IN", ""));77EXPECT_EQ("PREoneIN1", shaderc_util::format(umap1, "PRE", "IN", ""));78}7980TEST_F(FormatMap, LargerMap) {81const std::string result = shaderc_util::format(map8, "", "", "\n"),82uresult = shaderc_util::format(umap8, "", "", "\n");83auto has_all =84AllOf(HasSubstr("1one\n"), HasSubstr("2two\n"), HasSubstr("3three\n"),85HasSubstr("4four\n"), HasSubstr("5five\n"), HasSubstr("6six\n"),86HasSubstr("7seven\n"), HasSubstr("8eight\n"));87EXPECT_THAT(result, has_all);88EXPECT_EQ(48u, result.size());89EXPECT_THAT(uresult, has_all);90EXPECT_EQ(48u, uresult.size());91}9293TEST_F(FormatMap, Multimap) {94const std::string result = shaderc_util::format(mmap, " ", "&", ""),95uresult = shaderc_util::format(ummap, " ", "&", "");96auto has_all = AllOf(HasSubstr(" 1&100"), HasSubstr(" 1&200"),97HasSubstr(" 2&100"), HasSubstr(" 2&200"));98EXPECT_THAT(result, has_all);99EXPECT_EQ(4 * 6u, result.size());100EXPECT_THAT(uresult, has_all);101EXPECT_EQ(4 * 6u, uresult.size());102}103104} // anonymous namespace105106107