67 lines
1.7 KiB
Go
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)
|
|
}
|
|
}
|