MCPcopy
hub / github.com/golang/tools / TestFixGoAndDefer

Function TestFixGoAndDefer

gopls/internal/cache/parsego/parse_test.go:53–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func TestFixGoAndDefer(t *testing.T) {
54 var testCases = []struct {
55 source string
56 fixes []parsego.FixType
57 wantFix string
58 }{
59 {source: "", fixes: nil}, // keyword alone
60 {source: "a.b(", fixes: nil},
61 {source: "a.b()", fixes: nil},
62 {source: "func {", fixes: nil},
63 {
64 source: "f",
65 fixes: []parsego.FixType{parsego.FixedDeferOrGo},
66 wantFix: "f()",
67 },
68 {
69 source: "func",
70 fixes: []parsego.FixType{parsego.FixedDeferOrGo},
71 wantFix: "(func())()",
72 },
73 {
74 source: "func {}",
75 fixes: []parsego.FixType{parsego.FixedDeferOrGo},
76 wantFix: "(func())()",
77 },
78 {
79 source: "func {}(",
80 fixes: []parsego.FixType{parsego.FixedDeferOrGo},
81 wantFix: "(func())()",
82 },
83 {
84 source: "func {}()",
85 fixes: []parsego.FixType{parsego.FixedDeferOrGo},
86 wantFix: "(func())()",
87 },
88 {
89 source: "a.",
90 fixes: []parsego.FixType{parsego.FixedDeferOrGo, parsego.FixedDanglingSelector, parsego.FixedDeferOrGo},
91 wantFix: "a._()",
92 },
93 {
94 source: "a.b",
95 fixes: []parsego.FixType{parsego.FixedDeferOrGo},
96 wantFix: "a.b()",
97 },
98 }
99
100 for _, keyword := range []string{"go", "defer"} {
101 for _, tc := range testCases {
102 source := fmt.Sprintf("%s %s", keyword, tc.source)
103 t.Run(source, func(t *testing.T) {
104 src := filesrc(source)
105 pgf, fixes := parsego.Parse(context.Background(), token.NewFileSet(), "file://foo.go", src, parsego.Full, false)
106 if !slices.Equal(fixes, tc.fixes) {
107 t.Fatalf("got %v want %v", fixes, tc.fixes)
108 }
109 if tc.fixes == nil {
110 return

Callers

nothing calls this directly

Calls 8

ParseFunction · 0.92
FileSetForFunction · 0.92
FormatFunction · 0.92
filesrcFunction · 0.85
inspectFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
FatalfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…