1 module contract.operators; 2 3 4 import contract; 5 6 7 @("opCast no template") 8 @safe unittest { 9 10 const tu = parse( 11 Cpp( 12 q{ 13 struct Struct { 14 operator int() const; 15 }; 16 } 17 ) 18 ); 19 20 tu.children.length.shouldEqual(1); 21 22 const struct_ = tu.children[0]; 23 printChildren(struct_); 24 struct_.kind.should == Cursor.Kind.StructDecl; 25 struct_.children.length.shouldEqual(1); 26 27 const conversion = struct_.children[0]; 28 printChildren(conversion); 29 30 conversion.kind.should == Cursor.Kind.ConversionFunction; 31 conversion.spelling.should == "operator int"; 32 } 33 34 @("opCast template") 35 @safe unittest { 36 37 const tu = parse( 38 Cpp( 39 q{ 40 template<typename T> 41 struct Struct { 42 operator T() const; 43 }; 44 } 45 ) 46 ); 47 48 tu.children.length.shouldEqual(1); 49 50 const struct_ = tu.children[0]; 51 printChildren(struct_); 52 struct_.kind.should == Cursor.Kind.ClassTemplate; 53 struct_.children.length.shouldEqual(2); 54 55 const typeParam = struct_.children[0]; 56 typeParam.kind.should == Cursor.Kind.TemplateTypeParameter; 57 58 const conversion = struct_.children[1]; 59 printChildren(conversion); 60 61 conversion.kind.should == Cursor.Kind.ConversionFunction; 62 conversion.spelling.should == "operator type-parameter-0-0"; 63 64 const retType = conversion.returnType; 65 retType.kind.should == Type.Kind.Unexposed; 66 retType.canonical.kind.should == Type.Kind.Unexposed; 67 retType.spelling.should == "T"; 68 retType.canonical.spelling.should == "type-parameter-0-0"; 69 }