MCPcopy Create free account
hub / github.com/expr-lang/expr / addMapDumpTests

Function addMapDumpTests

internal/spew/dump_test.go:550–649  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

548}
549
550func addMapDumpTests() {
551 // Map with string keys and int vals.
552 k := "one"
553 kk := "two"
554 m := map[string]int{k: 1, kk: 2}
555 klen := fmt.Sprintf("%d", len(k)) // not kLen to shut golint up
556 kkLen := fmt.Sprintf("%d", len(kk))
557 mLen := fmt.Sprintf("%d", len(m))
558 nilMap := map[string]int(nil)
559 nm := (*map[string]int)(nil)
560 pm := &m
561 mAddr := fmt.Sprintf("%p", pm)
562 pmAddr := fmt.Sprintf("%p", &pm)
563 mt := "map[string]int"
564 mt1 := "string"
565 mt2 := "int"
566 ms := "(len=" + mLen + ") {\n (" + mt1 + ") (len=" + klen + ") " +
567 "\"one\": (" + mt2 + ") 1,\n (" + mt1 + ") (len=" + kkLen +
568 ") \"two\": (" + mt2 + ") 2\n}"
569 ms2 := "(len=" + mLen + ") {\n (" + mt1 + ") (len=" + kkLen + ") " +
570 "\"two\": (" + mt2 + ") 2,\n (" + mt1 + ") (len=" + klen +
571 ") \"one\": (" + mt2 + ") 1\n}"
572 addDumpTest(m, "("+mt+") "+ms+"\n", "("+mt+") "+ms2+"\n")
573 addDumpTest(pm, "(*"+mt+")("+mAddr+")("+ms+")\n",
574 "(*"+mt+")("+mAddr+")("+ms2+")\n")
575 addDumpTest(&pm, "(**"+mt+")("+pmAddr+"->"+mAddr+")("+ms+")\n",
576 "(**"+mt+")("+pmAddr+"->"+mAddr+")("+ms2+")\n")
577 addDumpTest(nm, "(*"+mt+")(<nil>)\n")
578 addDumpTest(nilMap, "("+mt+") <nil>\n")
579
580 // Map with custom formatter type on pointer receiver only keys and vals.
581 k2 := pstringer("one")
582 v2 := pstringer("1")
583 m2 := map[pstringer]pstringer{k2: v2}
584 k2Len := fmt.Sprintf("%d", len(k2))
585 v2Len := fmt.Sprintf("%d", len(v2))
586 m2Len := fmt.Sprintf("%d", len(m2))
587 nilMap2 := map[pstringer]pstringer(nil)
588 nm2 := (*map[pstringer]pstringer)(nil)
589 pm2 := &m2
590 m2Addr := fmt.Sprintf("%p", pm2)
591 pm2Addr := fmt.Sprintf("%p", &pm2)
592 m2t := "map[spew_test.pstringer]spew_test.pstringer"
593 m2t1 := "spew_test.pstringer"
594 m2t2 := "spew_test.pstringer"
595 m2s := "(len=" + m2Len + ") {\n (" + m2t1 + ") (len=" + k2Len + ") " +
596 "stringer one: (" + m2t2 + ") (len=" + v2Len + ") stringer 1\n}"
597 if spew.UnsafeDisabled {
598 m2s = "(len=" + m2Len + ") {\n (" + m2t1 + ") (len=" + k2Len +
599 ") " + "\"one\": (" + m2t2 + ") (len=" + v2Len +
600 ") \"1\"\n}"
601 }
602 addDumpTest(m2, "("+m2t+") "+m2s+"\n")
603 addDumpTest(pm2, "(*"+m2t+")("+m2Addr+")("+m2s+")\n")
604 addDumpTest(&pm2, "(**"+m2t+")("+pm2Addr+"->"+m2Addr+")("+m2s+")\n")
605 addDumpTest(nm2, "(*"+m2t+")(<nil>)\n")
606 addDumpTest(nilMap2, "("+m2t+") <nil>\n")
607

Callers 1

TestDumpFunction · 0.85

Calls 3

addDumpTestFunction · 0.85
pstringerTypeAlias · 0.85
SprintfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…