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.shouldEqual(1); 19 const cursor = tu.children[0]; 20 21 cursor.kind.shouldEqual(Cursor.Kind.VarDecl); 22 cursor.spelling.shouldEqual("arr"); 23 24 const type = cursor.type; 25 type.kind.shouldEqual(Type.Kind.ConstantArray); 26 type.spelling.shouldEqual("int [4]"); 27 type.canonical.kind.shouldEqual(Type.Kind.ConstantArray); 28 type.canonical.spelling.shouldEqual("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.shouldEqual(1); 47 const cursor = tu.children[0]; 48 const structChildren = cursor.children; 49 structChildren.length.shouldEqual(2); 50 51 structChildren[0].kind.shouldEqual(Cursor.Kind.FieldDecl); 52 structChildren[0].spelling.shouldEqual("length"); 53 structChildren[0].type.kind.shouldEqual(Type.Kind.Int); 54 structChildren[0].type.spelling.shouldEqual("int"); 55 structChildren[0].type.canonical.kind.shouldEqual(Type.Kind.Int); 56 structChildren[0].type.canonical.spelling.shouldEqual("int"); 57 58 structChildren[1].kind.shouldEqual(Cursor.Kind.FieldDecl); 59 structChildren[1].spelling.shouldEqual("arr"); 60 structChildren[1].type.kind.shouldEqual(Type.Kind.IncompleteArray); 61 structChildren[1].type.spelling.shouldEqual("unsigned char []"); 62 structChildren[1].type.canonical.kind.shouldEqual(Type.Kind.IncompleteArray); 63 structChildren[1].type.canonical.spelling.shouldEqual("unsigned char []"); 64 }