This test checks the behavior of the 'add test for FUNC' code action.

-- flags --
-ignore_extra_diags

-- go.mod --
module golang.org/lsptests/addtest

go 1.18

-- settings.json --
{
	"addTestSourceCodeAction": true
}

-- withcopyright/copyright.go --
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.23

// Package main is for lsp test.
package main

func Foo(in string) string {return in} //@codeactionedit("Foo", "source.addTest", with_copyright)

-- @with_copyright/withcopyright/copyright_test.go --
@@ -0,0 +1,24 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main_test
+
+func TestFoo(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := main.Foo(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("Foo() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- withoutcopyright/copyright.go --
//go:build go1.23

// Package copyright is for lsp test.
package copyright

func Foo(in string) string {return in} //@codeactionedit("Foo", "source.addTest", without_copyright)

-- @without_copyright/withoutcopyright/copyright_test.go --
@@ -0,0 +1,20 @@
+package copyright_test
+
+func TestFoo(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := copyright.Foo(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("Foo() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- missingtestfile/missingtestfile.go --
package main

func ExportedFunction(in string) string {return in} //@codeactionedit("ExportedFunction", "source.addTest", missing_test_file_exported_function)

type Bar struct {}

func (*Bar) ExportedMethod(in string) string {return in} //@codeactionedit("ExportedMethod", "source.addTest", missing_test_file_exported_recv_exported_method)

-- @missing_test_file_exported_function/missingtestfile/missingtestfile_test.go --
@@ -0,0 +1,20 @@
+package main_test
+
+func TestExportedFunction(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := main.ExportedFunction(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("ExportedFunction() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- @missing_test_file_exported_recv_exported_method/missingtestfile/missingtestfile_test.go --
@@ -0,0 +1,20 @@
+package main_test
+
+func TestBar_ExportedMethod(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := ExportedMethod(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("ExportedMethod() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- xpackagetestfile/xpackagetestfile.go --
package main

func ExportedFunction(in string) string {return in} //@codeactionedit("ExportedFunction", "source.addTest", xpackage_exported_function)
func unexportedFunction(in string) string {return in} //@codeactionedit("unexportedFunction", "source.addTest", xpackage_unexported_function)

type Bar struct {}

func (*Bar) ExportedMethod(in string) string {return in} //@codeactionedit("ExportedMethod", "source.addTest", xpackage_exported_recv_exported_method)
func (*Bar) unexportedMethod(in string) string {return in} //@codeactionedit("unexportedMethod", "source.addTest", xpackage_exported_recv_unexported_method)

type foo struct {}

func (*foo) ExportedMethod(in string) string {return in} //@codeactionedit("ExportedMethod", "source.addTest", xpackage_unexported_recv_exported_method)
func (*foo) unexportedMethod(in string) string {return in} //@codeactionedit("unexportedMethod", "source.addTest", xpackage_unexported_recv_unexported_method)

-- xpackagetestfile/xpackagetestfile_test.go --
package main

-- @xpackage_exported_function/xpackagetestfile/xpackagetestfile_test.go --
@@ -3 +3,18 @@
+func TestExportedFunction(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := ExportedFunction(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("ExportedFunction() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- @xpackage_unexported_function/xpackagetestfile/xpackagetestfile_test.go --
@@ -3 +3,18 @@
+func Test_unexportedFunction(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := unexportedFunction(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("unexportedFunction() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- @xpackage_exported_recv_exported_method/xpackagetestfile/xpackagetestfile_test.go --
@@ -3 +3,18 @@
+func TestBar_ExportedMethod(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := ExportedMethod(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("ExportedMethod() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- @xpackage_exported_recv_unexported_method/xpackagetestfile/xpackagetestfile_test.go --
@@ -3 +3,18 @@
+func TestBar_unexportedMethod(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := unexportedMethod(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("unexportedMethod() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- @xpackage_unexported_recv_exported_method/xpackagetestfile/xpackagetestfile_test.go --
@@ -3 +3,18 @@
+func Test_foo_ExportedMethod(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := ExportedMethod(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("ExportedMethod() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- @xpackage_unexported_recv_unexported_method/xpackagetestfile/xpackagetestfile_test.go --
@@ -3 +3,18 @@
+func Test_foo_unexportedMethod(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := unexportedMethod(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("unexportedMethod() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- aliasreceiver/aliasreceiver.go --
package main

type bar struct {}
type middle1 = bar
type middle2 = middle1
type middle3 = middle2
type Bar = middle3

func (*Bar) ExportedMethod(in string) string {return in} //@codeactionedit("ExportedMethod", "source.addTest", pointer_receiver_exported_method)
func (*Bar) unexportedMethod(in string) string {return in} //@codeactionedit("unexportedMethod", "source.addTest", pointer_receiver_unexported_method)

type bar2 struct {}
type middle4 = bar2
type middle5 = middle4
type middle6 = middle5
type foo = *middle6

func (foo) ExportedMethod(in string) string {return in} //@codeactionedit("ExportedMethod", "source.addTest", alias_receiver_exported_method)
func (foo) unexportedMethod(in string) string {return in} //@codeactionedit("unexportedMethod", "source.addTest", alias_receiver_unexported_method)

-- aliasreceiver/aliasreceiver_test.go --
package main

-- @pointer_receiver_exported_method/aliasreceiver/aliasreceiver_test.go --
@@ -3 +3,18 @@
+func TestBar_ExportedMethod(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := ExportedMethod(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("ExportedMethod() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- @pointer_receiver_unexported_method/aliasreceiver/aliasreceiver_test.go --
@@ -3 +3,18 @@
+func TestBar_unexportedMethod(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := unexportedMethod(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("unexportedMethod() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- @alias_receiver_exported_method/aliasreceiver/aliasreceiver_test.go --
@@ -3 +3,18 @@
+func Test_foo_ExportedMethod(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := ExportedMethod(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("ExportedMethod() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- @alias_receiver_unexported_method/aliasreceiver/aliasreceiver_test.go --
@@ -3 +3,18 @@
+func Test_foo_unexportedMethod(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    arg string
+    want string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got := unexportedMethod(tt.arg)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("unexportedMethod() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- multiinputoutput/multiinputoutput.go --
package main

func Foo(in, in1, in2, in3 string) (out, out1, out2 string) {return in, in, in} //@codeactionedit("Foo", "source.addTest", multi_input_output)

-- @multi_input_output/multiinputoutput/multiinputoutput_test.go --
@@ -0,0 +1,34 @@
+package main_test
+
+func TestFoo(t *testing.T) {
+  type args struct {
+    in string
+    in2 string
+    in3 string
+    in4 string
+  }
+  tests := []struct {
+    name string // description of this test case
+    args args
+    want string
+    want2 string
+    want3 string
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got, got2, got3 := main.Foo(tt.args.in, tt.args.in2, tt.args.in3, tt.args.in4)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("Foo() = %v, want %v", got, tt.want)
+      }
+      if true {
+        t.Errorf("Foo() = %v, want %v", got2, tt.want2)
+      }
+      if true {
+        t.Errorf("Foo() = %v, want %v", got3, tt.want3)
+      }
+    })
+  }
+}
-- xpackagerename/xpackagerename.go --
package main

import (
  mytime "time"
  myast "go/ast"
)

func Foo(t mytime.Time, a *myast.Node) (mytime.Time, *myast.Node) {return t, a} //@codeactionedit("Foo", "source.addTest", xpackage_rename)

-- @xpackage_rename/xpackagerename/xpackagerename_test.go --
@@ -0,0 +1,28 @@
+package main_test
+
+func TestFoo(t *testing.T) {
+  type args struct {
+    in mytime.Time
+    in2 *myast.Node
+  }
+  tests := []struct {
+    name string // description of this test case
+    args args
+    want mytime.Time
+    want2 *myast.Node
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got, got2 := main.Foo(tt.args.in, tt.args.in2)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("Foo() = %v, want %v", got, tt.want)
+      }
+      if true {
+        t.Errorf("Foo() = %v, want %v", got2, tt.want2)
+      }
+    })
+  }
+}
-- xtestpackagerename/xtestpackagerename.go --
package main

import (
  mytime "time"
  myast "go/ast"
)

func Foo(t mytime.Time, a *myast.Node) (mytime.Time, *myast.Node) {return t, a} //@codeactionedit("Foo", "source.addTest", xtest_package_rename)

-- xtestpackagerename/xtestpackagerename_test.go --
package main_test

import (
  yourtime "time"
  yourast "go/ast"
)

var fooTime = yourtime.Time{}
var fooNode = yourast.Node{}

-- @xtest_package_rename/xtestpackagerename/xtestpackagerename_test.go --
@@ -11 +11,26 @@
+func TestFoo(t *testing.T) {
+  type args struct {
+    in yourtime.Time
+    in2 *yourast.Node
+  }
+  tests := []struct {
+    name string // description of this test case
+    args args
+    want yourtime.Time
+    want2 *yourast.Node
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got, got2 := main.Foo(tt.args.in, tt.args.in2)
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("Foo() = %v, want %v", got, tt.want)
+      }
+      if true {
+        t.Errorf("Foo() = %v, want %v", got2, tt.want2)
+      }
+    })
+  }
+}
-- returnwitherror/returnwitherror.go --
package main

func OnlyErr() error {return nil} //@codeactionedit("OnlyErr", "source.addTest", return_only_error)
func StringErr() (string, error) {return "", nil} //@codeactionedit("StringErr", "source.addTest", return_string_error)
func MultipleStringErr() (string, string, string, error) {return "", "", "", nil} //@codeactionedit("MultipleStringErr", "source.addTest", return_multiple_string_error)

-- @return_only_error/returnwitherror/returnwitherror_test.go --
@@ -0,0 +1,24 @@
+package main_test
+
+func TestOnlyErr(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    wantErr bool
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      gotErr := main.OnlyErr()
+      if gotErr != nil {
+        if !tt.wantErr {
+          t.Errorf("OnlyErr() failed: %v", gotErr)
+        }
+        return
+      }
+      if tt.wantErr {
+        t.Fatal("OnlyErr() succeeded unexpectedly")
+      }
+    })
+  }
+}
-- @return_string_error/returnwitherror/returnwitherror_test.go --
@@ -0,0 +1,29 @@
+package main_test
+
+func TestStringErr(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    want string
+    wantErr bool
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got, gotErr := main.StringErr()
+      if gotErr != nil {
+        if !tt.wantErr {
+          t.Errorf("StringErr() failed: %v", gotErr)
+        }
+        return
+      }
+      if tt.wantErr {
+        t.Fatal("StringErr() succeeded unexpectedly")
+      }
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("StringErr() = %v, want %v", got, tt.want)
+      }
+    })
+  }
+}
-- @return_multiple_string_error/returnwitherror/returnwitherror_test.go --
@@ -0,0 +1,37 @@
+package main_test
+
+func TestMultipleStringErr(t *testing.T) {
+  tests := []struct {
+    name string // description of this test case
+    want string
+    want2 string
+    want3 string
+    wantErr bool
+  }{
+    // TODO: Add test cases.
+  }
+  for _, tt := range tests {
+    t.Run(tt.name, func(t *testing.T) {
+      got, got2, got3, gotErr := main.MultipleStringErr()
+      if gotErr != nil {
+        if !tt.wantErr {
+          t.Errorf("MultipleStringErr() failed: %v", gotErr)
+        }
+        return
+      }
+      if tt.wantErr {
+        t.Fatal("MultipleStringErr() succeeded unexpectedly")
+      }
+      // TODO: update the condition below to compare got with tt.want.
+      if true {
+        t.Errorf("MultipleStringErr() = %v, want %v", got, tt.want)
+      }
+      if true {
+        t.Errorf("MultipleStringErr() = %v, want %v", got2, tt.want2)
+      }
+      if true {
+        t.Errorf("MultipleStringErr() = %v, want %v", got3, tt.want3)
+      }
+    })
+  }
+}
