我有一個Extractor接口,它有一個Playlist方法:// extractor.gopackage extractortype Extractor interface { Playlist(timestampFrom int64) (playlist.Tracklist, error)}我在另一個包中使用這個接口:// fip.gopackage fiptype Extractor struct {}func (extractor Extractor) Playlist(timestampFrom int64) ([]playlist.Track, error) { // ...}在我的測試中,我想展示一個關于如何使用該Playlist方法的示例fip:// fip_test.gopackage fipfunc ExamplePlaylist() { // ...}但go vet顯示此錯誤: fip/extractor_test.go:82:1: ExamplePlaylist refers to unknown identifier: Playlist我不明白為什么......Playlist確實作為fip包中的一種方法存在。我錯過了什么?
1 回答

ITMISS
TA貢獻1871條經驗 獲得超8個贊
示例函數的正確名稱ExampleExtractor_Playlist如測試文檔的示例部分所述。
報價:
The naming convention to declare examples for the package, a function F, a type T and method M on type T are:
func Example() { ... }
func ExampleF() { ... }
func ExampleT() { ... }
func ExampleT_M() { ... }
您的示例是最后一種情況TisExtractor和Mis Playlist。
- 1 回答
- 0 關注
- 148 瀏覽
添加回答
舉報
0/150
提交
取消