From 7103138b8bf45fc6f125daec4d8542a0f37385e4 Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Wed, 2 Mar 2022 11:35:52 -0700 Subject: [PATCH] gopls: add regtest for edit go directive quick fix Change-Id: Id02a51b8513e11c688a1da9e7e1af66481d4881e Reviewed-on: https://go-review.googlesource.com/c/tools/+/389255 Trust: Suzy Mueller Run-TryBot: Suzy Mueller Reviewed-by: Robert Findley gopls-CI: kokoro TryBot-Result: Gopher Robot --- .../regtest/diagnostics/diagnostics_test.go | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/gopls/internal/regtest/diagnostics/diagnostics_test.go b/gopls/internal/regtest/diagnostics/diagnostics_test.go index e5b346cb3d..b9802e2457 100644 --- a/gopls/internal/regtest/diagnostics/diagnostics_test.go +++ b/gopls/internal/regtest/diagnostics/diagnostics_test.go @@ -2185,3 +2185,33 @@ func F[T C](_ T) { } }) } + +func TestEditGoDirective(t *testing.T) { + testenv.NeedsGo1Point(t, 18) + const files = ` +-- go.mod -- +module mod.com + +go 1.16 +-- main.go -- +package main + +func F[T any](_ T) { +} +` + Run(t, files, func(t *testing.T, env *Env) { // Create a new workspace-level directory and empty file. + var d protocol.PublishDiagnosticsParams + env.Await( + OnceMet( + env.DiagnosticAtRegexpWithMessage("main.go", `T any`, "type parameters require"), + ReadDiagnostics("main.go", &d), + ), + ) + + env.ApplyQuickFixes("main.go", d.Diagnostics) + + env.Await( + EmptyDiagnostics("main.go"), + ) + }) +}