- 编辑器:多标签、语法高亮、gopls 全套(补全/诊断/跳转/重命名/代码动作/内联提示/签名大纲) - 调试:Delve DAP(断点/条件断点/变量树/表达式求值/goroutine 列表) - 测试:结果树、覆盖率行着色、失败跳源码、-run 精确运行、行号可跑标记 - Git:状态着色、选择性暂存提交、pull/push、历史并排对比 - 本地历史 + 自动快照 + 崩溃恢复、会话/光标恢复 - 全局搜索替换(预览+确认,GBK 安全)、多终端、gopls 崩溃自愈 - 设计文档与验证记录见 docs/plans/
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestExpandAll(t *testing.T) {
|
|
root := t.TempDir()
|
|
deep := filepath.Join(root, "a", "b")
|
|
if err := os.MkdirAll(deep, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(deep, "x.go"), []byte("package x\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
a := &App{root: root, open: map[string]*bool{}, dirs: map[string][]fs.DirEntry{}}
|
|
|
|
a.ExpandAll()
|
|
|
|
for _, dir := range []string{
|
|
filepath.Join(root, "a"),
|
|
filepath.Join(deep),
|
|
} {
|
|
if !*a.openFlag(dir) {
|
|
t.Fatalf("%s 没有被展开", dir)
|
|
}
|
|
}
|
|
|
|
a.CollapseAll()
|
|
for _, dir := range []string{
|
|
filepath.Join(root, "a"),
|
|
filepath.Join(deep),
|
|
} {
|
|
if *a.openFlag(dir) {
|
|
t.Fatalf("%s 没有被折叠", dir)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAddEntriesTargetDir(t *testing.T) {
|
|
root := t.TempDir()
|
|
f := filepath.Join(root, "main.go")
|
|
if err := os.WriteFile(f, []byte("package main\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
a := &App{root: root, open: map[string]*bool{}, dirs: map[string][]fs.DirEntry{}, sel: map[string]bool{}}
|
|
|
|
// 没有选中项时落在工作区根。
|
|
if got := len(a.addEntries()); got != 2 {
|
|
t.Fatalf("应当有两个菜单项,实际 %d", got)
|
|
}
|
|
|
|
// 选中一个文件时,应当落到它所在的目录(这里是根)。
|
|
a.sel[f] = true
|
|
if got := len(a.addEntries()); got != 2 {
|
|
t.Fatalf("应当有两个菜单项,实际 %d", got)
|
|
}
|
|
}
|