func Test_Config_Empty(t *testing.T) { cfg := &Config{} is_iface := cfg.isInterface("foo") testutil.AssertFalse(t, is_iface, "isInterface() returned true") pkg := cfg.packageName("foo") testutil.AssertEmpty(t, pkg, "Package() returned", pkg) rcvr := cfg.receiver("foo") testutil.AssertEmpty(t, rcvr, "Receiver() returned", rcvr) str := cfg.String() if !strings.HasPrefix(str, "Config[") || !strings.HasSuffix(str, "]") { t.Fatal("String() returned", str) } }
func Test_TypeData_Primitive(t *testing.T) { allTypes := []string{ "void", "boolean", "byte", "char", "short", "int", "long", "float", "double", "string", } for _, str := range allTypes { for dim := 0; dim < 5; dim++ { td := NewTypeDataPrimitive(str, dim) _, is_nil := td.TypeName() testutil.AssertEqual(t, dim == 0 && strings.EqualFold(str, "void"), is_nil, str, "should not be nil", is_nil) var expStr string switch str { case "boolean": expStr = "bool" case "short": expStr = "int16" case "long": expStr = "int64" case "float": expStr = "float32" case "double": expStr = "float64" default: expStr = str } for i := 1; i <= dim; i++ { expStr = "[]" + expStr } testutil.AssertEqual(t, td.String(), expStr, "Expected", expStr, "not", td.String()) testutil.AssertFalse(t, td.isObject(), "Unexpected object", str) } } defer func() { if x := recover(); x != nil { testutil.AssertEqual(t, x, "Unrecognized primitive type xxx") } }() td := NewTypeDataPrimitive("xxx", 0) testutil.AssertNotNil(t, td, "Got nil TypeData for bad primitive type") }
func validate(t *testing.T, str string, dim int, td *TypeData, fd *FakeDictionary) { vt, is_nil := td.TypeName() testutil.AssertEqual(t, dim == 0 && strings.EqualFold(str, "void"), is_nil, str, "should not be nil", is_nil) if !is_nil { testutil.AssertNotNil(t, vt, str, "dim", dim, "is nil ::", vt) } expName := str if dim == 0 { expName = str } else { var star string if fd != nil && !fd.IsInterface(str) { star = "*" } expName = fmt.Sprintf("array_%s%s_dim%d", star, str, dim) } testutil.AssertEqual(t, expName, td.Name(), "Expected name", expName, "not", td.Name()) var expStr string if fd == nil || fd.IsInterface(str) { expStr = str } else { expStr = "*" + str } for i := 1; i <= dim; i++ { expStr = "[]" + expStr } testutil.AssertEqual(t, expStr, td.String(), "Expected string ", expStr, "not", td.String()) if fd != nil { if dim == 0 { testutil.AssertTrue(t, td.isObject(), "Expected object", str) } else { testutil.AssertFalse(t, td.isObject(), "Unexpected object", str) } } }