MyGoland 首次提交:Go 轻量 IDE
- 编辑器:多标签、语法高亮、gopls 全套(补全/诊断/跳转/重命名/代码动作/内联提示/签名大纲) - 调试:Delve DAP(断点/条件断点/变量树/表达式求值/goroutine 列表) - 测试:结果树、覆盖率行着色、失败跳源码、-run 精确运行、行号可跑标记 - Git:状态着色、选择性暂存提交、pull/push、历史并排对比 - 本地历史 + 自动快照 + 崩溃恢复、会话/光标恢复 - 全局搜索替换(预览+确认,GBK 安全)、多终端、gopls 崩溃自愈 - 设计文档与验证记录见 docs/plans/
This commit is contained in:
commit
a80c0f886a
220 files changed
+20784
No files matched your search
@@ -0,0 +1,94 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// isolateConfig 把配置目录指到临时目录,避免测试污染真实的会话文件。
|
||||
func isolateConfig(t *testing.T) {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
t.Setenv("AppData", dir)
|
||||
t.Setenv("XDG_CONFIG_HOME", dir)
|
||||
}
|
||||
|
||||
func TestSessionRoundTrip(t *testing.T) {
|
||||
isolateConfig(t)
|
||||
root := t.TempDir()
|
||||
p1 := filepath.Join(root, "a.go")
|
||||
p2 := filepath.Join(root, "b.go")
|
||||
for _, p := range []string{p1, p2} {
|
||||
if err := os.WriteFile(p, []byte("package x\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
a := &App{
|
||||
root: root, bps: map[string]map[int]breakpoint{p1: {3: {Enabled: true}, 7: {Enabled: true}}},
|
||||
sidebar: 320, sidebarOn: false,
|
||||
panel: true, panelTab: 2, panelH: 260,
|
||||
panelKind: 1, light: true, shellIdx: 2,
|
||||
}
|
||||
a.docs = []*Doc{{path: p1}, {path: p2}}
|
||||
a.active = p2
|
||||
a.saveSession()
|
||||
|
||||
st, ok := loadSession(root)
|
||||
if !ok {
|
||||
t.Fatal("没有读到会话")
|
||||
}
|
||||
if !st.Panel || st.PanelTab != 2 || st.PanelH != 260 {
|
||||
t.Fatalf("面板状态不对: %+v", st)
|
||||
}
|
||||
if st.Sidebar || st.SidebarW != 320 || st.PanelKind != 1 {
|
||||
t.Fatalf("侧栏状态不对: %+v", st)
|
||||
}
|
||||
if len(st.Tabs) != 2 || st.Tabs[0] != p1 || st.Tabs[1] != p2 {
|
||||
t.Fatalf("标签不对: %+v", st.Tabs)
|
||||
}
|
||||
if st.Active != p2 {
|
||||
t.Fatalf("当前标签不对: %q", st.Active)
|
||||
}
|
||||
if len(st.Breakpoints[p1]) != 2 {
|
||||
t.Fatalf("断点不对: %+v", st.Breakpoints)
|
||||
}
|
||||
if !st.Light || st.ShellIdx != 2 {
|
||||
t.Fatalf("主题/外壳不对: %+v", st)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLastWorkspace(t *testing.T) {
|
||||
isolateConfig(t)
|
||||
root := t.TempDir()
|
||||
a := &App{root: root, bps: map[string]map[int]breakpoint{}}
|
||||
a.saveSession()
|
||||
|
||||
got := lastWorkspace()
|
||||
if filepath.Clean(got) != filepath.Clean(root) {
|
||||
t.Fatalf("上次工作区应是 %q,实际 %q", root, got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestLastWorkspaceGone 确认目录被删后不会返回失效路径。
|
||||
func TestLastWorkspaceGone(t *testing.T) {
|
||||
isolateConfig(t)
|
||||
root := t.TempDir()
|
||||
a := &App{root: root, bps: map[string]map[int]breakpoint{}}
|
||||
a.saveSession()
|
||||
|
||||
if err := os.RemoveAll(root); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := lastWorkspace(); got != "" {
|
||||
t.Fatalf("目录不存在时不该返回 %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionMissing(t *testing.T) {
|
||||
isolateConfig(t)
|
||||
if _, ok := loadSession(filepath.Join(t.TempDir(), "nope")); ok {
|
||||
t.Fatal("不存在的会话不该读成功")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user