internal/lsp: test adding imports for package statements with comments
Test that having a comment at the start of a file allows imports
to be added correctly.
Updates golang/go#33721
Change-Id: Id1673c2509537413710b73261ad2a59afe06b93f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190800
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/internal/lsp/source/imports_test.go b/internal/lsp/source/imports_test.go
index 0a62f6f..2d054db 100644
--- a/internal/lsp/source/imports_test.go
+++ b/internal/lsp/source/imports_test.go
@@ -84,10 +84,36 @@
},
},
{
- name: "package statement comments",
+ // Issue 33721: add import statement after package declaration preceded by comments.
+ name: "issue 33721 package statement comments before",
pkg: "os",
- in: `// This is a comment
-package main // This too`,
+ in: `// Here is a comment before
+package main
+`,
+ want: []importInfo{
+ importInfo{
+ name: "",
+ path: "os",
+ },
+ },
+ },
+ {
+ name: "package statement comments same line",
+ pkg: "os",
+ in: `package main // Here is a comment after
+`,
+ want: []importInfo{
+ importInfo{
+ name: "",
+ path: "os",
+ },
+ },
+ },
+ {
+ name: "package statement comments before and after",
+ pkg: "os",
+ in: `// Here is a comment before
+package main // Here is a comment after`,
want: []importInfo{
importInfo{
name: "",