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