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,82 @@
|
||||
package app
|
||||
|
||||
import "testing"
|
||||
|
||||
// newTestApp 造一个没有窗口的 App,终端会话操作不依赖 UI。
|
||||
func newTestApp(shells ...int) *App {
|
||||
a := &App{}
|
||||
for _, sh := range shells {
|
||||
a.terms = append(a.terms, &termSession{shell: sh, state: "就绪"})
|
||||
}
|
||||
a.termIdx = 0
|
||||
return a
|
||||
}
|
||||
|
||||
func TestTermLabel(t *testing.T) {
|
||||
cases := map[int]string{0: "PS", 1: "Bash", 2: "CMD", 9: "终端"}
|
||||
for sh, want := range cases {
|
||||
if got := (&termSession{shell: sh}).label(); got != want {
|
||||
t.Fatalf("shell %d 标签应为 %q,实际 %q", sh, want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloseTermMiddle(t *testing.T) {
|
||||
a := newTestApp(0, 1, 2)
|
||||
a.termIdx = 0
|
||||
a.closeTerm(1) // 关中间那个,当前不变
|
||||
if len(a.terms) != 2 || a.termIdx != 0 {
|
||||
t.Fatalf("关中间后应剩 2 个且选中不变: %d %d", len(a.terms), a.termIdx)
|
||||
}
|
||||
if a.terms[1].shell != 2 {
|
||||
t.Fatalf("剩下应是原第 1 和第 3 个: %+v", a.terms)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloseTermBeforeActive(t *testing.T) {
|
||||
a := newTestApp(0, 1, 2)
|
||||
a.termIdx = 2
|
||||
a.closeTerm(0) // 关掉当前左边的,选中要左移一位
|
||||
if a.termIdx != 1 || len(a.terms) != 2 {
|
||||
t.Fatalf("选中应左移: idx=%d n=%d", a.termIdx, len(a.terms))
|
||||
}
|
||||
if a.terms[a.termIdx].shell != 2 {
|
||||
t.Fatalf("选中的还应是原来的第 3 个: %+v", a.terms)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloseTermActiveLast(t *testing.T) {
|
||||
a := newTestApp(0, 1)
|
||||
a.termIdx = 1
|
||||
a.closeTerm(1) // 关掉当前,且它是最后一个
|
||||
if len(a.terms) != 1 || a.termIdx != 0 {
|
||||
t.Fatalf("应回落到第一个: n=%d idx=%d", len(a.terms), a.termIdx)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloseLastRemaining(t *testing.T) {
|
||||
a := newTestApp(0)
|
||||
a.closeTerm(0)
|
||||
if len(a.terms) != 0 || a.termIdx != 0 {
|
||||
t.Fatalf("关空后应清空且索引归零: n=%d idx=%d", len(a.terms), a.termIdx)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloseTermOutOfRange(t *testing.T) {
|
||||
a := newTestApp(0)
|
||||
a.closeTerm(5) // 越界不该 panic
|
||||
if len(a.terms) != 1 {
|
||||
t.Fatalf("越界关闭不应改动列表: %d", len(a.terms))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTermShellsForSession(t *testing.T) {
|
||||
a := newTestApp(0, 1, 2)
|
||||
got := a.termShells()
|
||||
if len(got) != 3 || got[0] != 0 || got[1] != 1 || got[2] != 2 {
|
||||
t.Fatalf("会话存档应记录每个外壳: %v", got)
|
||||
}
|
||||
if newTestApp().termShells() != nil {
|
||||
t.Fatal("没有会话时应返回 nil")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user