1 module contract.namespace;
2 
3 
4 import contract;
5 
6 
7 
8 @Tags("contract")
9 @("struct")
10 @safe unittest {
11     const tu = parse(
12         Cpp(
13             q{
14                 namespace ns {
15                     struct Struct {
16 
17                     };
18                 }
19             }
20         )
21     );
22 
23     tu.children.length.should == 1;
24     const namespace = tu.children[0];
25     namespace.kind.should == Cursor.Kind.Namespace;
26 
27     namespace.children.length.should == 1;
28     const struct_ = namespace.children[0];
29     struct_.kind.should == Cursor.Kind.StructDecl;
30 
31     struct_.spelling.should == "Struct";
32     struct_.type.spelling.should == "ns::Struct";
33 }
34 
35 
36 @Tags("contract")
37 @("template.type.parameter")
38 @safe unittest {
39 
40     import dpp.clang: namespace;
41 
42     const tu = parse(
43         Cpp(
44             q{
45                 namespace ns {
46                     struct Struct;
47                     template<typename T>
48                     struct Template { };
49                     class Class: public Template<Struct> {
50                         int i;
51                     };
52                 }
53             }
54         )
55     );
56 
57     tu.children.length.should == 1;
58     const ns = tu.child(0);
59     ns.shouldMatch(Cursor.Kind.Namespace, "ns");
60     ns.type.shouldMatch(Type.Kind.Invalid, "");
61 
62     printChildren(ns);
63     ns.children.length.should == 3;
64 
65     const struct_ = ns.child(0);
66     struct_.shouldMatch(Cursor.Kind.StructDecl, "Struct");
67     struct_.type.shouldMatch(Type.Kind.Record, "ns::Struct");
68     printChildren(struct_);
69     struct_.children.length.should == 0;
70 
71     const template_ = ns.child(1);
72     template_.shouldMatch(Cursor.Kind.ClassTemplate, "Template");
73     template_.type.shouldMatch(Type.Kind.Invalid, "");
74     printChildren(template_);
75     template_.children.length.should == 1;
76 
77     const class_ = ns.child(2);
78     class_.shouldMatch(Cursor.Kind.ClassDecl, "Class");
79     class_.type.shouldMatch(Type.Kind.Record, "ns::Class");
80     printChildren(class_);
81     class_.children.length.should == 2;
82 
83     const base = class_.child(0);
84     base.shouldMatch(Cursor.Kind.CXXBaseSpecifier, "Template<struct ns::Struct>");
85     base.type.shouldMatch(Type.Kind.Unexposed, "Template<ns::Struct>");
86     base.type.canonical.shouldMatch(Type.Kind.Record, "ns::Template<ns::Struct>");
87     printChildren(base);
88     base.children.length.should == 2;
89 
90     const templateRef = base.child(0);
91     templateRef.shouldMatch(Cursor.Kind.TemplateRef, "Template");
92     templateRef.type.shouldMatch(Type.Kind.Invalid, "");
93     templateRef.children.length.should == 0;
94 
95     const typeRef = base.child(1);
96     typeRef.shouldMatch(Cursor.Kind.TypeRef, "struct ns::Struct");
97     typeRef.type.shouldMatch(Type.Kind.Record, "ns::Struct");
98     typeRef.type.canonical.shouldMatch(Type.Kind.Record, "ns::Struct");
99     typeRef.children.length.should == 0;
100 
101     const i = class_.child(1);
102     i.shouldMatch(Cursor.Kind.FieldDecl, "i");
103     i.type.shouldMatch(Type.Kind.Int, "int");
104     i.children.length.should == 0;
105 
106     i.namespace.shouldMatch(Cursor.Kind.Namespace, "ns");
107 }