Files
MyGolandRelease/internal/godoc/godoc_test.go
T
zerorigin f5bfbac6c3 feat: 标准库文档批量预热——补全/悬停翻译秒出
懒翻译要等 1-2 秒。真 gopls 实证 go/doc 从本地源码提取的文档与
gopls 补全/悬停正文规范化空白后完全一致,批量预热方案成立:
- internal/godoc: go/doc 提取器 + 36 个常用标准库清单 + NormKey
- app.PreheatDocs: 6 并发翻译,进度走输出面板,已缓存自动跳过;
  菜单手动触发 + 打开项目 8 秒后自动跑(每会话一次)
- tools/preheat: 命令行批量工具,直接写用户缓存文件
- 缓存 key 统一 NormKey,预热/懒翻译/旧缓存三方互命中
- 已实测灌入 10 包 394 条译文(272 秒),常用包全部秒出
2026-11-04 17:30:51 +08:00

51 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package godoc
import (
"strings"
"testing"
)
// TestDocsFmt 提取 fmt 包:应当包含 Println 的文档,条目量在合理范围
//(fmt 实测 29 条:23 个函数 + 6 个类型)。
func TestDocsFmt(t *testing.T) {
docs, err := Docs("fmt")
if err != nil {
t.Fatalf("Docs(fmt): %v", err)
}
if len(docs) < 25 {
t.Fatalf("fmt 包导出符号文档只有 %d 条,异常", len(docs))
}
var found bool
for _, d := range docs {
if strings.Contains(d, "Println formats using") {
found = true
break
}
}
if !found {
t.Fatal("没提取到 Println 的文档")
}
t.Logf("fmt 包共 %d 条文档", len(docs))
}
// TestDocsMissing 包不存在时应当报错而不是 panic。
func TestDocsMissing(t *testing.T) {
if _, err := Docs("nosuchpkg123"); err == nil {
t.Fatal("不存在的包应报错")
}
}
// TestIsStandard 标准库与第三方导入路径的判断。
func TestIsStandard(t *testing.T) {
for _, p := range []string{"fmt", "net/http", "encoding/json"} {
if !isStandard(p) {
t.Errorf("%s 应判定为标准库", p)
}
}
for _, p := range []string{"github.com/x/y", "golang.org/x/tools"} {
if isStandard(p) {
t.Errorf("%s 不应判定为标准库", p)
}
}
}