[clang-tools-extra] r334014 - [clangd] Test tweaks (consistency, shorter, doc). NFC

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 5 05:22:44 PDT 2018


Author: sammccall
Date: Tue Jun  5 05:22:43 2018
New Revision: 334014

URL: http://llvm.org/viewvc/llvm-project?rev=334014&view=rev
Log:
[clangd] Test tweaks (consistency, shorter, doc). NFC

Modified:
    clang-tools-extra/trunk/clangd/Quality.h
    clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
    clang-tools-extra/trunk/unittests/clangd/TestTU.h

Modified: clang-tools-extra/trunk/clangd/Quality.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.h?rev=334014&r1=334013&r2=334014&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Quality.h (original)
+++ clang-tools-extra/trunk/clangd/Quality.h Tue Jun  5 05:22:43 2018
@@ -61,11 +61,10 @@ llvm::raw_ostream &operator<<(llvm::raw_
 
 /// Attributes of a symbol-query pair that affect how much we like it.
 struct SymbolRelevanceSignals {
-  // 0-1 fuzzy-match score for unqualified name. Must be explicitly assigned.
+  /// 0-1 fuzzy-match score for unqualified name. Must be explicitly assigned.
   float NameMatch = 1;
   bool Forbidden = false; // Unavailable (e.g const) or inaccessible (private).
-  /// Proximity between the best declaration and the query location. [0-1] score
-  /// where 1 is closest
+  /// Proximity between best declaration and the query. [0-1], 1 is closest.
   float ProximityScore = 0;
 
   void merge(const CodeCompletionResult &SemaResult);

Modified: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp?rev=334014&r1=334013&r2=334014&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Tue Jun  5 05:22:43 2018
@@ -60,44 +60,34 @@ TEST(QualityTests, SymbolQualitySignalEx
 TEST(QualityTests, SymbolRelevanceSignalExtraction) {
   TestTU Test;
   Test.HeaderCode = R"cpp(
-    int test_func_in_header();
-    int test_func_in_header_and_cpp();
+    int header();
+    int header_main();
     )cpp";
   Test.Code = R"cpp(
-    int ::test_func_in_header_and_cpp() {
-    }
-    int test_func_in_cpp();
+    int ::header_main() {}
+    int main();
 
     [[deprecated]]
-    int test_deprecated() { return 0; }
+    int deprecated() { return 0; }
   )cpp";
   auto AST = Test.build();
 
-  SymbolRelevanceSignals Deprecated;
-  Deprecated.merge(CodeCompletionResult(&findDecl(AST, "test_deprecated"),
-                                        /*Priority=*/42, nullptr, false,
-                                        /*Accessible=*/false));
-  EXPECT_EQ(Deprecated.NameMatch, SymbolRelevanceSignals().NameMatch);
-  EXPECT_TRUE(Deprecated.Forbidden);
-
-  // Test proximity scores.
-  SymbolRelevanceSignals FuncInCpp;
-  FuncInCpp.merge(CodeCompletionResult(&findDecl(AST, "test_func_in_cpp"),
-                                       CCP_Declaration));
-  /// Decls in the current file should get a proximity score of 1.0.
-  EXPECT_FLOAT_EQ(FuncInCpp.ProximityScore, 1.0);
-
-  SymbolRelevanceSignals FuncInHeader;
-  FuncInHeader.merge(CodeCompletionResult(&findDecl(AST, "test_func_in_header"),
-                                          CCP_Declaration));
-  /// Decls outside current file currently don't get a proximity score boost.
-  EXPECT_FLOAT_EQ(FuncInHeader.ProximityScore, 0.0);
-
-  SymbolRelevanceSignals FuncInHeaderAndCpp;
-  FuncInHeaderAndCpp.merge(CodeCompletionResult(
-      &findDecl(AST, "test_func_in_header_and_cpp"), CCP_Declaration));
-  /// Decls in both header **and** the main file get the same boost.
-  EXPECT_FLOAT_EQ(FuncInHeaderAndCpp.ProximityScore, 1.0);
+  SymbolRelevanceSignals Relevance;
+  Relevance.merge(CodeCompletionResult(&findDecl(AST, "deprecated"),
+                                       /*Priority=*/42, nullptr, false,
+                                       /*Accessible=*/false));
+  EXPECT_EQ(Relevance.NameMatch, SymbolRelevanceSignals().NameMatch);
+  EXPECT_TRUE(Relevance.Forbidden);
+
+  Relevance = {};
+  Relevance.merge(CodeCompletionResult(&findDecl(AST, "main"), 42));
+  EXPECT_FLOAT_EQ(Relevance.ProximityScore, 1.0) << "Decl in current file";
+  Relevance = {};
+  Relevance.merge(CodeCompletionResult(&findDecl(AST, "header"), 42));
+  EXPECT_FLOAT_EQ(Relevance.ProximityScore, 0.0) << "Decl from header";
+  Relevance = {};
+  Relevance.merge(CodeCompletionResult(&findDecl(AST, "header_main"), 42));
+  EXPECT_FLOAT_EQ(Relevance.ProximityScore, 1.0) << "Current file and header";
 }
 
 // Do the signals move the scores in the direction we expect?
@@ -136,7 +126,7 @@ TEST(QualityTests, SymbolRelevanceSignal
 
   SymbolRelevanceSignals WithProximity;
   WithProximity.ProximityScore = 0.2f;
-  EXPECT_LT(Default.evaluate(), WithProximity.evaluate());
+  EXPECT_GT(WithProximity.evaluate(), Default.evaluate());
 }
 
 TEST(QualityTests, SortText) {

Modified: clang-tools-extra/trunk/unittests/clangd/TestTU.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TestTU.h?rev=334014&r1=334013&r2=334014&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/TestTU.h (original)
+++ clang-tools-extra/trunk/unittests/clangd/TestTU.h Tue Jun  5 05:22:43 2018
@@ -40,7 +40,7 @@ struct TestTU {
   std::string Code;
   std::string Filename = "TestTU.cpp";
 
-  // Define contents of a header to be included by TestTU.cpp.
+  // Define contents of a header which will be implicitly included by Code.
   std::string HeaderCode;
   std::string HeaderFilename = "TestTU.h";
 




More information about the cfe-commits mailing list