func TestNomsTypeDiff(t *testing.T) { assert := assert.New(t) expected := "- List<Number>\n+ List<String>\n" t1 := types.MakeListType(types.NumberType) t2 := types.MakeListType(types.StringType) buf := util.NewBuffer(nil) Diff(buf, t1, t2) assert.Equal(expected, buf.String()) expected = "- List<Number>\n+ Set<String>\n" t1 = types.MakeListType(types.NumberType) t2 = types.MakeSetType(types.StringType) buf = util.NewBuffer(nil) Diff(buf, t1, t2) assert.Equal(expected, buf.String()) }
func (suite *ParsedResultTestSuite) SetupTest() { suite.prim = newTestField("a", types.NumberType, "") suite.prim2 = newTestField("b", types.StringType, "") suite.compound = newTestField("set", types.MakeSetType(types.StringType), "") suite.compoundOfCompound = newTestField("listOfSet", types.MakeListType(types.MakeSetType(types.StringType)), "") suite.namedType = newTestField("otherStruct", makeUnresolvedType("", "Other"), "Other") suite.namespacedType = newTestField("namespacedStruct", makeUnresolvedType("Elsewhere", "Other"), "Elsewhere.Other") suite.mapOfNamedType = newTestField("mapOfStructToOther", types.MakeMapType(makeUnresolvedType("", "Struct"), makeUnresolvedType("Elsewhere", "Other")), "Map<Struct, Elsewhere.Other>") }
// resolveReferences replaces references with the actual Type func resolveReferences(i *intermediate, aliases map[string][]*types.Type) { var rec func(t *types.Type) *types.Type resolveFields := func(desc types.StructDesc) *types.Type { fields := make(types.TypeMap, desc.Len()) desc.IterFields(func(name string, t *types.Type) { fields[name] = rec(t) }) return types.MakeStructType(desc.Name, fields) } rec = func(t *types.Type) *types.Type { switch t.Kind() { case UnresolvedKind: desc := t.Desc.(UnresolvedDesc) if desc.Namespace == "" { return findType(desc.Name, i.Types) } ts, ok := aliases[desc.Namespace] d.Exp.True(ok, "No such namespace: %s", desc.Namespace) return findType(desc.Name, ts) case types.ListKind: return types.MakeListType(rec(t.Desc.(types.CompoundDesc).ElemTypes[0])) case types.SetKind: return types.MakeSetType(rec(t.Desc.(types.CompoundDesc).ElemTypes[0])) case types.RefKind: return types.MakeRefType(rec(t.Desc.(types.CompoundDesc).ElemTypes[0])) case types.MapKind: elemTypes := t.Desc.(types.CompoundDesc).ElemTypes return types.MakeMapType(rec(elemTypes[0]), rec(elemTypes[1])) case types.StructKind: return resolveFields(t.Desc.(types.StructDesc)) } return t } for idx, t := range i.Types { i.Types[idx] = rec(t) } }
func (c *current) onCompoundType2(t interface{}) (interface{}, error) { return types.MakeListType(t.(*types.Type)), nil }