Skip to content

Commit eaed532

Browse files
cleanup: Tweak formatting for relationships (#129)
1 parent 591e819 commit eaed532

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

test/Snapshot.cc

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "absl/container/flat_hash_map.h"
1010
#include "absl/strings/match.h"
11+
#include "absl/strings/str_join.h"
1112
#include "absl/strings/str_replace.h"
1213
#include "absl/strings/str_split.h"
1314
#include "doctest/doctest.h"
@@ -209,27 +210,20 @@ void formatSnapshot(const scip::Document &document,
209210
const scip::Relationship &r2) -> bool {
210211
return r1.symbol() < r2.symbol();
211212
});
212-
if (!relationships.empty()) {
213+
for (size_t i = 0; i < relationships.size(); ++i) {
213214
out << lineStart << "relation ";
214-
for (size_t i = 0; i < relationships.size(); ++i) {
215-
auto &rel = relationships[i];
216-
if (rel.is_implementation()) {
217-
out << "implementation=";
218-
}
219-
if (rel.is_reference()) {
220-
out << "reference=";
221-
}
222-
if (rel.is_type_definition()) {
223-
out << "type_definition=";
224-
}
225-
if (rel.is_definition()) {
226-
out << "definition=";
227-
}
228-
out << formatSymbol(rel.symbol());
229-
if (i != relationships.size() - 1) {
230-
out << ' ';
231-
}
232-
}
215+
auto &rel = relationships[i];
216+
std::vector<const char *> kinds{};
217+
#define ADD_KIND(kind_) \
218+
if (rel.is_##kind_()) { \
219+
kinds.push_back(#kind_); \
220+
}
221+
ADD_KIND(implementation)
222+
ADD_KIND(reference)
223+
ADD_KIND(type_definition)
224+
ADD_KIND(definition)
225+
out << absl::StrJoin(kinds, "+") << ' ';
226+
out << formatSymbol(rel.symbol());
233227
out << '\n';
234228
}
235229
}

test/index/types/types.snapshot.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170

171171
class Child: Parent {};
172172
// ^^^^^ definition [..] Child#
173-
// relation implementation=[..] Parent#
173+
// relation implementation [..] Parent#
174174
// ^^^^^^ reference [..] Parent#
175175

176176
template <class CRTPChild>
@@ -181,7 +181,7 @@
181181

182182
class CRTPChild: CRTPBase<CRTPChild> {
183183
// ^^^^^^^^^ definition [..] CRTPChild#
184-
// relation implementation=[..] CRTPBase#
184+
// relation implementation [..] CRTPBase#
185185
// ^^^^^^^^^ reference [..] CRTPChild#
186186
void doStuff() { }
187187
};
@@ -190,14 +190,15 @@
190190
// ^^^^^^^^^^^ definition [..] DiamondBase#
191191
class Derived1 : public virtual DiamondBase {};
192192
// ^^^^^^^^ definition [..] Derived1#
193-
// relation implementation=[..] DiamondBase#
193+
// relation implementation [..] DiamondBase#
194194
// ^^^^^^^^^^^ reference [..] DiamondBase#
195195
class Derived2 : public virtual DiamondBase {};
196196
// ^^^^^^^^ definition [..] Derived2#
197-
// relation implementation=[..] DiamondBase#
197+
// relation implementation [..] DiamondBase#
198198
// ^^^^^^^^^^^ reference [..] DiamondBase#
199199
class Join : public Derived1, public Derived2 {};
200200
// ^^^^ definition [..] Join#
201-
// relation implementation=[..] Derived1# implementation=[..] Derived2#
201+
// relation implementation [..] Derived1#
202+
// relation implementation [..] Derived2#
202203
// ^^^^^^^^ reference [..] Derived1#
203204
// ^^^^^^^^ reference [..] Derived2#

0 commit comments

Comments
 (0)