package orgsettings import ( "os" "strings" "testing" ) // Small helpers for the structural tests. They read this package's own source, which is the right tool for a // defect that lives in a SQL string rather than in behaviour a unit test can reach without a database. func readSource(t *testing.T, name string) string { t.Helper() b, err := os.ReadFile(name) if err != nil { t.Fatalf("read %s: %v", name, err) } return string(b) } func contains(s, sub string) bool { return strings.Contains(s, sub) } func containsAll(s string, subs ...string) bool { for _, sub := range subs { if !strings.Contains(s, sub) { return false } } return true } // functionBody returns the text from a function's signature to the next line that begins a new top level // declaration. Crude, and sufficient: it only has to bound one function well enough to look inside it. func functionBody(src, signature string) string { i := strings.Index(src, signature) if i < 0 { return "" } rest := src[i+len(signature):] // The next top level func starts at a line beginning with "func ", which cannot occur inside a body at // column zero in gofmt output. if j := strings.Index(rest, "\nfunc "); j >= 0 { return rest[:j] } return rest }