Files
code-utils/service/insights_test.go
李琦 7c4109f687 feat: 提交详情能看 diff,也能丢给 AI 审这一次改动。文件检查可单独排除路径,TODO 只认大写,避免把 todo 表和模块当成待办标记。
热力图按容器宽度铺满一年,不再横向滚动。托盘右键换成可换皮肤的弹层;更新下载显示进度,退出后再由脚本拉起安装器,避免还占着 exe。
2026-08-19 15:46:03 +08:00

67 lines
1.7 KiB
Go

package service
import (
"testing"
"view/model"
)
func TestHasUpperTODO(t *testing.T) {
cases := []struct {
text string
want bool
}{
{"// TODO: fix later", true},
{"# TODO", true},
{" TODO()", true},
{"create table todo", false},
{"type TodoService struct {}", false},
{"const todos = []", false},
{"TODOS := 1", false},
{"myTODO", false},
{"TODO_ITEM", false},
{"// todo: later", false},
{"// Todo: later", false},
}
for _, c := range cases {
if got := hasUpperTODO(c.text); got != c.want {
t.Errorf("hasUpperTODO(%q) = %v, want %v", c.text, got, c.want)
}
}
}
func TestPathExcludedAndFilterStructure(t *testing.T) {
rules := []model.ExclusionRule{{Pattern: "vendor"}, {Pattern: "src/todo"}, {Pattern: "*.pb.go"}}
if !pathExcluded("vendor/lib.go", rules) {
t.Fatal("vendor dir should be excluded")
}
if !pathExcluded("src/todo/list.go", rules) {
t.Fatal("src/todo dir should be excluded")
}
if !pathExcluded("api/user.pb.go", rules) {
t.Fatal("*.pb.go should be excluded")
}
if pathExcluded("src/app/main.go", rules) {
t.Fatal("normal source should stay")
}
s := model.StructureStats{
Files: []model.FileEntry{
{Path: "src/app/main.go"},
{Path: "vendor/lib.go"},
{Path: "src/todo/list.go"},
},
LargeFiles: []model.FileEntry{{Path: "vendor/huge.bin"}},
Folders: []model.FolderStat{{Name: "vendor"}, {Name: "src"}},
}
got := filterStructureForInsights(s, rules)
if len(got.Files) != 1 || got.Files[0].Path != "src/app/main.go" {
t.Fatalf("files=%#v", got.Files)
}
if len(got.LargeFiles) != 0 {
t.Fatalf("large=%#v", got.LargeFiles)
}
if len(got.Folders) != 1 || got.Folders[0].Name != "src" {
t.Fatalf("folders=%#v", got.Folders)
}
}