1 module contract.array; 2 3 4 import contract; 5 6 7 @Tags("contract") 8 @("int[4]") 9 @safe unittest { 10 const tu = parse( 11 C( 12 q{ 13 int arr[4]; 14 } 15 ) 16 ); 17 18 tu.children.length.should == 1; 19 const cursor = tu.children[0]; 20 21 cursor.kind.should == Cursor.Kind.VarDecl; 22 cursor.spelling.should == "arr"; 23 24 const type = cursor.type; 25 type.kind.should == Type.Kind.ConstantArray; 26 type.spelling.should == "int [4]"; 27 type.canonical.kind.should == Type.Kind.ConstantArray; 28 type.canonical.spelling.should == "int [4]"; 29 } 30 31 32 @Tags("contract") 33 @("flexible") 34 @safe unittest { 35 const tu = parse( 36 C( 37 q{ 38 struct Slice { 39 int length; 40 unsigned char arr[]; 41 }; 42 } 43 ) 44 ); 45 46 tu.children.length.should == 1; 47 const cursor = tu.children[0]; 48 const structChildren = cursor.children; 49 structChildren.length.should == 2; 50 51 structChildren[0].kind.should == Cursor.Kind.FieldDecl; 52 structChildren[0].spelling.should == "length"; 53 structChildren[0].type.kind.should == Type.Kind.Int; 54 structChildren[0].type.spelling.should == "int"; 55 structChildren[0].type.canonical.kind.should == Type.Kind.Int; 56 structChildren[0].type.canonical.spelling.should == "int"; 57 58 structChildren[1].kind.should == Cursor.Kind.FieldDecl; 59 structChildren[1].spelling.should == "arr"; 60 structChildren[1].type.kind.should == Type.Kind.IncompleteArray; 61 structChildren[1].type.spelling.should == "unsigned char []"; 62 structChildren[1].type.canonical.kind.should == Type.Kind.IncompleteArray; 63 structChildren[1].type.canonical.spelling.should == "unsigned char []"; 64 }