1 //===-- ObjCMemberwiseInitializerTests.cpp ----------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 #include "TweakTesting.h"
11 #include "gmock/gmock-matchers.h"
12 #include "gmock/gmock.h"
13 #include "gtest/gtest.h"
19 TWEAK_TEST(ObjCMemberwiseInitializer
);
21 TEST_F(ObjCMemberwiseInitializerTest
, TestAvailability
) {
22 FileName
= "TestTU.m";
24 // Ensure the action can't be triggered since arc is disabled.
25 EXPECT_UNAVAILABLE(R
"cpp(
30 ExtraArgs
.push_back("-fobjc-runtime=macosx");
31 ExtraArgs
.push_back("-fobjc-arc");
33 // Ensure the action can be initiated on the interface and implementation,
34 // but not on the forward declaration.
35 EXPECT_AVAILABLE(R
"cpp(
39 EXPECT_AVAILABLE(R
"cpp(
46 EXPECT_UNAVAILABLE("@class Fo^o;");
48 // Ensure that the action can be triggered on ivars and properties,
49 // including selecting both.
50 EXPECT_AVAILABLE(R
"cpp(
56 EXPECT_AVAILABLE(R
"cpp(
58 @property(nonatomic) id fi^eld;
61 EXPECT_AVAILABLE(R
"cpp(
65 @property(nonatomic) id pr^op;
69 // Ensure that the action can't be triggered on property synthesis
71 EXPECT_UNAVAILABLE(R
"cpp(
73 @property(nonatomic) id prop;
80 EXPECT_UNAVAILABLE(R
"cpp(
90 TEST_F(ObjCMemberwiseInitializerTest
, Test
) {
91 FileName
= "TestTU.m";
92 ExtraArgs
.push_back("-fobjc-runtime=macosx");
93 ExtraArgs
.push_back("-fobjc-arc");
95 const char *Input
= R
"cpp(
99 @property(nonatomic) id prop]];
100 @property(nonatomic) id notSelected;
102 const char *Output
= R
"cpp(
106 @property(nonatomic) id prop;
107 @property(nonatomic) id notSelected;
108 - (instancetype)initWithField:(id)field prop:(id)prop;
111 EXPECT_EQ(apply(Input
), Output
);
115 @property(nonatomic, nullable) id somePrettyLongPropertyName;
116 @property(nonatomic, nonnull) id someReallyLongPropertyName;
121 - (instancetype)init {
128 @property(nonatomic, nullable) id somePrettyLongPropertyName;
129 @property(nonatomic, nonnull) id someReallyLongPropertyName;
130 - (instancetype)initWithSomePrettyLongPropertyName:(nullable id)somePrettyLongPropertyName someReallyLongPropertyName:(nonnull id)someReallyLongPropertyName;
136 - (instancetype)init {
140 - (instancetype)initWithSomePrettyLongPropertyName:(nullable id)somePrettyLongPropertyName someReallyLongPropertyName:(nonnull id)someReallyLongPropertyName {
143 _somePrettyLongPropertyName = somePrettyLongPropertyName;
144 _someReallyLongPropertyName = someReallyLongPropertyName;
150 EXPECT_EQ(apply(Input
), Output
);
154 } // namespace clangd