Skip to content

Commit a3c3981

Browse files
committed
[unittest/Sema] NFC: Add a way to create a protocol with a given name and parent type
1 parent 8024b7b commit a3c3981

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

unittests/Sema/SemaFixture.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ Type SemaTest::getStdlibType(StringRef name) const {
7676
return Type();
7777
}
7878

79+
ProtocolType *SemaTest::createProtocol(llvm::StringRef protocolName,
80+
Type parent) {
81+
auto *PD = new (Context)
82+
ProtocolDecl(DC, SourceLoc(), SourceLoc(),
83+
Context.getIdentifier(protocolName), /*Inherited=*/{},
84+
/*trailingWhere=*/nullptr);
85+
PD->setImplicit();
86+
87+
return ProtocolType::get(PD, parent, Context);
88+
}
89+
7990
ConstraintSystem::PotentialBindings
8091
SemaTest::inferBindings(ConstraintSystem &cs, TypeVariableType *typeVar) {
8192
llvm::SmallDenseMap<TypeVariableType *, ConstraintSystem::PotentialBindings>

unittests/Sema/SemaFixture.h

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "swift/AST/Module.h"
1616
#include "swift/AST/SourceFile.h"
1717
#include "swift/AST/Type.h"
18+
#include "swift/AST/Types.h"
1819
#include "swift/Basic/LangOptions.h"
1920
#include "swift/Basic/Platform.h"
2021
#include "swift/Basic/SourceManager.h"
@@ -66,6 +67,9 @@ class SemaTest : public SemaTestBase {
6667
protected:
6768
Type getStdlibType(StringRef name) const;
6869

70+
ProtocolType *createProtocol(llvm::StringRef protocolName,
71+
Type parent = Type());
72+
6973
static ConstraintSystem::PotentialBindings
7074
inferBindings(ConstraintSystem &cs, TypeVariableType *typeVar);
7175
};

0 commit comments

Comments
 (0)