(t *testing.T)
| 92 | } |
| 93 | |
| 94 | func TestCollectAttributes(t *testing.T) { |
| 95 | cases := []struct { |
| 96 | name string |
| 97 | attrNames *expr.AttributeExpr |
| 98 | parent *expr.AttributeExpr |
| 99 | want []*AttributeData |
| 100 | }{ |
| 101 | { |
| 102 | name: "nil-attributes", |
| 103 | attrNames: nil, |
| 104 | parent: &expr.AttributeExpr{Type: &expr.Object{}}, |
| 105 | want: nil, |
| 106 | }, |
| 107 | { |
| 108 | name: "non-object-attributes", |
| 109 | attrNames: &expr.AttributeExpr{Type: expr.Primitive(expr.StringKind)}, |
| 110 | parent: &expr.AttributeExpr{Type: &expr.Object{}}, |
| 111 | want: nil, |
| 112 | }, |
| 113 | { |
| 114 | name: "simple-string-attribute", |
| 115 | attrNames: &expr.AttributeExpr{ |
| 116 | Type: &expr.Object{ |
| 117 | {Name: "name", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.StringKind)}}, |
| 118 | }, |
| 119 | }, |
| 120 | parent: &expr.AttributeExpr{ |
| 121 | Type: &expr.Object{ |
| 122 | {Name: "name", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.StringKind)}}, |
| 123 | }, |
| 124 | Validation: &expr.ValidationExpr{Required: []string{"name"}}, |
| 125 | }, |
| 126 | want: []*AttributeData{ |
| 127 | {Name: "Name", TypeRef: "string", Pointer: false}, |
| 128 | }, |
| 129 | }, |
| 130 | { |
| 131 | name: "pointer-primitive", |
| 132 | attrNames: &expr.AttributeExpr{ |
| 133 | Type: &expr.Object{ |
| 134 | {Name: "age", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.IntKind)}}, |
| 135 | }, |
| 136 | }, |
| 137 | parent: &expr.AttributeExpr{ |
| 138 | Type: &expr.Object{ |
| 139 | {Name: "age", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.IntKind), Meta: map[string][]string{"struct:field:pointer": {"true"}}}}, |
| 140 | }, |
| 141 | }, |
| 142 | want: []*AttributeData{ |
| 143 | {Name: "Age", TypeRef: "int", Pointer: true}, |
| 144 | }, |
| 145 | }, |
| 146 | { |
| 147 | name: "multiple-attributes", |
| 148 | attrNames: &expr.AttributeExpr{ |
| 149 | Type: &expr.Object{ |
| 150 | {Name: "name", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.StringKind)}}, |
| 151 | {Name: "age", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.IntKind)}}, |
nothing calls this directly
no test coverage detected