| 49 | } |
| 50 | |
| 51 | func TestGetMap(t *testing.T) { |
| 52 | object := map[string]interface{}{ |
| 53 | "Name": "lu", |
| 54 | "Age": 20, |
| 55 | "Extend": map[string]interface{}{ |
| 56 | "Location": map[string]interface{}{ |
| 57 | "City": "Beijing", |
| 58 | }, |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | if Get(object, []string{"Name"}) != "lu" { |
| 63 | t.Fatal("[ERROR]Name != lu") |
| 64 | } |
| 65 | |
| 66 | if Get(object, []string{"Age"}) != 20 { |
| 67 | t.Fatal("[ERROR]Age != 20") |
| 68 | } |
| 69 | |
| 70 | if Get(object, []string{"Books", "0"}) != nil { |
| 71 | t.Fatal("[ERROR]books.0 != nil") |
| 72 | } |
| 73 | |
| 74 | t.Log(Get(object, []string{"Extend", "Location"})) |
| 75 | |
| 76 | if Get(object, []string{"Extend", "Location", "City"}) != "Beijing" { |
| 77 | t.Fatal("[ERROR]Extend.Location.City != Beijing") |
| 78 | } |
| 79 | } |