ray-x / go.nvim

G'day Nvimer, Joyful Gopher: Discover the Feature-Rich Go Plugin for Neovim
MIT License
1.93k stars 119 forks source link

Improve GoTestSubCase #358

Closed thuan1412 closed 9 months ago

thuan1412 commented 1 year ago

Currently, the GoTestSubCase command has two small problems:

  1. It only supports table-drivent test pattern and does not support normal subtest pattern.
  2. We must put the cursor in the name of the testcase to run the testcase.

We should resolve these two problems to increase productivity when writing tests.

ray-x commented 1 year ago

For 1 an alterative is snippets included in go.nvim for 2, it is by design, as the plugin need to know the name of testcase to run a specific test. But you do not need to put the cursor on the name, anywhere inside the testcase should be fine. For table driven test you need to put cursor on the table entry to run a specific test case.

thuan1412 commented 1 year ago
  1. Could you give more detail about the snippets?
  2. I tried to run GoTestSubCase where I put the cursor outside of the testcase name, but it does not run the 1 + 2 = 3 testcase, instead, it run the whole Test_add function.
    
    package add

import "testing"

func Testadd(t *testing.T) { type args struct { a int b int } tests := []struct { name string args args want int }{ { name: "1 + 2 = 3", args: args{1, 2}, want: 3, }, } for , tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := add(tt.args.a, tt.args.b); got != tt.want { t.Errorf("add() = %v, want %v", got, tt.want) } }) } }

ray-x commented 12 months ago

Yes, I know it is a bit painful. I will need to update the AST parser to handle TestSubCase.