MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / assertSentinelNotDeclared

Function assertSentinelNotDeclared

pkg/codegen/server_urls_test.go:138–149  ·  view source on GitHub ↗

assertSentinelNotDeclared parses the generated output as a package body and fails if it is not valid Go or if injectSentinel appears as a top-level declared identifier (i.e. the payload escaped its comment or string literal and became real source).

(t *testing.T, out string)

Source from the content-addressed store, hash-verified

136// top-level declared identifier (i.e. the payload escaped its comment or
137// string literal and became real source).
138func assertSentinelNotDeclared(t *testing.T, out string) {
139 t.Helper()
140 src := "package p\n" + out
141 fset := token.NewFileSet()
142 file, err := parser.ParseFile(fset, "gen.go", src, parser.ParseComments)
143 require.NoError(t, err, "generated output must parse as valid Go:\n%s", src)
144
145 for _, name := range topLevelDeclNames(file) {
146 assert.NotEqual(t, injectSentinel, name,
147 "injected identifier became a real top-level declaration:\n%s", src)
148 }
149}
150
151// topLevelDeclNames returns every identifier declared at file scope.
152func topLevelDeclNames(file *ast.File) []string {

Callers 1

TestServerURLInjectionFunction · 0.85

Calls 1

topLevelDeclNamesFunction · 0.85

Tested by

no test coverage detected