package jxutils import ( "testing" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/globals/refutil" ) func TestObjFieldByName(t *testing.T) { kk := struct { ID int8 Name string }{ ID: 1, Name: "hello", } if refutil.GetObjFieldByName(kk, "ID").(int8) != 1 { t.Fatal("value is not ok") } if refutil.GetObjFieldByName(kk, "Name").(string) != "hello" { t.Fatal("value is not ok") } pKK := &kk if refutil.GetObjFieldByName(pKK, "ID").(int8) != 1 { t.Fatal("value is not ok") } if refutil.GetObjFieldByName(pKK, "Name").(string) != "hello" { t.Fatal("value is not ok") } refutil.SetObjFieldByName(pKK, "ID", int8(100)) refutil.SetObjFieldByName(pKK, "Name", "world") if refutil.GetObjFieldByName(pKK, "ID").(int8) != 100 { t.Fatal("value is not ok") } if refutil.GetObjFieldByName(pKK, "Name").(string) != "world" { t.Fatal("value is not ok") } t.Log(utils.Format4Output(pKK, false)) }