MCPcopy Create free account
hub / github.com/despiteallobjections/amigo / TestRuntimeTypes

Function TestRuntimeTypes

types/builder_test.go:155–241  ·  view source on GitHub ↗

TestRuntimeTypes tests that (*Program).RuntimeTypes() includes all necessary types.

(t *testing.T)

Source from the content-addressed store, hash-verified

153
154// TestRuntimeTypes tests that (*Program).RuntimeTypes() includes all necessary types.
155func TestRuntimeTypes(t *testing.T) {
156 tests := []struct {
157 input string
158 want []string
159 }{
160 // An exported package-level type is needed.
161 {`package A; type T struct{}; func (T) f() {}`,
162 []string{"*p.T", "p.T"},
163 },
164 // An unexported package-level type is not needed.
165 {`package B; type t struct{}; func (t) f() {}`,
166 nil,
167 },
168 // Subcomponents of type of exported package-level var are needed.
169 {`package C; import "bytes"; var V struct {*bytes.Buffer}`,
170 []string{"*bytes.Buffer", "*struct{*bytes.Buffer}", "struct{*bytes.Buffer}"},
171 },
172 // Subcomponents of type of unexported package-level var are not needed.
173 {`package D; import "bytes"; var v struct {*bytes.Buffer}`,
174 nil,
175 },
176 // Subcomponents of type of exported package-level function are needed.
177 {`package E; import "bytes"; func F(struct {*bytes.Buffer}) {}`,
178 []string{"*bytes.Buffer", "struct{*bytes.Buffer}"},
179 },
180 // Subcomponents of type of unexported package-level function are not needed.
181 {`package F; import "bytes"; func f(struct {*bytes.Buffer}) {}`,
182 nil,
183 },
184 // Subcomponents of type of exported method of uninstantiated unexported type are not needed.
185 {`package G; import "bytes"; type x struct{}; func (x) G(struct {*bytes.Buffer}) {}; var v x`,
186 nil,
187 },
188 // ...unless used by MakeInterface.
189 {`package G2; import "bytes"; type x struct{}; func (x) G(struct {*bytes.Buffer}) {}; var v interface{} = x{}`,
190 []string{"*bytes.Buffer", "*p.x", "p.x", "struct{*bytes.Buffer}"},
191 },
192 // Subcomponents of type of unexported method are not needed.
193 {`package I; import "bytes"; type X struct{}; func (X) G(struct {*bytes.Buffer}) {}`,
194 []string{"*bytes.Buffer", "*p.X", "p.X", "struct{*bytes.Buffer}"},
195 },
196 // Local types aren't needed.
197 {`package J; import "bytes"; func f() { type T struct {*bytes.Buffer}; var t T; _ = t }`,
198 nil,
199 },
200 // ...unless used by MakeInterface.
201 {`package K; import "bytes"; func f() { type T struct {*bytes.Buffer}; _ = interface{}(T{}) }`,
202 []string{"*bytes.Buffer", "*p.T", "p.T"},
203 },
204 // Types used as operand of MakeInterface are needed.
205 {`package L; import "bytes"; func f() { _ = interface{}(struct{*bytes.Buffer}{}) }`,
206 []string{"*bytes.Buffer", "struct{*bytes.Buffer}"},
207 },
208 // MakeInterface is optimized away when storing to a blank.
209 {`package M; import "bytes"; var _ interface{} = struct{*bytes.Buffer}{}`,
210 nil,
211 },
212 }

Callers

nothing calls this directly

Calls 7

BuildPackageFunction · 0.92
DefaultFunction · 0.92
ParseStringFunction · 0.85
NewPackageFunction · 0.85
RuntimeTypesMethod · 0.80
StringMethod · 0.65
appendFunction · 0.50

Tested by

no test coverage detected