1 module contract.issues;
2 
3 
4 import contract;
5 
6 
7 
8 @Tags("contract")
9 @("119")
10 @safe unittest {
11 
12     import clang: Token;
13 
14     const tu = parse(
15         Cpp(
16             q{
17                 enum class Enum { foo, bar, baz };
18             }
19         )
20     );
21 
22     tu.children.length.should == 1;
23     const enum_ = tu.child(0);
24 
25     enum_.shouldMatch(Cursor.Kind.EnumDecl, "Enum");
26     enum_.type.shouldMatch(Type.Kind.Enum, "Enum");
27     printChildren(enum_);
28     enum_.children.length.should == 3; // EnumConstantDecl
29 
30     Token(Token.Kind.Keyword, "class").should.be in enum_.tokens;
31 }
32 
33 
34 
35 @Tags("contract")
36 @("126")
37 @safe unittest {
38 
39     import clang.c.index;
40 
41     const tu = parse(
42         Cpp(
43             q{
44                 template <typename T>
45                 struct Foo {
46                     T ts[42];
47                 };
48             }
49         )
50     );
51 
52     tu.children.length.should == 1;
53 
54     const foo = tu.child(0);
55     foo.shouldMatch(Cursor.Kind.ClassTemplate, "Foo");
56     foo.type.shouldMatch(Type.Kind.Invalid, "");
57     printChildren(foo);
58     foo.children.length.should == 2;
59 
60     const typeParam = foo.child(0);
61     typeParam.shouldMatch(Cursor.Kind.TemplateTypeParameter, "T");
62     typeParam.type.shouldMatch(Type.Kind.Unexposed, "T");
63     printChildren(typeParam);
64     typeParam.children.length.should == 0;
65 
66     const fieldDecl = foo.child(1);
67     fieldDecl.shouldMatch(Cursor.Kind.FieldDecl, "ts");
68     fieldDecl.type.shouldMatch(Type.Kind.ConstantArray, "T [42]");
69     printChildren(fieldDecl);
70     fieldDecl.children.length.should == 2;
71     // This is why the issue was filed
72     fieldDecl.type.getSizeof.should == -3;
73     writelnUt(clang_getTemplateCursorKind(foo.cx));
74 
75     const typeRef = fieldDecl.child(0);
76     typeRef.shouldMatch(Cursor.Kind.TypeRef, "T");
77     typeRef.type.shouldMatch(Type.Kind.Unexposed, "T");
78     printChildren(typeRef);
79     typeRef.children.length.should == 0;
80 
81     const intLiteral = fieldDecl.child(1);
82     intLiteral.shouldMatch(Cursor.Kind.IntegerLiteral, "");
83     intLiteral.type.shouldMatch(Type.Kind.Int, "int");
84     printChildren(intLiteral);
85     intLiteral.children.length.should == 0;
86 }