@@ -35,13 +35,36 @@ func TestGetNil(t *testing.T) {
3535 is .Equal (Get ([]* Foo {foo , foo2 }, "Bar.Name" ), []string {"Test" })
3636}
3737
38+ func TestGetMap (t * testing.T ) {
39+ is := assert .New (t )
40+ m := map [string ]interface {}{
41+ "bar" : map [string ]interface {}{
42+ "name" : "foobar" ,
43+ },
44+ }
45+
46+ is .Equal ("foobar" , Get (m , "bar.name" ))
47+ is .Equal (nil , Get (m , "foo.name" ))
48+ is .Equal ([]interface {}{"dark" , "dark" }, Get ([]map [string ]interface {}{m1 , m2 }, "firstname" ))
49+ is .Equal ([]interface {}{"test" }, Get ([]map [string ]interface {}{m1 , m2 }, "bar.name" ))
50+ }
51+
3852func TestGetThroughInterface (t * testing.T ) {
3953 is := assert .New (t )
4054
4155 is .Equal (Get (foo , "BarInterface.Bars.Bar.Name" ), []string {"Level2-1" , "Level2-2" })
4256 is .Equal (Get (foo , "BarPointer.Bars.Bar.Name" ), []string {"Level2-1" , "Level2-2" })
4357}
4458
59+ func TestGetNotFound (t * testing.T ) {
60+ is := assert .New (t )
61+
62+ is .Equal (nil , Get (foo , "id" ))
63+ is .Equal (nil , Get (foo , "id.id" ))
64+ is .Equal (nil , Get (foo , "Bar.id" ))
65+ is .Equal (nil , Get (foo , "Bars.id" ))
66+ }
67+
4568func TestGetSimple (t * testing.T ) {
4669 is := assert .New (t )
4770
@@ -68,5 +91,4 @@ func TestGetOrElse(t *testing.T) {
6891 // test GetOrElse coveers this case
6992 is .Equal ("foobar" , GetOrElse ((* string )(nil ), "foobar" ))
7093 })
71-
7294}
0 commit comments