You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
I am not sure if this feature already exists, but as far as I have researched, I am not able to find.
I remember seeing this feature used significantly in Visual Studio while writing C# by almost every .NET programmer, I have come across. I am surprised, that I am not able to find it in VS code.
Let's say I have a something like
package arrays
import"testing"funcTestNewBitArray(t*testing.T) {
varsizeint64=1a:=NewBitArray(size)
bArray:= []int8(a)
iflen(bArray) !=1 {
t.Error("Expected length to be 1, but got", len(bArray))
}
size=10a=NewBitArray(size)
bArray= []int8(a)
iflen(bArray) !=2 {
t.Error("Expected length to be 2, but got", len(bArray))
}
size=32a=NewBitArray(size)
bArray= []int8(a)
iflen(bArray) !=4 {
t.Error("Expected length to be 4, but got", len(bArray))
}
}
There are repeated blocks of instructions the code, which someone might prefer writing during the initial phase of development. After things start to work, I would typically want to make a function out of the repeated block and use it.
Now the workflow would be, I would select the repeated code block. In my case,
a:=NewBitArray(size)
bArray:= []int8(a)
iflen(bArray) !=1 {
t.Error("Expected length to be 1, but got", len(bArray))
}
and execute the command called "Extract Function" from context menu or from cmd+p or from "Go" Menu.
This would result in generating functions with appropriate method signature.
varcheckSizeClosure=func(sizeint) {
a:=NewBitArray(size)
bArray:= []int8(a)
iflen(bArray) !=1 {
t.Error("Expected length to be 1, but got", len(bArray))
}
}
or
funccheckSizeLocal(t*testing.T, sizeint) {
a:=NewBitArray(size)
bArray:= []int8(a)
iflen(bArray) !=1 {
t.Error("Expected length to be 1, but got", len(bArray))
}
}
With the newly generated function, I can tweak it a little bit to add an expected variable and my tests could be refactored into an idiomatic table based golang tests like this
I am not sure if this feature already exists, but as far as I have researched, I am not able to find.
I remember seeing this feature used significantly in Visual Studio while writing C# by almost every .NET programmer, I have come across. I am surprised, that I am not able to find it in VS code.
Let's say I have a something like
There are repeated blocks of instructions the code, which someone might prefer writing during the initial phase of development. After things start to work, I would typically want to make a function out of the repeated block and use it.
Now the workflow would be, I would select the repeated code block. In my case,
and execute the command called "Extract Function" from context menu or from
cmd+p
or from "Go" Menu.This would result in generating functions with appropriate method signature.
or
With the newly generated function, I can tweak it a little bit to add an
expected
variable and my tests could be refactored into an idiomatic table based golang tests like thisHaving "Extract Function" feature would help much in cleaning the code base that is full of repeated code.
The text was updated successfully, but these errors were encountered: