-
Notifications
You must be signed in to change notification settings - Fork 199
/
kythe_facts_test.cc
172 lines (156 loc) · 4.26 KB
/
kythe_facts_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2017-2020 The Verible Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "verilog/tools/kythe/kythe_facts.h"
#include <sstream>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace verilog {
namespace kythe {
namespace {
using ::testing::ElementsAre;
TEST(SignatureTest, EmptyToString) {
const Signature s;
EXPECT_EQ(s.ToString(), "");
EXPECT_THAT(s.Names(), ElementsAre(""));
}
TEST(SignatureTest, ToString) {
const Signature s("foobar");
EXPECT_EQ(s.ToString(), "foobar#");
EXPECT_THAT(s.Names(), ElementsAre("foobar"));
}
TEST(SignatureTest, WithParentToString) {
const Signature s1("foobar");
const Signature s2(s1, "baz");
EXPECT_EQ(s2.ToString(), "foobar#baz#");
EXPECT_THAT(s2.Names(), ElementsAre("foobar", "baz"));
}
TEST(SignatureTest, Equality) {
const Signature s1("aaa");
const Signature s2("bbb");
EXPECT_EQ(s1, s1);
EXPECT_EQ(s2, s2);
EXPECT_NE(s1, s2);
EXPECT_NE(s2, s1);
{
const Signature s3(s2, "ccc");
EXPECT_NE(s1, s3);
EXPECT_NE(s3, s1);
EXPECT_NE(s2, s3);
EXPECT_NE(s3, s2);
}
}
TEST(VNameTest, DefaultCtor) {
const VName vname;
std::ostringstream stream;
stream << vname;
EXPECT_EQ(stream.str(),
R"({
"signature": "",
"path": "",
"language": "verilog",
"root": "",
"corpus": ""
})");
}
TEST(VNameTest, FilledCtor) {
const Signature s("s");
const VName vname{.path = "/path/to/nowhere.lol",
.root = "root",
.signature = s,
.corpus = "http://corpus.code/corpus/"};
{
std::ostringstream stream;
stream << vname;
EXPECT_EQ(stream.str(), R"({
"signature": "s#",
"path": "/path/to/nowhere.lol",
"language": "verilog",
"root": "root",
"corpus": "http://corpus.code/corpus/"
})");
EXPECT_EQ(vname, vname);
}
{
const VName vname2;
EXPECT_FALSE(vname == vname2);
EXPECT_FALSE(vname2 == vname);
}
}
TEST(FactTest, FormatJSON) {
const Signature s("sss");
const VName v{.path = "/path", .root = "", .signature = s, .corpus = ""};
const Fact fact(v, "FactName", "FactValue");
std::ostringstream stream;
stream << fact;
EXPECT_EQ(stream.str(), R"({
"source": {
"signature": "sss#",
"path": "/path",
"language": "verilog",
"root": "",
"corpus": ""
},
"fact_name": "FactName",
"fact_value": "FactValue"
})");
}
TEST(FactTest, Equality) {
const Signature s("sss");
const VName v{.path = "/path", .root = "", .signature = s, .corpus = ""};
const Fact fact1(v, "FactName", "FactValueA");
const Fact fact2(v, "FactName", "FactValueB");
EXPECT_EQ(fact1, fact1);
EXPECT_EQ(fact2, fact2);
EXPECT_NE(fact1, fact2);
EXPECT_NE(fact2, fact1);
}
TEST(EdgeTest, FormatJSON) {
const Signature s1("sss"), s2("ttt");
const VName v1{.path = "/path", .root = "", .signature = s1, .corpus = ""};
const VName v2{.path = "/path", .root = "", .signature = s2, .corpus = ""};
const Edge edge(v1, "EdgeName", v2);
std::ostringstream stream;
stream << edge;
EXPECT_EQ(stream.str(), R"({
"source": {
"signature": "sss#",
"path": "/path",
"language": "verilog",
"root": "",
"corpus": ""
},
"edge_kind": "EdgeName",
"target": {
"signature": "ttt#",
"path": "/path",
"language": "verilog",
"root": "",
"corpus": ""
},
"fact_name": "/"
})");
}
TEST(EdgeTest, Equality) {
const Signature s1("sss"), s2("ttt");
const VName v1{.path = "/path", .root = "", .signature = s1, .corpus = ""};
const VName v2{.path = "/path", .root = "", .signature = s2, .corpus = ""};
const Edge edge1(v1, "EdgeName", v2), edge2(v2, "Reverse", v1);
EXPECT_EQ(edge1, edge1);
EXPECT_EQ(edge2, edge2);
EXPECT_NE(edge1, edge2);
EXPECT_NE(edge2, edge1);
}
} // namespace
} // namespace kythe
} // namespace verilog