fix: 修正 Example 函数命名与输出注释位置,让 go vet / go test 恢复可用
go vet ./... 此前有 13 处失败, 导致 go test ./...(默认带 vet)根本跑不起来,
必须加 -vet=off。这是既存问题, 与实现改动无关。
命名问题(12 处): Example 函数名的前缀必须是包内真实存在的标识符。
ExampleStructMap_* -> ExampleR_* (包里没有 StructMap)
ExampleSet_* -> ExampleR_Set_* (Set 是 R 的方法, 不是包级函数)
ExampleAppend_* -> ExampleR_Append_* (同上)
ExampleSchema_Unmarshal -> ExampleSchema_unmarshalJSON
(Schema 没有 Unmarshal 方法,
这个例子演示的是 json.Unmarshal)
输出注释位置(1 处): ExampleR_Append_typeConversionError 的 // Output: 后面
还跟着一条注释, 违反"Output 必须是最后一个注释块"。因为格式不合法, Go 一直
没把它当输出例子比对 —— 里面写的期望输出其实是错的(与实际信息不符)也没被发现。
把注释挪到 defer 之前, 并把期望输出更正为真实的 panic 信息。
已验证: 故意改错期望输出现在会导致测试失败, 说明确实在比对了。
现在 go vet ./... 干净, go test ./... 无需 -vet=off 即可运行。
This commit is contained in:
+10
-10
@@ -342,8 +342,8 @@ func ExampleNew_withMap() {
|
||||
// New timeout: 30
|
||||
}
|
||||
|
||||
// ExampleStructMap_Scope_noArgs 演示如何使用 Scope() 不传参数来复制整个对象
|
||||
func ExampleStructMap_Scope_noArgs() {
|
||||
// ExampleR_Scope_noArgs 演示如何使用 Scope() 不传参数来复制整个对象
|
||||
func ExampleR_Scope_noArgs() {
|
||||
type Config struct {
|
||||
Host string
|
||||
Port int
|
||||
@@ -376,8 +376,8 @@ func ExampleStructMap_Scope_noArgs() {
|
||||
// Clone - Host: 127.0.0.1, Port: 9090
|
||||
}
|
||||
|
||||
// ExampleStructMap_Scope_withPath 演示如何使用 Scope() 传入路径来复制嵌套对象
|
||||
func ExampleStructMap_Scope_withPath() {
|
||||
// ExampleR_Scope_withPath 演示如何使用 Scope() 传入路径来复制嵌套对象
|
||||
func ExampleR_Scope_withPath() {
|
||||
type Address struct {
|
||||
City string
|
||||
Street string
|
||||
@@ -449,8 +449,8 @@ func ExampleNew_withNestedMap() {
|
||||
// User (dot notation): Alice
|
||||
}
|
||||
|
||||
// ExampleStructMap_lowercaseFields 演示如何使用小写字段名访问 struct
|
||||
func ExampleStructMap_lowercaseFields() {
|
||||
// ExampleR_lowercaseFields 演示如何使用小写字段名访问 struct
|
||||
func ExampleR_lowercaseFields() {
|
||||
type Person struct {
|
||||
Name string
|
||||
Age int
|
||||
@@ -480,8 +480,8 @@ func ExampleStructMap_lowercaseFields() {
|
||||
// Updated - Name: Bob, Age: 35
|
||||
}
|
||||
|
||||
// ExampleStructMap_lowercaseNestedFields 演示如何使用小写字段名访问嵌套 struct
|
||||
func ExampleStructMap_lowercaseNestedFields() {
|
||||
// ExampleR_lowercaseNestedFields 演示如何使用小写字段名访问嵌套 struct
|
||||
func ExampleR_lowercaseNestedFields() {
|
||||
type Address struct {
|
||||
City string
|
||||
Street string
|
||||
@@ -520,8 +520,8 @@ func ExampleStructMap_lowercaseNestedFields() {
|
||||
// Updated City: Shanghai, Street: New Street
|
||||
}
|
||||
|
||||
// ExampleStructMap_castConversion 演示使用 cast 进行智能类型转换
|
||||
func ExampleStructMap_castConversion() {
|
||||
// ExampleR_castConversion 演示使用 cast 进行智能类型转换
|
||||
func ExampleR_castConversion() {
|
||||
type Config struct {
|
||||
Port int
|
||||
Host string
|
||||
|
||||
Reference in New Issue
Block a user