Open chuckchann opened 1 year ago
somebody help ?
what version are you using? I just added this test for a quick check on latest version and it passes fine
func TestSetArray(t *testing.T) {
data := map[string]interface{}{
"name": "Alice",
"age": 30,
"hobbies": []string{
"reading",
"swimming",
"running",
},
}
d := objx.Map(data)
d = d.Set("hobbies[0]", "coding")
assert.Equal(t, "coding", d.Get("hobbies[0]").String())
}
what version are you using? I just added this test for a quick check on latest version and it passes fine
func TestSetArray(t *testing.T) { data := map[string]interface{}{ "name": "Alice", "age": 30, "hobbies": []string{ "reading", "swimming", "running", }, } d := objx.Map(data) d = d.Set("hobbies[0]", "coding") assert.Equal(t, "coding", d.Get("hobbies[0]").String()) }
my version is v0.5.0 in your test case, the type of struct field( "hobbies") has been change to string, you can print the object "d", here is my print result:
"map[age:30 hobbies:coding name:Alice]"
that`s why your test case passes fine
this is my code:
func main() { data := map[string]interface{}{ "name": "Alice", "age": 30, "hobbies": []string{ "reading", "swimming", "running", }, }
}
my result is: after set -> map[age:30 hobbies:sssss name:Alice]
what I expect is: after set -> map[age:30 hobbies:[coding, swimming, running] name:Alice]
it seems that there is a bug in obj.Set function when I want to modify a value in the array?