(t *testing.T)
| 63 | } |
| 64 | |
| 65 | func Test_MapStructObjectWrapper(t *testing.T) { |
| 66 | // This tests that maps work as expected when wrapping a Struct with js.Object field containing a map. |
| 67 | // js.Object fields' content should be passed to JS, so this is basically doubly-wrapping a map in two structs. |
| 68 | |
| 69 | stringMap := map[string]string{"key": "value"} |
| 70 | |
| 71 | // You cannot wrap a map directly, so put it in a struct. |
| 72 | type StructWithMap struct { |
| 73 | Map map[string]string |
| 74 | } |
| 75 | |
| 76 | swm := &StructWithMap{Map: stringMap} |
| 77 | swmWrapped := js.MakeFullWrapper(swm) |
| 78 | |
| 79 | // Now that map is wrapped in a struct, wrap the js.object in *another* struct. |
| 80 | type StructWithObject struct { |
| 81 | Wrappedswm *js.Object // This Object contains StructWithMap. |
| 82 | } |
| 83 | |
| 84 | swo := &StructWithObject{Wrappedswm: swmWrapped} |
| 85 | swoWrapper := js.MakeFullWrapper(swo) |
| 86 | swmUnwrapped := swoWrapper.Interface().(*StructWithObject) |
| 87 | |
| 88 | // Using "Get("Map")" shows that the first wrapping was unchanged. |
| 89 | if got := swoWrapper.Get("Wrappedswm").Get("Map").Get("key").String(); got != stringMap["key"] { |
| 90 | t.Errorf("Wrapped Wrappedswm value Got: %s, Want: %s", got, stringMap["key"]) |
| 91 | } |
| 92 | |
| 93 | if got := swmUnwrapped.Wrappedswm.Get("Map").Get("key").String(); got != stringMap["key"] { |
| 94 | t.Errorf("Unwrapped Wrappedswm value Got: %s, Want: %s", got, stringMap["key"]) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | func Test_MapEmbeddedObject(t *testing.T) { |
| 99 | o := js.Global.Get("JSON").Call("parse", `{"props": {"one": 1, "two": 2}}`) |
nothing calls this directly
no test coverage detected
searching dependent graphs…