Files
MyGolandRelease/internal/app/recent_test.go
T
zerorigin a80c0f886a MyGoland 首次提交:Go 轻量 IDE
- 编辑器:多标签、语法高亮、gopls 全套(补全/诊断/跳转/重命名/代码动作/内联提示/签名大纲)
- 调试:Delve DAP(断点/条件断点/变量树/表达式求值/goroutine 列表)
- 测试:结果树、覆盖率行着色、失败跳源码、-run 精确运行、行号可跑标记
- Git:状态着色、选择性暂存提交、pull/push、历史并排对比
- 本地历史 + 自动快照 + 崩溃恢复、会话/光标恢复
- 全局搜索替换(预览+确认,GBK 安全)、多终端、gopls 崩溃自愈
- 设计文档与验证记录见 docs/plans/
2026-11-04 16:37:05 +08:00

62 lines
1.4 KiB
Go

package app
import (
"os"
"path/filepath"
"testing"
)
func TestRecentAddAndOrder(t *testing.T) {
isolateConfig(t)
d1, d2 := t.TempDir(), t.TempDir()
addRecent(d1)
addRecent(d2)
items := loadRecent()
if len(items) != 2 {
t.Fatalf("应有 2 条,实际 %d", len(items))
}
if items[0].Path != filepath.Clean(d2) {
t.Fatalf("最近打开的应该在最前面,实际 %q", items[0].Path)
}
// 再打开一次旧的:不新增条目,但要移到最前。
addRecent(d1)
items = loadRecent()
if len(items) != 2 {
t.Fatalf("重复打开不该增加条目,实际 %d", len(items))
}
if items[0].Path != filepath.Clean(d1) {
t.Fatalf("重新打开的项目应排最前,实际 %q", items[0].Path)
}
}
func TestRecentDropsMissing(t *testing.T) {
isolateConfig(t)
d := t.TempDir()
addRecent(d)
if err := os.RemoveAll(d); err != nil {
t.Fatal(err)
}
if items := loadRecent(); len(items) != 0 {
t.Fatalf("目录已删除,不该再列出: %+v", items)
}
}
func TestRecentLimit(t *testing.T) {
isolateConfig(t)
for i := 0; i < recentLimit+5; i++ {
addRecent(t.TempDir())
}
if n := len(loadRecent()); n != recentLimit {
t.Fatalf("最多保留 %d 条,实际 %d", recentLimit, n)
}
}
func TestRecentEmptyFile(t *testing.T) {
isolateConfig(t)
if items := loadRecent(); len(items) != 0 {
t.Fatalf("没有记录时应为空: %+v", items)
}
}