Go测试包提到示例函数,如:
func Example() { ... }
func ExampleF() { ... }
func ExampleT() { ... }
func ExampleT_M() { ... }
Run Code Online (Sandbox Code Playgroud)
这些是什么意思和用例?
我知道Golang通过以功能名称(拼写为“ func”)开头的单行注释来支持功能文档。但是,这有一个令人作呕的副作用:具有多个单行注释将不会生成带有换行符的GoDoc,该换行符将文本的每一行分开
这是一张图片来说明:
这是函子及其文档:
//GetFunctionName gets function name
// Parameters:
// - `i` : Function
// **NOTE** this func fails if `i` is a variable set to a func
// (they're called "anonymous functions" in JavaScript)
func GetFunctionName(i interface{}) string {
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
}
Run Code Online (Sandbox Code Playgroud)
如何在生成的文档中插入换行符?(如果这是Javadoc,我希望<br>一切都会很好)
在整个项目中,我负责测试和记录,并以以下格式创建了有关功能和方法的记录:
// CheckPermissionArray checks that values is an array that contains the `expectedValue`
//
// Parameters:
//
// - `values` : the array to check
// - `expectedValue` : the value to search for
//
// Returns:
//
// - an error iff `expectedValue` is not in `values`
Run Code Online (Sandbox Code Playgroud)
老板和其他程序员赞成这种格式,但是问题是godoc无法识别该列表:
有没有办法让名单得到认可?
从某种程度上讲,Visual Studio Code可以很好地识别此文档,尽管有点bug。