MCPcopy
hub / github.com/gogf/gf / TestMapWithMapOption

Function TestMapWithMapOption

util/gconv/gconv_z_unit_map_test.go:287–338  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

285}
286
287func TestMapWithMapOption(t *testing.T) {
288 // Test for option: Deep.
289 gtest.C(t, func(t *gtest.T) {
290 var testMapDeep = struct {
291 Earth string
292 SubMapTest SubMapTest
293 }{
294 Earth: "中国",
295 SubMapTest: SubMapTest{
296 Name: "黄山",
297 },
298 }
299 var (
300 dt = gconv.Map(testMapDeep, gconv.MapOption{Deep: true})
301 df = gconv.Map(testMapDeep, gconv.MapOption{Deep: false})
302 dtk = reflect.TypeOf(dt["SubMapTest"]).Kind()
303 dfk = reflect.TypeOf(df["SubMapTest"]).Kind()
304 )
305 t.AssertNE(dtk, dfk)
306 })
307
308 // Test for option: OmitEmpty.
309 gtest.C(t, func(t *gtest.T) {
310 var testMapOmitEmpty = struct {
311 Earth string
312 Venus int `gconv:",omitempty"`
313 Mars string `c:",omitempty"`
314 Mercury any `json:",omitempty"`
315 }{
316 Earth: "死海",
317 Venus: 0,
318 Mars: "",
319 Mercury: nil,
320 }
321 r := gconv.Map(testMapOmitEmpty, gconv.MapOption{OmitEmpty: true})
322 t.Assert(r, map[string]any{"Earth": "死海"})
323 })
324
325 // Test for option: Tags.
326 gtest.C(t, func(t *gtest.T) {
327 var testMapOmitEmpty = struct {
328 Earth string `gconv:"errEarth" chinese:"地球" french:"Terre"`
329 }{
330 Earth: "尼莫点",
331 }
332 c := gconv.Map(testMapOmitEmpty, gconv.MapOption{Tags: []string{"chinese", "french"}})
333 t.Assert(c, map[string]any{"地球": "尼莫点"})
334
335 f := gconv.Map(testMapOmitEmpty, gconv.MapOption{Tags: []string{"french", "chinese"}})
336 t.Assert(f, map[string]any{"Terre": "尼莫点"})
337 })
338}
339
340func TestMapToMapExtra(t *testing.T) {
341 gtest.C(t, func(t *gtest.T) {

Callers

nothing calls this directly

Calls 5

CFunction · 0.92
MapFunction · 0.92
KindMethod · 0.80
AssertNEMethod · 0.80
AssertMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…