MCPcopy Create free account
hub / github.com/goadesign/goa / TestIsPrimitivePointer

Function TestIsPrimitivePointer

codegen/transformer_test.go:9–86  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestIsPrimitivePointer(t *testing.T) {
10 newObj := func(fieldName string, fieldType expr.DataType, req bool) *expr.AttributeExpr {
11 attr := &expr.AttributeExpr{
12 Type: &expr.Object{
13 &expr.NamedAttributeExpr{Name: fieldName, Attribute: &expr.AttributeExpr{Type: fieldType}},
14 },
15 }
16 if req {
17 attr.Validation = &expr.ValidationExpr{Required: []string{fieldName}}
18 }
19 return attr
20 }
21 tc := []struct {
22 Test string
23 Context *AttributeContext
24 Attr *expr.AttributeExpr
25 Name string
26 Expected bool
27 }{
28 {
29 Test: "pointer attribute",
30 Context: &AttributeContext{},
31 Attr: newObj("foo", expr.String, false),
32 Name: "foo",
33 Expected: true,
34 },
35 {
36 Test: "non pointer attribute",
37 Context: &AttributeContext{},
38 Attr: newObj("foo", expr.String, true),
39 Name: "foo",
40 Expected: false,
41 },
42 {
43 Test: "pointer context with pointer attribute",
44 Context: &AttributeContext{Pointer: true},
45 Attr: newObj("foo", expr.String, false),
46 Name: "foo",
47 Expected: true,
48 },
49 {
50 Test: "pointer context with non pointer attribute",
51 Context: &AttributeContext{Pointer: true},
52 Attr: newObj("foo", expr.String, true),
53 Name: "foo",
54 Expected: true,
55 },
56 {
57 Test: "ignore required context with pointer attribute",
58 Context: &AttributeContext{IgnoreRequired: true},
59 Attr: newObj("foo", expr.String, false),
60 Name: "foo",
61 Expected: true,
62 },
63 {
64 Test: "ignore required context with non pointer attribute",
65 Context: &AttributeContext{IgnoreRequired: true},
66 Attr: newObj("foo", expr.String, true),

Callers

nothing calls this directly

Calls 3

newObjFunction · 0.85
RunMethod · 0.45
IsPrimitivePointerMethod · 0.45

Tested by

no test coverage detected