11#include "gmock/gmock.h"
12#include "gtest/gtest.h"
18TEST(FileDistanceTests, Distance) {
19 FileDistanceOptions Opts;
25 {{
"tools/clang/lib/Format/FormatToken.cpp", SourceParams()},
26 {
"tools/clang/include/clang/Format/FormatToken.h", SourceParams()},
27 {
"include/llvm/ADT/StringRef.h", CostTwo}},
31 EXPECT_EQ(D.distance(
"tools/clang/lib/Format/FormatToken.cpp"), 0u);
32 EXPECT_EQ(D.distance(
"include/llvm/ADT/StringRef.h"), 2u);
34 EXPECT_EQ(D.distance(
"tools/clang/lib/Format/"), 5u);
36 EXPECT_EQ(D.distance(
"tools/clang/lib/Format/FormatToken.cpp/Oops"), 3u);
38 EXPECT_EQ(D.distance(
"/"), 22u);
40 EXPECT_EQ(D.distance(
"tools/clang/lib/Format/AnotherFile.cpp"), 8u);
42 EXPECT_EQ(D.distance(
"include/llvm/Support/Allocator.h"), 18u);
44 EXPECT_EQ(D.distance(
"include/llvm-c/Core.h"), 23u);
47TEST(FileDistanceTests, BadSource) {
49 FileDistanceOptions Opts;
52 SourceParams CostLots;
54 FileDistance D({{
"a", SourceParams()}, {
"b/b/b", CostLots}}, Opts);
55 EXPECT_EQ(D.distance(
"b"), 8u);
56 EXPECT_EQ(D.distance(
"b/b/b"), 14u);
57 EXPECT_EQ(D.distance(
"b/b/b/c"), 17u);
63TEST(FileDistanceTests, URI) {
64 FileDistanceOptions Opts;
67 SourceParams CostLots;
70 URIDistance D({{
testPath(
"foo"), CostLots},
71 {
"/not/a/testpath", SourceParams()},
72 {
"C:\\not\\a\\testpath", SourceParams()}},
75 EXPECT_EQ(D.distance(
"file:///C%3a/not/a/testpath/either"), 3u);
77 EXPECT_EQ(D.distance(
"file:///not/a/testpath/either"), 3u);
79 EXPECT_EQ(D.distance(
"unittest:///foo"), 1000u);
80 EXPECT_EQ(D.distance(
"unittest:///bar"), 1008u);
83TEST(FileDistance, LimitUpTraversals) {
84 FileDistanceOptions Opts;
85 Opts.UpCost = Opts.DownCost = 1;
86 SourceParams CheapButLimited, CostLots;
87 CheapButLimited.MaxUpTraversals = 1;
90 FileDistance D({{
"/", CostLots}, {
"/a/b/c", CheapButLimited}}, Opts);
91 EXPECT_EQ(D.distance(
"/a"), 101u);
92 EXPECT_EQ(D.distance(
"/a/z"), 102u);
93 EXPECT_EQ(D.distance(
"/a/b"), 1u);
94 EXPECT_EQ(D.distance(
"/a/b/z"), 2u);
97TEST(FileDistance, DisallowDownTraversalsFromRoot) {
98 FileDistanceOptions Opts;
99 Opts.UpCost = Opts.DownCost = 1;
100 Opts.AllowDownTraversalFromRoot =
false;
101 SourceParams CostLots;
104 FileDistance D({{
"/", SourceParams()}, {
"/a/b/c", CostLots}}, Opts);
105 EXPECT_EQ(D.distance(
"/"), 0u);
106 EXPECT_EQ(D.distance(
"/a"), 102u);
107 EXPECT_EQ(D.distance(
"/a/b"), 101u);
111TEST(ScopeDistance, Smoke) {
112 ScopeDistance D({
"x::y::z",
"x::",
"",
"a::"});
113 EXPECT_EQ(D.distance(
"x::y::z::"), 0u);
114 EXPECT_GT(D.distance(
"x::y::"), D.distance(
"x::y::z::"));
115 EXPECT_GT(D.distance(
"x::"), D.distance(
"x::y::"));
116 EXPECT_GT(D.distance(
"x::y::z::down::"), D.distance(
"x::y::"));
117 EXPECT_GT(D.distance(
""), D.distance(
"a::"));
118 EXPECT_GT(D.distance(
"x::"), D.distance(
"a::"));
static constexpr unsigned Unreachable
std::string testPath(PathRef File, llvm::sys::path::Style Style)
TEST(BackgroundQueueTest, Priority)
volatile int UnittestSchemeAnchorSource
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//