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

Function TestEqual

expr/equal_test.go:8–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestEqual(t *testing.T) {
9 var (
10 ut1 = userType("ut1", object(String, Int))
11 ut2 = userType("ut2", object(String, String))
12 aut1 = userType("aut1", arrayOf(object(String, Int)))
13 aut2 = userType("aut2", arrayOf(object(String, String)))
14 rut = userType("rut", object(String, Int))
15 arut = userType("arut", arrayOf(rut))
16 )
17 nat := &NamedAttributeExpr{Name: "recursive", Attribute: &AttributeExpr{Type: rut}}
18 *rut.Type.(*Object) = append(*rut.Type.(*Object), nat)
19 cases := []struct {
20 Name string
21 dt, dt2 DataType
22 Expected bool
23 }{
24 {"primitive-true", String, String, true},
25 {"primitive-false", String, Int, false},
26 {"array-primitive-true", arrayOf(String), arrayOf(String), true},
27 {"array-primitive-false", arrayOf(String), arrayOf(Int), false},
28 {"map-primitive-true", mapOf(String, String), mapOf(String, String), true},
29 {"map-primitive-false", mapOf(String, Int), mapOf(Int, Int), false},
30 {"map-primitive-false-2", mapOf(Int, String), mapOf(Int, Int), false},
31 {"object-true", object(String, Int), object(String, Int), true},
32 {"object-false", object(String, Int), object(String, String), false},
33 {"array-object-true", arrayOf(object(String, Float32)), arrayOf(object(String, Float32)), true},
34 {"array-object-false", arrayOf(object(String, Float32)), arrayOf(object(Int)), false},
35 {"map-object-true", mapOf(object(String, Float32), object(String, Float32)), mapOf(object(String, Float32), object(String, Float32)), true},
36 {"map-object-false", mapOf(object(String, Float32), object(Int)), mapOf(object(Int), object(Int)), false},
37 {"map-object-false-2", mapOf(object(Int), object(String, Float32)), mapOf(object(Int), object(Int)), false},
38 {"user-true", ut1, ut1, true},
39 {"user-false", ut1, ut2, false},
40 {"user-recursive-true", rut, rut, true},
41 {"user-recursive-false", rut, ut2, false},
42 {"user-recursive-false-2", ut1, rut, false},
43 {"array-user-true", aut1, aut1, true},
44 {"array-user-false", aut1, aut2, false},
45 {"array-user-recursive-true", arut, arut, true},
46 {"array-user-recursive-false", arut, aut2, false},
47 {"array-user-recursive-false-2", aut1, arut, false},
48 }
49 for _, k := range cases {
50 t.Run(k.Name, func(t *testing.T) {
51 res := Equal(k.dt, k.dt2)
52 if res != k.Expected {
53 t.Errorf("Equal(%q, %q) returned %v but expected %v",
54 k.dt.Name(), k.dt2.Name(), res, k.Expected)
55 }
56 })
57 }
58}
59
60func arrayOf(dt DataType) *Array {
61 return &Array{ElemType: &AttributeExpr{Type: dt}}

Callers

nothing calls this directly

Calls 7

userTypeFunction · 0.85
objectFunction · 0.85
arrayOfFunction · 0.85
mapOfFunction · 0.85
EqualFunction · 0.85
NameMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected