Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/libshaderc_util/src/format_test.cc
1560 views
1
// Copyright 2015 The Shaderc Authors. All rights reserved.
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 "libshaderc_util/format.h"
16
17
#include <gmock/gmock.h>
18
#include <map>
19
#include <string>
20
#include <unordered_map>
21
22
namespace {
23
24
using testing::AllOf;
25
using testing::HasSubstr;
26
using testing::IsEmpty;
27
28
class FormatMap : public testing::Test {
29
public:
30
FormatMap()
31
: map1({{"one", 1}}),
32
umap1({map1.begin(), map1.end()}),
33
map8({{1, "one"},
34
{2, "two"},
35
{3, "three"},
36
{4, "four"},
37
{5, "five"},
38
{6, "six"},
39
{7, "seven"},
40
{8, "eight"}}),
41
umap8({map8.begin(), map8.end()}),
42
mmap({{1, 100}, {1, 200}, {2, 100}, {2, 200}}),
43
ummap({mmap.begin(), mmap.end()}) {}
44
45
protected:
46
std::map<int, int> empty_map;
47
std::unordered_map<int, int> empty_umap;
48
std::map<std::string, int> map1;
49
std::unordered_map<std::string, int> umap1;
50
std::map<int, std::string> map8;
51
std::unordered_map<int, std::string> umap8;
52
std::multimap<int, int> mmap;
53
std::unordered_multimap<int, int> ummap;
54
};
55
56
TEST_F(FormatMap, EmptyMap) {
57
EXPECT_THAT(shaderc_util::format(empty_map, "pre", "in", "post"), IsEmpty());
58
EXPECT_THAT(shaderc_util::format(empty_umap, "pre", "in", "post"), IsEmpty());
59
}
60
61
TEST_F(FormatMap, SingleEntry) {
62
EXPECT_EQ("PREoneIN1POST", shaderc_util::format(map1, "PRE", "IN", "POST"));
63
EXPECT_EQ("PREoneIN1POST", shaderc_util::format(umap1, "PRE", "IN", "POST"));
64
}
65
66
TEST_F(FormatMap, EmptyPrefix) {
67
EXPECT_EQ("oneIN1POST", shaderc_util::format(map1, "", "IN", "POST"));
68
EXPECT_EQ("oneIN1POST", shaderc_util::format(umap1, "", "IN", "POST"));
69
}
70
71
TEST_F(FormatMap, EmptyInfix) {
72
EXPECT_EQ("PREone1POST", shaderc_util::format(map1, "PRE", "", "POST"));
73
EXPECT_EQ("PREone1POST", shaderc_util::format(umap1, "PRE", "", "POST"));
74
}
75
76
TEST_F(FormatMap, EmptyPostfix) {
77
EXPECT_EQ("PREoneIN1", shaderc_util::format(map1, "PRE", "IN", ""));
78
EXPECT_EQ("PREoneIN1", shaderc_util::format(umap1, "PRE", "IN", ""));
79
}
80
81
TEST_F(FormatMap, LargerMap) {
82
const std::string result = shaderc_util::format(map8, "", "", "\n"),
83
uresult = shaderc_util::format(umap8, "", "", "\n");
84
auto has_all =
85
AllOf(HasSubstr("1one\n"), HasSubstr("2two\n"), HasSubstr("3three\n"),
86
HasSubstr("4four\n"), HasSubstr("5five\n"), HasSubstr("6six\n"),
87
HasSubstr("7seven\n"), HasSubstr("8eight\n"));
88
EXPECT_THAT(result, has_all);
89
EXPECT_EQ(48u, result.size());
90
EXPECT_THAT(uresult, has_all);
91
EXPECT_EQ(48u, uresult.size());
92
}
93
94
TEST_F(FormatMap, Multimap) {
95
const std::string result = shaderc_util::format(mmap, " ", "&", ""),
96
uresult = shaderc_util::format(ummap, " ", "&", "");
97
auto has_all = AllOf(HasSubstr(" 1&100"), HasSubstr(" 1&200"),
98
HasSubstr(" 2&100"), HasSubstr(" 2&200"));
99
EXPECT_THAT(result, has_all);
100
EXPECT_EQ(4 * 6u, result.size());
101
EXPECT_THAT(uresult, has_all);
102
EXPECT_EQ(4 * 6u, uresult.size());
103
}
104
105
} // anonymous namespace
106
107