MCPcopy Index your code
hub / github.com/expr-lang/expr / TestAddedReflectValue

Function TestAddedReflectValue

internal/spew/internalunsafe_test.go:53–102  ·  view source on GitHub ↗

TestAddedReflectValue tests functionality of the dump and formatter code which falls back to the standard fmt library for new types that might get added to the language.

(t *testing.T)

Source from the content-addressed store, hash-verified

51// falls back to the standard fmt library for new types that might get added to
52// the language.
53func TestAddedReflectValue(t *testing.T) {
54 i := 1
55
56 // Dump using a reflect.Value that is exported.
57 v := reflect.ValueOf(int8(5))
58 changeKind(&v, false)
59 buf := new(bytes.Buffer)
60 d := dumpState{w: buf, cs: &Config}
61 d.dump(v)
62 s := buf.String()
63 want := "(int8) 5"
64 if s != want {
65 t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want)
66 }
67 i++
68
69 // Dump using a reflect.Value that is not exported.
70 changeKind(&v, true)
71 buf.Reset()
72 d.dump(v)
73 s = buf.String()
74 want = "(int8) <int8 Value>"
75 if s != want {
76 t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want)
77 }
78 i++
79
80 // Formatter using a reflect.Value that is exported.
81 changeKind(&v, false)
82 buf2 := new(dummyFmtState)
83 f := formatState{value: v, cs: &Config, fs: buf2}
84 f.format(v)
85 s = buf2.String()
86 want = "5"
87 if s != want {
88 t.Errorf("TestAddedReflectValue #%d got: %s want: %s", i, s, want)
89 }
90 i++
91
92 // Formatter using a reflect.Value that is not exported.
93 changeKind(&v, true)
94 buf2.Reset()
95 f = formatState{value: v, cs: &Config, fs: buf2}
96 f.format(v)
97 s = buf2.String()
98 want = "<int8 Value>"
99 if s != want {
100 t.Errorf("TestAddedReflectValue #%d got: %s want: %s", i, s, want)
101 }
102}

Callers

nothing calls this directly

Calls 6

dumpMethod · 0.95
formatMethod · 0.95
changeKindFunction · 0.85
StringMethod · 0.65
ErrorfMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…