[clangd] Add test for structured-binding completion. NFC
authorSam McCall <sam.mccall@gmail.com>
Mon, 19 Oct 2020 14:45:32 +0000 (16:45 +0200)
committerSam McCall <sam.mccall@gmail.com>
Mon, 19 Oct 2020 14:45:51 +0000 (16:45 +0200)
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

index 510f358..15576ed 100644 (file)
@@ -2579,6 +2579,29 @@ TEST(CompletionTest, Lambda) {
   EXPECT_EQ(A.SnippetSuffix, "(${1:int a}, ${2:const double &b})");
 }
 
+TEST(CompletionTest, StructuredBinding) {
+  clangd::CodeCompleteOptions Opts = {};
+
+  auto Results = completions(R"cpp(
+    struct S {
+      using Float = float;
+      int x;
+      Float y;
+    };
+    void function() {
+      const auto &[xxx, yyy] = S{};
+      yyy^
+    }
+  )cpp",
+                             {}, Opts);
+
+  ASSERT_EQ(Results.Completions.size(), 1u);
+  const auto &A = Results.Completions.front();
+  EXPECT_EQ(A.Name, "yyy");
+  EXPECT_EQ(A.Kind, CompletionItemKind::Variable);
+  EXPECT_EQ(A.ReturnType, "const Float");
+}
+
 TEST(CompletionTest, ObjectiveCMethodNoArguments) {
   auto Results = completions(R"objc(
       @interface Foo