mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 18:00:26 +00:00
Try to make index tests more platform independent
This commit is contained in:
parent
76c07f3cc6
commit
e421f86bfa
@ -463,7 +463,6 @@ struct IndexInclude {
|
|||||||
// Absolute path to the index.
|
// Absolute path to the index.
|
||||||
std::string resolved_path;
|
std::string resolved_path;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(IndexInclude, line, resolved_path);
|
|
||||||
|
|
||||||
struct IndexFile {
|
struct IndexFile {
|
||||||
IdCache id_cache;
|
IdCache id_cache;
|
||||||
|
@ -2,8 +2,18 @@
|
|||||||
|
|
||||||
#include "indexer.h"
|
#include "indexer.h"
|
||||||
|
|
||||||
|
#include <doctest/doctest.h>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
bool gTestOutputMode = false;
|
bool gTestOutputMode = false;
|
||||||
|
|
||||||
|
std::string GetBaseName(const std::string& path) {
|
||||||
|
size_t last_slash = path.find_last_of('/');
|
||||||
|
if (last_slash != std::string::npos && (last_slash + 1) < path.size())
|
||||||
|
return path.substr(last_slash + 1);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// int16_t
|
// int16_t
|
||||||
@ -64,6 +74,25 @@ void ReflectMember(Writer& visitor, const char* name, std::string& value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move this to indexer.cc
|
// TODO: Move this to indexer.cc
|
||||||
|
void Reflect(Reader& visitor, IndexInclude& value) {
|
||||||
|
REFLECT_MEMBER_START();
|
||||||
|
REFLECT_MEMBER(line);
|
||||||
|
REFLECT_MEMBER(resolved_path);
|
||||||
|
REFLECT_MEMBER_END();
|
||||||
|
}
|
||||||
|
void Reflect(Writer& visitor, IndexInclude& value) {
|
||||||
|
REFLECT_MEMBER_START();
|
||||||
|
REFLECT_MEMBER(line);
|
||||||
|
if (gTestOutputMode) {
|
||||||
|
std::string basename = GetBaseName(value.resolved_path);
|
||||||
|
if (!StartsWith(value.resolved_path, "&"))
|
||||||
|
basename = "&" + basename;
|
||||||
|
REFLECT_MEMBER2("resolved_path", basename);
|
||||||
|
} else {
|
||||||
|
REFLECT_MEMBER(resolved_path);
|
||||||
|
}
|
||||||
|
REFLECT_MEMBER_END();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename TVisitor>
|
template <typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, IndexType& value) {
|
void Reflect(TVisitor& visitor, IndexType& value) {
|
||||||
@ -144,7 +173,8 @@ void Reflect(TVisitor& visitor, IndexFile& value) {
|
|||||||
REFLECT_MEMBER(args);
|
REFLECT_MEMBER(args);
|
||||||
}
|
}
|
||||||
REFLECT_MEMBER(includes);
|
REFLECT_MEMBER(includes);
|
||||||
REFLECT_MEMBER(dependencies);
|
if (!gTestOutputMode)
|
||||||
|
REFLECT_MEMBER(dependencies);
|
||||||
REFLECT_MEMBER(skipped_by_preprocessor);
|
REFLECT_MEMBER(skipped_by_preprocessor);
|
||||||
REFLECT_MEMBER(types);
|
REFLECT_MEMBER(types);
|
||||||
REFLECT_MEMBER(funcs);
|
REFLECT_MEMBER(funcs);
|
||||||
@ -208,3 +238,15 @@ std::unique_ptr<IndexFile> Deserialize(std::string path,
|
|||||||
void SetTestOutputMode() {
|
void SetTestOutputMode() {
|
||||||
gTestOutputMode = true;
|
gTestOutputMode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_SUITE("Serializer utils") {
|
||||||
|
TEST_CASE("GetBaseName") {
|
||||||
|
REQUIRE(GetBaseName("foo.cc") == "foo.cc");
|
||||||
|
REQUIRE(GetBaseName("foo/foo.cc") == "foo.cc");
|
||||||
|
REQUIRE(GetBaseName("/foo.cc") == "foo.cc");
|
||||||
|
REQUIRE(GetBaseName("///foo.cc") == "foo.cc");
|
||||||
|
REQUIRE(GetBaseName("bar/") == "bar/");
|
||||||
|
REQUIRE(GetBaseName("foobar/bar/") ==
|
||||||
|
"foobar/bar/"); // TODO: Should be bar, but good enough.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user