|
|
@@ -2,7 +2,7 @@ package maputils
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
-func TestFindValueInMap(t *testing.T) {
|
|
|
+func TestGetValueInMap(t *testing.T) {
|
|
|
testMap := map[string]any{
|
|
|
"foo1": map[string]any{
|
|
|
"foo1_sub": []any{
|
|
|
@@ -11,7 +11,7 @@ func TestFindValueInMap(t *testing.T) {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- value, err := FindValueInMap(testMap, "foo1.foo1_sub.[0]")
|
|
|
+ value, err := GetValueInMap(testMap, "foo1.foo1_sub.[0]")
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
@@ -20,7 +20,7 @@ func TestFindValueInMap(t *testing.T) {
|
|
|
t.Fatal("值不一致")
|
|
|
}
|
|
|
|
|
|
- value, err = FindValueInMap(testMap, "foo1.foo1_sub.[1]")
|
|
|
+ value, err = GetValueInMap(testMap, "foo1.foo1_sub.[1]")
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
@@ -29,3 +29,31 @@ func TestFindValueInMap(t *testing.T) {
|
|
|
t.Fatal("值不一致")
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestGetValue(t *testing.T) {
|
|
|
+ testMap := map[string]any{
|
|
|
+ "foo1": map[string]any{
|
|
|
+ "foo1_sub": []any{
|
|
|
+ "value1", 2,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ foo1Map, ok := GetValue[string, map[string]any](testMap, "foo1")
|
|
|
+ if !ok {
|
|
|
+ t.Fatal("取foo1值失败")
|
|
|
+ }
|
|
|
+
|
|
|
+ foo1Sub, ok := GetValue[string, []any](foo1Map, "foo1_sub")
|
|
|
+ if !ok {
|
|
|
+ t.Fatal("取foo1Sub值失败")
|
|
|
+ }
|
|
|
+
|
|
|
+ if foo1Sub[0].(string) != "value1" {
|
|
|
+ t.Fatal("值不一致")
|
|
|
+ }
|
|
|
+
|
|
|
+ if foo1Sub[1].(int) != 2 {
|
|
|
+ t.Fatal("值不一致")
|
|
|
+ }
|
|
|
+}
|