10#include "gmock/gmock.h"
11#include "gtest/gtest.h"
13using ::testing::StartsWith;
21TEST_F(ExpandDeducedTypeTest, Test) {
29 inline namespace inl_ns {
40 EXPECT_EQ(apply(
"[[auto]] i = 0;"),
"int i = 0;");
41 EXPECT_EQ(apply(
"au^to i = 0;"),
"int i = 0;");
43 EXPECT_EQ(apply(
"^auto C = ns::Class::Nested();"),
44 "ns::Class::Nested C = ns::Class::Nested();");
46 EXPECT_EQ(apply(
"namespace ns { void f() { ^auto C = Class(); } }"),
47 "namespace ns { void f() { Class C = Class(); } }");
49 EXPECT_THAT(apply(
"au^to x = doesnt_exist(); // error-ok"),
50 StartsWith(
"fail: Could not deduce type for 'auto' type"));
52 EXPECT_THAT(apply(
"au^to x = &ns::Func;"),
53 StartsWith(
"fail: Could not expand type"));
55 EXPECT_THAT(apply(
"au^to &x = ns::Func;"),
56 StartsWith(
"fail: Could not expand type"));
60 EXPECT_EQ(apply(
"au^to x = inl_ns::Visible();"),
61 "inl_ns::Visible x = inl_ns::Visible();");
63 EXPECT_EQ(apply(
"namespace x { void y() { struct S{}; ^auto z = S(); } }"),
64 "namespace x { void y() { struct S{}; S z = S(); } }");
66 EXPECT_EQ(apply(R
"cpp(au^to x = "test";)cpp"),
67 R"cpp(const char * x = "test";)cpp");
69 EXPECT_THAT(apply(R
"cpp(au^to s = &"foobar";)cpp"),
70 StartsWith("fail: Could not expand type"));
72 EXPECT_EQ(apply(
"ns::Class * foo() { au^to c = foo(); }"),
73 "ns::Class * foo() { ns::Class * c = foo(); }");
75 apply(
"void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
76 "void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");
78 EXPECT_EQ(apply(
"dec^ltype(auto) x = 10;"),
"int x = 10;");
79 EXPECT_EQ(apply(
"decltype(au^to) x = 10;"),
"int x = 10;");
81 EXPECT_THAT(apply(R
"cpp(decl^type(auto) s = "foobar"; // error-ok)cpp"),
82 StartsWith("fail: Could not expand type"));
84 EXPECT_THAT(apply(
"int arr[10]; decl^type(auto) foobar = arr; // error-ok"),
85 StartsWith(
"fail: Could not expand type"));
87 EXPECT_THAT(apply(R
"cpp(decl^type(auto) s = &"foobar";)cpp"),
88 StartsWith("fail: Could not expand type"));
93 EXPECT_THAT(apply(
"template <typename T> void x() { ^auto y = T::z(); }"),
94 StartsWith(
"fail: Could not deduce type for 'auto' type"));
97 EXPECT_EQ(apply(
"decl^type(0) i;"),
"int i;");
99 EXPECT_THAT(apply(
"void f(); decl^type(f) g;"),
100 StartsWith(
"fail: Could not expand type"));
102 EXPECT_EQ(apply(
"decl^type(0) f();"),
"int f();");
104 EXPECT_EQ(apply(
"auto f() -> decl^type(0) { return 0; }"),
105 "auto f() -> int { return 0; }");
107 EXPECT_EQ(apply(
"void f(decl^type(0));"),
"void f(int);");
109 EXPECT_EQ(apply(
"template <decl^type(0)> struct Foobar {};"),
110 "template <int> struct Foobar {};");
112 EXPECT_EQ(apply(
"template <class = decl^type(0)> class Foo {};"),
113 "template <class = int> class Foo {};");
115 EXPECT_EQ(apply(
"template <class> class Bar {}; Bar<decl^type(0)> b;"),
116 "template <class> class Bar {}; Bar<int> b;");
118 EXPECT_THAT(apply(
"template <class T> struct Foobar { decl^type(T{}) t; };"),
119 StartsWith(
"fail: Could not expand a dependent type"));
121 EXPECT_THAT(apply(R
"cpp(decl^type("foobar") s; // error-ok)cpp"),
122 StartsWith("fail: Could not expand type"));
124 EXPECT_THAT(apply(
"int arr[10]; decl^type(arr) foobar;"),
125 StartsWith(
"fail: Could not expand type"));
127 EXPECT_THAT(apply(R
"cpp(decl^type(&"foobar") s;)cpp"),
128 StartsWith("fail: Could not expand type"));
130 ExtraArgs.push_back(
"-std=c++20");
133 EXPECT_THAT(apply(
"auto X = [](^auto){};"),
134 StartsWith(
"fail: Could not deduce"));
135 EXPECT_EQ(apply(
"auto X = [](^auto){return 0;}; int Y = X(42);"),
136 "auto X = [](int){return 0;}; int Y = X(42);");
137 EXPECT_THAT(apply(
"auto X = [](^auto){return 0;}; int Y = X(42) + X('c');"),
138 StartsWith(
"fail: Could not deduce"));
141 "auto X = [](C ^auto *){return 0;};");
#define TWEAK_TEST(TweakID)
#define EXPECT_AVAILABLE(MarkedCode)
#define EXPECT_UNAVAILABLE(MarkedCode)
TEST_F(BackgroundIndexTest, NoCrashOnErrorFile)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//