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

Function TestInvalidReflectValue

internal/spew/internal_test.go:54–78  ·  view source on GitHub ↗

TestInvalidReflectValue ensures the dump and formatter code handles an invalid reflect value properly. This needs access to internal state since it should never happen in real code and therefore can't be tested via the public API.

(t *testing.T)

Source from the content-addressed store, hash-verified

52// should never happen in real code and therefore can't be tested via the public
53// API.
54func TestInvalidReflectValue(t *testing.T) {
55 i := 1
56
57 // Dump invalid reflect value.
58 v := new(reflect.Value)
59 buf := new(bytes.Buffer)
60 d := dumpState{w: buf, cs: &Config}
61 d.dump(*v)
62 s := buf.String()
63 want := "<invalid>"
64 if s != want {
65 t.Errorf("InvalidReflectValue #%d\n got: %s want: %s", i, s, want)
66 }
67 i++
68
69 // Formatter invalid reflect value.
70 buf2 := new(dummyFmtState)
71 f := formatState{value: *v, cs: &Config, fs: buf2}
72 f.format(*v)
73 s = buf2.String()
74 want = "<invalid>"
75 if s != want {
76 t.Errorf("InvalidReflectValue #%d got: %s want: %s", i, s, want)
77 }
78}
79
80// SortValues makes the internal sortValues function available to the test
81// package.

Callers

nothing calls this directly

Calls 4

dumpMethod · 0.95
formatMethod · 0.95
StringMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…