Skip to content

Commit f24b8c6

Browse files
thedavekwonfacebook-github-bot
authored andcommitted
Complex Annotation Test for TypeSystemFacade
Summary: more complex annotations... Reviewed By: praihan Differential Revision: D79925554 fbshipit-source-id: 83a7d940cb0ef8e0ae370be33b328841d00a67d7
1 parent 7eaf2f5 commit f24b8c6

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed

third-party/thrift/src/thrift/lib/cpp2/schema/test/SyntaxGraphTest.cpp

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ TEST_F(ServiceSchemaTest, Programs) {
6666
EXPECT_EQ(programs.size(), 3);
6767

6868
auto& mainProgram = syntaxGraph.findProgramByName("syntax_graph");
69-
EXPECT_EQ(mainProgram.definitionsByName().size(), 15);
69+
EXPECT_EQ(mainProgram.definitionsByName().size(), 16);
7070
EXPECT_EQ(mainProgram.namespaces().size(), 1);
7171
EXPECT_EQ(
7272
mainProgram.namespaces().at("cpp2"), "apache.thrift.syntax_graph.test");
@@ -578,7 +578,7 @@ TEST_F(ServiceSchemaTest, Interaction) {
578578

579579
void checkAnnotationsOnTestUnion(const UnionNode& node) {
580580
const auto& annotations = node.definition().annotations();
581-
EXPECT_EQ(annotations.size(), 1);
581+
EXPECT_EQ(annotations.size(), 2);
582582
EXPECT_EQ(
583583
&annotations[0].type().asStruct(),
584584
&node.definition()
@@ -591,6 +591,18 @@ void checkAnnotationsOnTestUnion(const UnionNode& node) {
591591
EXPECT_TRUE(annotations[0].value()["field2"].isObject());
592592
const auto& innerField = annotations[0].value()["field2"];
593593
EXPECT_EQ(innerField["field1"].asInt(), 4);
594+
595+
EXPECT_EQ(
596+
&annotations[1].type().asStruct(),
597+
&node.definition()
598+
.program()
599+
.definitionsByName()
600+
.at("ComplexAnnotation")
601+
->asStruct());
602+
EXPECT_EQ(annotations[1].value().size(), 3);
603+
EXPECT_EQ(annotations[1].value()["l"][0]["field1"].asInt(), 1);
604+
EXPECT_EQ(annotations[1].value()["s"][0], "foo");
605+
EXPECT_EQ(annotations[1].value()["m"]["bar"]["field1"].asInt(), 2);
594606
}
595607

596608
TEST_F(ServiceSchemaTest, StructuredAnnotation) {
@@ -795,12 +807,39 @@ TEST_F(ServiceSchemaTest, asTypeSystem) {
795807
&mainProgram.definitionsByName().at("TestUnion")->asUnion(),
796808
&sgUnionNode);
797809
checkAnnotationsOnTestUnion(sgUnionNode);
798-
const auto& annot = *unionNode.getAnnotationOrNull(
799-
"meta.com/thrift_test/TestStructuredAnnotation");
800-
EXPECT_EQ(annot.asFieldSet().at(FieldId{1}).asInt64(), 3);
801-
EXPECT_EQ(
802-
annot.asFieldSet().at(FieldId{2}).asFieldSet().at(FieldId{1}).asInt64(),
803-
4);
810+
{
811+
const auto& annot = *unionNode.getAnnotationOrNull(
812+
"meta.com/thrift_test/TestStructuredAnnotation");
813+
EXPECT_EQ(annot.asFieldSet().at(FieldId{1}).asInt64(), 3);
814+
EXPECT_EQ(
815+
annot.asFieldSet().at(FieldId{2}).asFieldSet().at(FieldId{1}).asInt64(),
816+
4);
817+
}
818+
{
819+
const auto& annot = *unionNode.getAnnotationOrNull(
820+
"meta.com/thrift_test/ComplexAnnotation");
821+
EXPECT_EQ(
822+
annot.asFieldSet()
823+
.at(FieldId{1})
824+
.asList()[0]
825+
.asFieldSet()
826+
.at(FieldId{1})
827+
.asInt64(),
828+
1);
829+
EXPECT_TRUE(annot.asFieldSet()
830+
.at(FieldId{2})
831+
.asSet()
832+
.contains(type_system::SerializableRecord::Text("foo")));
833+
EXPECT_EQ(
834+
annot.asFieldSet()
835+
.at(FieldId{3})
836+
.asMap()
837+
.at(type_system::SerializableRecord::Text("bar"))
838+
.asFieldSet()
839+
.at(FieldId{1})
840+
.asInt64(),
841+
2);
842+
}
804843

805844
uri = "meta.com/thrift_test/TestEnum";
806845
const type_system::EnumNode& enumNode =

third-party/thrift/src/thrift/lib/cpp2/schema/test/syntax_graph.thrift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ struct TestRecursiveStruct {
2525
1: optional TestRecursiveStruct myself;
2626
}
2727

28+
@thrift.Uri{value = "meta.com/thrift_test/ComplexAnnotation"}
29+
@scope.Structured
30+
struct ComplexAnnotation {
31+
1: list<TestInnerStructuredAnnotation> l;
32+
2: set<string> s;
33+
3: map<string, TestInnerStructuredAnnotation> m;
34+
}
35+
2836
@thrift.Uri{value = "meta.com/thrift_test/TestStructuredAnnotation"}
2937
@scope.Definition
3038
@scope.Field
@@ -62,6 +70,11 @@ typedef TestStructuredAnnotation TypedefToTestStructuredAnnotation
6270
field1 = 3,
6371
field2 = TestInnerStructuredAnnotation{field1 = 4},
6472
}
73+
@ComplexAnnotation{
74+
l = [TestInnerStructuredAnnotation{field1 = 1}],
75+
s = ["foo"],
76+
m = {"bar": TestInnerStructuredAnnotation{field1 = 2}},
77+
}
6578
@thrift.Uri{value = "meta.com/thrift_test/TestUnion"}
6679
union TestUnion {
6780
1: TestStruct s;

0 commit comments

Comments
 (0)