MyGoland 首次提交:Go 轻量 IDE

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

No files matched your search

+124
View File
@@ -0,0 +1,124 @@
package app
import (
"os"
"path/filepath"
"testing"
)
// TestSnapshotAndList 保存后能列出,内容能读回来。
func TestSnapshotAndList(t *testing.T) {
isolateConfig(t)
path := filepath.Join(t.TempDir(), "a.go")
if err := saveSnapshot(path, []byte("package main\n"), "save", false); err != nil {
t.Fatal(err)
}
if err := saveSnapshot(path, []byte("package main\n// 改了\n"), "save", false); err != nil {
t.Fatal(err)
}
items := listHistory(path)
if len(items) != 2 {
t.Fatalf("应有 2 条历史,实际 %d", len(items))
}
// 最新的在前
if items[0].Time < items[1].Time {
t.Fatal("应按时间倒序")
}
got, err := readSnapshot(path, items[0].Hash)
if err != nil {
t.Fatal(err)
}
if string(got) != "package main\n// 改了\n" {
t.Fatalf("内容不对: %q", got)
}
}
// TestSnapshotDedup 内容没变不重复记:否则每按一次 Ctrl+S 就多一条。
func TestSnapshotDedup(t *testing.T) {
isolateConfig(t)
path := filepath.Join(t.TempDir(), "a.go")
data := []byte("package main\n")
for i := 0; i < 5; i++ {
if err := saveSnapshot(path, data, "save", false); err != nil {
t.Fatal(err)
}
}
if n := len(listHistory(path)); n != 1 {
t.Fatalf("相同内容只该留一条,实际 %d", n)
}
}
// TestSnapshotPrune 超过上限要裁掉最老的,并把快照文件删掉。
func TestSnapshotPrune(t *testing.T) {
isolateConfig(t)
path := filepath.Join(t.TempDir(), "a.go")
for i := 0; i < histKeep+8; i++ {
data := []byte{byte('a' + i%26), byte(i)}
if err := saveSnapshot(path, data, "auto", true); err != nil {
t.Fatal(err)
}
}
items := listHistory(path)
if len(items) > histKeep {
t.Fatalf("应裁到 %d 条,实际 %d", histKeep, len(items))
}
dir := historyDir(path)
entries, err := os.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
snaps := 0
for _, e := range entries {
if filepath.Ext(e.Name()) == ".snap" {
snaps++
}
}
if snaps > histKeep {
t.Fatalf("快照文件没清干净: %d 个", snaps)
}
}
// TestSnapshotTooLarge 超大内容不存历史,避免把日志反复复制。
func TestSnapshotTooLarge(t *testing.T) {
isolateConfig(t)
path := filepath.Join(t.TempDir(), "big.log")
big := make([]byte, histMaxSize+1)
for i := range big {
big[i] = 'x'
}
if err := saveSnapshot(path, big, "save", false); err != nil {
t.Fatal(err)
}
if n := len(listHistory(path)); n != 0 {
t.Fatalf("超大内容不该留历史,实际 %d 条", n)
}
}
// TestPendingRoundTrip 未保存标记能写能读能清。
func TestPendingRoundTrip(t *testing.T) {
isolateConfig(t)
if got := loadPending(); len(got) != 0 {
t.Fatal("初始应为空")
}
markPending([]pendingSnap{{Path: "C:/x/a.go", Hash: "abc", Time: 1}})
got := loadPending()
if len(got) != 1 || got[0].Hash != "abc" {
t.Fatalf("读回来的不对: %+v", got)
}
markPending(nil)
if got := loadPending(); len(got) != 0 {
t.Fatalf("清空后应为空: %+v", got)
}
}
// TestApplyEOL 快照里的换行要和原文件一致。
func TestApplyEOL(t *testing.T) {
if got := applyEOL("a\nb\n", "\r\n"); got != "a\r\nb\r\n" {
t.Fatalf("CRLF 还原不对: %q", got)
}
if got := applyEOL("a\nb\n", "\n"); got != "a\nb\n" {
t.Fatalf("LF 不该改: %q", got)
}
}